-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
39 lines (31 loc) · 1.06 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import json
from pyquery import PyQuery as pq
url = "https://sks.klu.edu.tr/Takvimler/73-yemek-takvimi.klu"
#webpage = pq(url = url)
webpage = ""
import urllib3
from urllib3.util.ssl_ import create_urllib3_context
import certifi
import ssl
ctx = create_urllib3_context()
ctx.load_default_certs()
ctx.options |= 0x4 # ssl.OP_LEGACY_SERVER_CONNECT
with urllib3.PoolManager(ssl_context=ssl.create_default_context(cafile=certifi.where())) as http:
webpage = http.request("GET", url)
print(webpage.status)
data = pq(webpage.data)
jsonIn = data.find("textarea").html()
jsonIn = jsonIn.replace('\\n', '')
getDay = json.loads(jsonIn)
currentMonth = getDay[0]["start"].replace(' 00:00:00 ', '').split('-')[1]
counter = 0
out = []
while currentMonth in getDay[counter]['start']:
out.append({'day' : getDay[counter]['title'],
'date': getDay[counter]['start'].replace(' 00:00:00 ', ''),
'content': getDay[counter]['aciklama']})
#print(getDay[counter]['title'])
counter = counter + 1
f = open("list.json", "w")
f.write(json.dumps(out, indent=2))
f.close()