티스토리 뷰

모각코

모각코 1월 17일 결과

AI의 호흡 2019. 1. 17. 16:58
import telegram
from telegram.ext import Updater,MessageHandler, Filters, CommandHandler
import requests
from multiprocessing import Process
from bs4 import BeautifulSoup
import os
import time
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
my_token = '645804650:AAEFzjMH_sL6fU3oj-k12pCsLexAw8Uyzjs'
bot = telegram.Bot(token=my_token)
updates = bot.getUpdates()
chat_id = "702266940"
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
def m():
def start(bot, update):
with open(os.path.join(BASE_DIR, 'hello.txt'), 'r+') as f_read:
hello = f_read.read()
bot.sendMessage(chat_id=chat_id, text=hello)

def depart(bot, update):
depart_notice = requests.get('http://computer.cnu.ac.kr/index.php?mid=notice')
depart_notice.encoding = 'utf-8'
depart_html = depart_notice.text
depart_soup = BeautifulSoup(depart_html, 'html.parser')
update.message.reply_text("depart")
a = ""
for text in depart_soup.select("tr.notice >td.title > a"):
a = a + "\n" + text.text + "\n" + text.get('href')
for no in depart_soup.select("td.title > a.hx"):
a = a + no.text.replace(" ", "") + "\n" + text.get('href')
bot.sendMessage(chat_id=chat_id, text=a)

with open(os.path.join(BASE_DIR, 'hello.txt'), 'r+') as f_read:
hello = f_read.read()
bot.sendMessage(chat_id=chat_id, text=hello)

def com(bot, update):
com_notice = requests.get('http://computer.cnu.ac.kr/index.php?mid=gnotice')
com_notice.encoding = 'utf-8'
com_html = com_notice.text
com_soup = BeautifulSoup(com_html, 'html.parser')
update.message.reply_text("com")
a = ""
for text in com_soup.select("tr.notice >td.title > a"):
a = a + "\n" + text.text + "\n" + text.get('href')
for no in com_soup.select("td.title > a.hx"):
a = a + no.text.replace(" ", "") + "\n" + text.get('href')
bot.sendMessage(chat_id=chat_id, text=a)

with open(os.path.join(BASE_DIR, 'hello.txt'), 'r+') as f_read:
hello = f_read.read()
bot.sendMessage(chat_id=chat_id, text=hello)

def sa(bot, update):
sa_notice = requests.get('http://computer.cnu.ac.kr/index.php?mid=saccord')
sa_notice.encoding = 'utf-8'
sa_html = sa_notice.text
sa_soup = BeautifulSoup(sa_html, 'html.parser')
update.message.reply_text("sa")
a = ""
for text in sa_soup.select("tr.notice >td.title > a"):
a = a + "\n" + text.text + "\n" + text.get('href')
for no in sa_soup.select("td.title > a.hx"):
a = a + no.text.replace(" ", "") + "\n" + text.get('href')
bot.sendMessage(chat_id=chat_id, text=a)

with open(os.path.join(BASE_DIR, 'hello.txt'), 'r+') as f_read:
hello = f_read.read()
bot.sendMessage(chat_id=chat_id, text=hello)

def job(bot, update):
job_notice = requests.get('http://computer.cnu.ac.kr/index.php?mid=job')
job_notice.encoding = 'utf-8'
job_html = job_notice.text
job_soup = BeautifulSoup(job_html, 'html.parser')
update.message.reply_text("job")
a = ""
for text in job_soup.select("tr.notice >td.title > a"):
a = a + "\n" + text.text + "\n" + text.get('href')
for no in job_soup.select("td.title > a.hx"):
a = a + no.text.replace(" ", "") + "\n" + text.get('href')
bot.sendMessage(chat_id=chat_id, text=a)

with open(os.path.join(BASE_DIR, 'hello.txt'), 'r+') as f_read:
hello = f_read.read()
bot.sendMessage(chat_id=chat_id, text=hello)

updater = Updater(my_token)
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', start))
dp.add_handler(CommandHandler('depart', depart))
dp.add_handler(CommandHandler('com', com))
dp.add_handler(CommandHandler('sa', sa))
dp.add_handler(CommandHandler('job', job))
updater.start_polling(timeout=1, clean=True)
updater.idle()
def main():
while True:
depart_notice = requests.get('http://computer.cnu.ac.kr/index.php?mid=notice')
depart_notice.encoding = 'utf-8'
depart_html = depart_notice.text
depart_soup = BeautifulSoup(depart_html, 'html.parser')
depart_notice1 = depart_soup.select('td.title > a')
depart_notice2 = depart_soup.select('td.title > a.hx')
menu = depart_soup.select('#gnb > ul > li.active > ul > li:nth-child(1)')
depart_latest1 = depart_notice1[0].text
depart_latest2 = depart_notice2[0].text
with open(os.path.join(BASE_DIR, 'depart_latest1.txt'), 'r+') as f_read:
before = f_read.read()
if before != depart_latest1:
text = menu[0].text + "\n" + depart_latest1 + depart_notice1[0].get('href')
bot.sendMessage(chat_id=chat_id, text=text)
else:
pass
with open(os.path.join(BASE_DIR, 'depart_latest1.txt'), 'w+') as f:
f.write(depart_latest1)
with open(os.path.join(BASE_DIR, 'depart_latest2.txt'), 'r+') as f_read:
before = f_read.read()
if before != depart_latest2:
text = menu[0].text + depart_latest2.replace(" ", "") + depart_notice2[0].get('href')
bot.sendMessage(chat_id=chat_id, text=text)
else:
pass
with open(os.path.join(BASE_DIR, 'depart_latest2.txt'), 'w+') as f:
f.write(depart_latest2)

com_notice = requests.get('http://computer.cnu.ac.kr/index.php?mid=gnotice')
com_notice.encoding = 'utf-8'
com_html = com_notice.text
com_soup = BeautifulSoup(com_html, 'html.parser')
com_notice1 = com_soup.select('td.title > a')
com_notice2 = com_soup.select('td.title > a.hx')
menu = depart_soup.select('#gnb > ul > li.active > ul > li:nth-child(2)')
com_latest1 = com_notice1[0].text
com_latest2 = com_notice2[0].text

with open(os.path.join(BASE_DIR, 'com_latest1.txt'), 'r+') as f_read:
before = f_read.read()
if before != com_latest1:
text = menu[0].text + "\n" + com_latest1 + com_notice1[0].get('href')
bot.sendMessage(chat_id=chat_id, text=text)
else:
pass

with open(os.path.join(BASE_DIR, 'com_latest1.txt'), 'w+') as f:
f.write(com_latest1)

with open(os.path.join(BASE_DIR, 'com_latest2.txt'), 'r+') as f_read:
before = f_read.read()
if before != com_latest2:
text = menu[0].text + com_latest2.replace(" ", "") + com_notice2[0].get('href')
bot.sendMessage(chat_id=chat_id, text=text)
else:
pass

with open(os.path.join(BASE_DIR, 'com_latest2.txt'), 'w+') as f:
f.write(com_latest2)

sa_notice = requests.get('http://computer.cnu.ac.kr/index.php?mid=saccord')
sa_notice.encoding = 'utf-8'
sa_html = sa_notice.text
sa_soup = BeautifulSoup(sa_html, 'html.parser')
sa_notice1 = sa_soup.select('td.title > a')
sa_notice2 = sa_soup.select('td.title > a.hx')
menu = depart_soup.select('#gnb > ul > li.active > ul > li:nth-child(3)')
sa_latest1 = sa_notice1[0].text
sa_latest2 = sa_notice2[0].text

with open(os.path.join(BASE_DIR, 'sa_latest1.txt'), 'r+') as f_read:
before = f_read.read()
if before != sa_latest1:
text = menu[0].text + "\n" + sa_latest1 + sa_notice1[0].get('href')
bot.sendMessage(chat_id=chat_id, text=text)
else:
pass

with open(os.path.join(BASE_DIR, 'sa_latest1.txt'), 'w+') as f:
f.write(sa_latest1)

with open(os.path.join(BASE_DIR, 'sa_latest2.txt'), 'r+') as f_read:
before = f_read.read()
if before != sa_latest2:
text = menu[0].text + sa_latest2.replace(" ", "") + sa_notice2[0].get('href')
bot.sendMessage(chat_id=chat_id, text=text)
else:
pass

with open(os.path.join(BASE_DIR, 'sa_latest2.txt'), 'w+') as f:
f.write(sa_latest2)

job_notice = requests.get('http://computer.cnu.ac.kr/index.php?mid=job')
job_notice.encoding = 'utf-8'
job_html = job_notice.text
job_soup = BeautifulSoup(job_html, 'html.parser')
job_notice1 = job_soup.select('td.title > a')
job_notice2 = job_soup.select('td.title > a.hx')
menu = depart_soup.select('#gnb > ul > li.active > ul > li:nth-child(4)')
job_latest1 = job_notice1[0].text
job_latest2 = job_notice2[0].text

with open(os.path.join(BASE_DIR, 'job_latest1.txt'), 'r+') as f_read:
before = f_read.read()
if before != job_latest1:
text = menu[0].text + "\n" + job_latest1 + job_notice1[0].get('href')
bot.sendMessage(chat_id=chat_id, text=text)
else:
pass

with open(os.path.join(BASE_DIR, 'job_latest1.txt'), 'w+') as f:
f.write(job_latest1)

with open(os.path.join(BASE_DIR, 'job_latest2.txt'), 'r+') as f_read:
before = f_read.read()
if before != job_latest2:
text = menu[0].text + job_latest2.replace(" ", "") + job_notice2[0].get('href')
bot.sendMessage(chat_id=chat_id, text=text)
else:
pass

with open(os.path.join(BASE_DIR, 'job_latest2.txt'), 'w+') as f:
f.write(job_latest2)

time.sleep(10)

p1 = Process(target = m)
p2 = Process(target = main)
p1.start()
p2.start()

멀티프로세싱하다가 시간이 없어서 못하였다.

일단 우리 학교 학과 공지사항을 얻어오고 새글이 올라오면 알려주는 기능과

각 메뉴마다 보고 싶은 것을 입력하면 보여주는 기능

두가지는 따로 되지만

같이 하면 안돼서

멀티 프로세싱도 해야겠다.

'모각코' 카테고리의 다른 글

모각코 1월22일 결과  (0) 2019.01.22
모각코 1월22일  (0) 2019.01.22
모각코 1월17일  (0) 2019.01.17
ftz level10  (0) 2019.01.15
ftz level9 plus  (0) 2019.01.15
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2026/03   »
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
글 보관함