Created
September 18, 2022 14:29
-
-
Save Xetera/910db71e8c1df315cbeaf2a6a8501c92 to your computer and use it in GitHub Desktop.
Python function for checking when a site was banned by the Turkish government
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Optional | |
import requests | |
import re | |
import datetime | |
def check_turkish_ban_date(site: str) -> Optional[datetime.date]: | |
""" | |
Looks up when a site (domain + tld) was banned in turkey. | |
Returns None if the site isn't banned. | |
Works regardless of caller IP. | |
Usage: `check_turkish_ban_date('wikileaks.org')` | |
""" | |
reg = re.compile(f"{site}, (?P<day>.*?)/(?P<month>.*?)/(?P<year>.*?) tarihli") | |
response = requests.get("http://195.175.254.2", headers={"Host": site}) | |
result = reg.search(response.text) | |
if not result: | |
return None | |
(day, month, year) = result.groups() | |
return datetime.date(int(year), int(month), int(day)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment