Skip to content

Instantly share code, notes, and snippets.

@cyb3rsalih
Last active December 30, 2023 15:23
Show Gist options
  • Save cyb3rsalih/238117f458ecdcd92e2d310655d6e965 to your computer and use it in GitHub Desktop.
Save cyb3rsalih/238117f458ecdcd92e2d310655d6e965 to your computer and use it in GitHub Desktop.
Find Turkish Newspaper for a Date;
# Example usage python3 gazete.py "23 Mayıs 1954"
import concurrent.futures
import sys
import requests
gazeteler = [
"agac",
"ahali_filibe",
"akis",
"aksam",
"anadolu",
"aydede",
"balkan_filibe",
"birgun",
"bugun_2005",
"bugun",
"buyuk_dogu",
"commodore",
"cumhuriyet",
"diyojen",
"haber",
"hakimiyeti_milliye",
"halkin_sesi",
"hayat",
"her_ay",
"ikaz",
"ikdam_sabah_postasi",
"iradei_milliye_sivas",
"kadro",
"kurun",
"milli_gazete",
"milliyet",
"peyam",
"radikal",
"sebilurresad",
"serbes_cumhuriyet",
"servet",
"serveti_funun",
"servetifunun_uyanis",
"son_posta",
"son_telgraf",
"sozcu",
"takvimi_vekayi",
"tan",
"tanin_yeni",
"tanin",
"taraf",
"tasviri_efkar",
"turk_dili",
"ulus",
"ulusal_birlik_izmir",
"vakit",
"vatan",
"yarın",
"yarim_ay",
"yeni_asir",
"yeni_istanbul",
"yeni_sabah",
"yeni_safak",
"yenigun_antakya",
"zafer",
"zaman",
"zaman_feza",
]
# Mapping of Turkish month names to their numeric values
turkish_months = {
"Ocak": 1,
"Şubat": 2,
"Mart": 3,
"Nisan": 4,
"Mayıs": 5,
"Haziran": 6,
"Temmuz": 7,
"Ağustos": 8,
"Eylül": 9,
"Ekim": 10,
"Kasım": 11,
"Aralık": 12,
}
def parse_turkish_date(date_str):
day, month_name, year = date_str.split()
month = turkish_months.get(month_name)
if not month:
raise ValueError(f"Invalid Turkish month name: {month_name}")
return f"{year}-{month:02d}-{int(day):02d}"
def get_date():
if len(sys.argv) > 1:
return parse_turkish_date(sys.argv[1])
else:
return parse_turkish_date(input("Gün Ay Yıl şeklinde tarih giriniz: "))
# Using the function
tarih = get_date()
def fetch_gazete(gazete):
url = f"https://www.gastearsivi.com/gazete/{gazete}/{tarih}/1"
r = requests.get(url)
if r.status_code == 200:
print(
# f"{gazete} gazetesi {tarih} tarihli sayısı bulundu.\n==> https://www.gastearsivi.com/gazete/{gazete}/{tarih}/1\n\n"
f"https://www.gastearsivi.com/gazete/{gazete}/{tarih}/1"
)
# Adjust the number of threads in the pool
pool_size = 10
with concurrent.futures.ThreadPoolExecutor(max_workers=pool_size) as executor:
executor.map(fetch_gazete, gazeteler)
print("Bitti")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment