-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflight.py
More file actions
96 lines (81 loc) · 2.9 KB
/
flight.py
File metadata and controls
96 lines (81 loc) · 2.9 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import requests
from bs4 import BeautifulSoup
import notify
import datetime
import sqlite3
"""
cron: */10 * * * *
new Env('航空公司公告通知');
"""
conn = sqlite3.connect('flight.db')
def init_db():
# 连仓库
# 建表
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS NOTIFY
(ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
COMPANY VARCHAR(200) NOT NULL,
TITLE VARCHAR(2000) NOT NULL
);''')
def check_db_exist(company,title):
c = conn.cursor()
c.execute('select count(1) from NOTIFY WHERE COMPANY = ? AND TITLE = ?',[company,title])
count = c.fetchone()[0]
if count > 0:
return True
else:
c.execute('INSERT INTO NOTIFY (COMPANY,TITLE) VALUES (?,?)',[company,title])
conn.commit()
def check_ca():
ca_url = "http://www.airchina.com.cn/cn/info/new-service/service_announcement.shtml"
response = requests.get(ca_url)
soup = BeautifulSoup(response.text, 'html.parser')
links = soup.select("div.serviceMsg a")
today = datetime.date.today().strftime("%Y-%m-%d")
notify_message = ""
for link in links:
title = link.text
create_date = link.nextSibling.text[1:-1]
if today == create_date:
if not check_db_exist('CA',title):
notify_message += title + ":" + create_date + '\n'
if notify_message:
notify.send("国航今日通知", notify_message)
def check_mu():
mu_url = "https://www.ceair.com/global/static/Announcement/AnnouncementMessage/notices/"
response = requests.get(mu_url)
soup = BeautifulSoup(response.content, 'html.parser')
links = soup.select("div.uw_chntent_right_text span.right_span")
today = datetime.date.today().strftime("%Y-%m-%d")
notify_message = ""
for link in links:
title = link.text
create_date = link.nextSibling.nextSibling.text.strip()
if today == create_date:
if not check_db_exist('MU', title):
notify_message += title + ":" + create_date + '\n'
if notify_message:
notify.send("东航今日通知", notify_message)
def check_cz():
cz_url = "https://www.csair.com/cn/about/news/notice/2022/"
response = requests.get(cz_url)
soup = BeautifulSoup(response.content, 'html.parser')
links = soup.select("div.tabContent>ul>li>a")
today = datetime.date.today().strftime("%Y-%m-%d")
notify_message = ""
for link in links:
title = link.text
if link.nextSibling:
create_date = link.nextSibling.text[1:-1]
else:
create_date = ""
if today == create_date:
if not check_db_exist('CZ', title):
notify_message += title + ":" + create_date + '\n'
if notify_message:
notify.send("南航今日通知", notify_message)
if __name__ == '__main__':
init_db()
check_ca()
check_mu()
check_cz()