forked from NJUPT-ACM-Team/RankPage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.py
More file actions
38 lines (33 loc) · 899 Bytes
/
Copy pathupdate.py
File metadata and controls
38 lines (33 loc) · 899 Bytes
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
from rank.utils.parser import *
from rank.database import Session
from rank.database.models import *
import datetime
import time
import requests
URL = 'http://acm.njupt.edu.cn/acmhome/contestRankList.do?&contestId=240&page=%d'
def get_rows():
rows = []
for i in range(1, 13):
url = URL % i
print(url)
r = requests.get(url)
r.encoding='utf8'
try:
rs = parse_page(r.text)
except Exception as var:
print(var)
rows = rows + rs
return rows
def get_html():
rows = get_rows()
return put_rows_together(rows)
def update():
html = get_html()
rank = RankPage(html=html, time=datetime.datetime.now())
Session.add(rank)
Session.commit()
r = Session.query(RankPage).order_by(RankPage.id.desc()).first()
if __name__ == '__main__':
while True:
update()
time.sleep(40)