-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlilac_menu.py
132 lines (93 loc) · 2.63 KB
/
lilac_menu.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import json
import sys
import pandas as pd
import numpy as np
from datetime import date
from urllib.request import urlopen
from bs4 import BeautifulSoup
import os
from twilio.rest import Client
import schedule
import time
def this_week() :
main = 'https://www.pknu.ac.kr/main/399'
html = urlopen(main)
soup = BeautifulSoup(html, "html.parser")
hotKeys = soup.select("a")[199]['href']
adr = f'{main}{hotKeys}'
html = urlopen(adr)
soup = BeautifulSoup(html, "html.parser")
hotKeys = soup.select("p")
menu = []
for t in hotKeys[28:93]:
#print(t)
a=str(t)[:89]
#print(a)
if(a=='<p style="margin: 0pt; word-break: keep-all; vertical-align: bottom; line-height: 130%;">'):
#print(t)
menu.append(t)
week = [[], [], [], [], []]
idx = 0
before = 0
for n,i in enumerate(menu) :
if str(i)[-5] == '밥' and n !=0 and n - before > 3 :
idx += 1
before = n
week[idx].append(str(i)[89:-4])
else:
week[idx].append(str(i)[89:-4])
return week
def before_week() :
main = 'https://www.pknu.ac.kr/main/399'
html = urlopen(main)
soup = BeautifulSoup(html, "html.parser")
hotKeys = soup.select("a")[200]['href']
adr = f'{main}{hotKeys}'
html = urlopen(adr)
soup = BeautifulSoup(html, "html.parser")
hotKeys = soup.select("p")
menu = []
for t in hotKeys[28:93]:
#print(t)
a=str(t)[:89]
#print(a)
if(a=='<p style="margin: 0pt; word-break: keep-all; vertical-align: bottom; line-height: 130%;">'):
#print(t)
menu.append(t)
week = [[], [], [], [], []]
idx = 0
before = 0
for n,i in enumerate(menu) :
if str(i)[-5] == '밥' and n !=0 and n - before > 3 :
idx += 1
before = n
week[idx].append(str(i)[89:-4])
else:
week[idx].append(str(i)[89:-4])
return week
#twilo_setting
account_sid = 'AC4a97b7b6a8bcead112bac3964e98d518'
auth_token = 'a303bc0955ecb9075536c1ff8131776f'
client = Client(account_sid, auth_token)
tit = ['Monday','Tuesday','Wednesday','Thursday','Friday']
#send message
def send_msg():
today = date.weekday(date.today())
if (today < 4):
week = this_week()
ms = f'****오늘의 라일락 메뉴****\n{str(week[today])[1:-1]}'
elif(today==4):
week = before_week()
ms = f'****오늘의 라일락 메뉴****\n{str(week[today])[1:-1]}'
if(today < 5):
message = client.messages.create(
to="+821041734742",
from_="+17755356857",
body=ms)
print('메세지 전송 완료')
#print(message.sid)
#set 주기
schedule.every().day.at("11:00").do(send_msg)
while True:
schedule.run_pending()
time.sleep(1)