Skip to content

Instantly share code, notes, and snippets.

@korayal
Created June 5, 2017 10:06
Show Gist options
  • Save korayal/90f7153d51cae771db98f92a04564dbf to your computer and use it in GitHub Desktop.
Save korayal/90f7153d51cae771db98f92a04564dbf to your computer and use it in GitHub Desktop.
Ankara MEB Atama Takibi
# ankara.meb.gov.tr ilanlarina bakip, icinde sonuc gecen ilan ciktiginda Pushover uzerinden bildirim gonderir.
#!/usr/bin/env python3
import requests
from bs4 import BeautifulSoup
from pushover import init, Client
import re
from pathlib import Path
from datetime import datetime, timedelta
token = "<token>"
user_key = "<user_key>"
tmp_file = Path('ameb_tmp')
session = requests.session()
lastdate = datetime.now()
if tmp_file.exists():
with tmp_file.open() as f:
ld = f.read()
date_text = re.search(r'\d{2}\.\d{2}\.\d{4} - \d{2}:\d{2}', ld)
lastdate = datetime.strptime(date_text.group(0), '%d.%m.%Y - %H:%M')
else:
lastdate = datetime.now() - timedelta(days=120)
req = session.get('https://ankara.meb.gov.tr/www/duyurular/kategori/2')
req.encoding = 'ISO-8859-9'
res = BeautifulSoup(req.text, 'html5lib')
titles_tags = res.select('div#content div.post h3')
titles = [t for t in titles_tags if 'sonu' in t.text.lower()]
init(token)
for t in reversed(titles):
date_tag = t.parent.find('small', class_='trans')
date_re = re.search(r'\d{2}\.\d{2}\.\d{4} - \d{2}:\d{2}', date_tag.text)
date_text = date_re.group(0)
date = datetime.strptime(date_text, '%d.%m.%Y - %H:%M')
if date > lastdate:
title = t.text
url = "https://ankara.meb.gov.tr" + t.parent.find('a')['href']
Client(user_key).send_message("Ankara Meb", title=title, url=url, priority=1)
with tmp_file.open('w') as f:
f.write(date_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment