-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (36 loc) · 1.07 KB
/
main.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
40
41
42
43
44
45
46
from logging import getLogger
from src import settings
from src.utils import (
fetch_html,
get_latest_year_term,
get_year_terms,
insert_year_term,
is_new_term,
)
# __name__では__main__になるので、直接srcを指定する。
logger = getLogger("src")
def main():
try:
html = fetch_html(settings.HOKUDAI_GRADE_URL)
except Exception as e:
logger.error(f"fetch_html() failure: {e}")
exit(1)
year_terms = get_year_terms(html)
now_latest = get_latest_year_term(year_terms)
isNew = None
try:
isNew = is_new_term(now_latest)
except Exception as e:
logger.error(f"is_new_term() failure: {e}")
exit(1)
if isNew:
try:
insert_year_term(now_latest)
except Exception as e:
logger.error(f"insert_year_term() failure: {e}")
exit(1)
logger.info("新たな成績が公開されました。", extra={"notify_slack": True})
else:
logger.info("成績は更新されていません。")
if __name__ == "__main__":
main()