Skip to content

Instantly share code, notes, and snippets.

@Xetera
Created September 18, 2022 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xetera/910db71e8c1df315cbeaf2a6a8501c92 to your computer and use it in GitHub Desktop.
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
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