-
Notifications
You must be signed in to change notification settings - Fork 2
/
jungle-bot.py
94 lines (86 loc) · 3.31 KB
/
jungle-bot.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
from re import split
import requests
import time
from bs4 import BeautifulSoup
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
page = requests
def main() :
print('check your request..')
## webhook url
webhook_url = "webhook-url"
moonjicam_url = "https://www.kaist.ac.kr/kr/html/campus/053001.html?dvs_cd=icc"
text = "Jungle Bot Text."
title, breakfast, lunch, dinner = get_umsik(moonjicam_url)
breakfast = " , ".join(breakfast)
lunch = " , ".join(lunch)
dinner = " , ".join(dinner)
messages = ["정글 여러분 오늘도 ~행복한~ 코딩해요. 👨💻",
"메리 크리스마스 Merry Christmas. ❄☃🌞",
]
payload = {
# "text": title + " (<%s|Click here.>)\n " % moonjicam_url + breakfast + "\n" + lunch + "\n" + dinner ,
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "🍜 " + title,
"emoji": True
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
# {
# "type": "mrkdwn",
# "text": "*아침*\n" + breakfast +"\n\n*점심*\n" + lunch + "\n\n*저녁*\n" + dinner,
# },
"type": "mrkdwn",
"text": "*[ 아 침 ]*\n - " + breakfast +"\n\n*[ 점 심 ]*\n - " + lunch + "\n\n*[ 저 녁 ]*\n - " + dinner,
},
"accessory": {
"type": "image",
"image_url": "https://i.pinimg.com/236x/3f/08/7f/3f087fef430d0fc0c84a9984eec222d1.jpg",
"alt_text": "맛없어도 먹어야해!"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": messages[0] + " <"+ moonjicam_url +"|campus link > | <https://sunio00000.github.io/contact|contact me>"
}
},
]
}
requests.post(webhook_url, json=payload)
print('ok. your request sended.')
#scraping
def get_umsik(url : str):
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# browser = webdriver.Chrome(ChromeDriverManager().install())
# browser = webdriver.Chrome(executable_path="/usr/bin/chromedriver.exe", options=options)
browser = webdriver.Chrome(options=options)
browser.get(url)
time.sleep(3)
html = browser.page_source
soup = BeautifulSoup(html, 'html.parser')
title = soup.select_one('#tab_item_1 > h3').text
td_first = soup.select('#tab_item_1 > table > tbody > tr > td:nth-child(1)')[0]
td_second = soup.select('#tab_item_1 > table > tbody > tr > td:nth-child(2)')[0]
td_third = soup.select('#tab_item_1 > table > tbody > tr > td:nth-child(3)')[0]
return (title, td_first.text.split(), td_second.text.split(), td_third.text.split())
#! this script using main function.
if __name__ == "__main__" :
main()