가온누리 알리미 서비스 입니다!
가온누리 공지에 새로운 글이 올라올 때마다 알림이 갑니다.
알림을 누르시면 가온누리 공지 페이지로 들어가실 수 있습니다
계속 실행이 되지 않으신다면 login.info라는 파일을 찾아 삭제해주시길 바랍니다!
소스코드
from win10toast import ToastNotifier
import webbrowser
import requests
from bs4 import BeautifulSoup
import time
import os.path
from tkinter import simpledialog ,Tk
toast = ToastNotifier()
toast.show_toast(title="가온누리 알리미 서비스가 시작됩니다!",duration=1, msg="눌러주세요!", icon_path='icon.ico', callback_on_click=lambda:webbrowser.open('https://andy-program-explore.tistory.com/11',new=2))
def nofify(url):
toast = ToastNotifier()
toast.show_toast(title="새로운 가온누리 공지가 올라왔습니다", msg="열려면 클릭해주세요!", icon_path='icon.ico', callback_on_click=lambda:webbrowser.open(url,new=2))
master = Tk()
master.withdraw()
right_string='''<?xml version="1.0" encoding="UTF-8"?>
<response>
<error>0</error>
<message>success</message>
<message_type></message_type>
</response>'''
url='https://gaonnuri.ksain.net/xe/index.php'
headers={'Host': 'gaonnuri.ksain.net',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0',
'Accept': 'application/xml, text/xml, */*; q=0.01',
'Accept-Language': 'ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'text/plain',
'X-Requested-With': 'XMLHttpRequest',
'Origin': 'https://gaonnuri.ksain.net',
'Connection': 'keep-alive',
'Referer': 'https://gaonnuri.ksain.net/xe/login'
}
headers2={
'Host': 'gaonnuri.ksain.net',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate',
'Referer': 'http://gaonnuri.ksain.net/xe/?mid=home',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'Cache-Control': 'max-age=0'
}
def data_gaonnuri(x,y):
return '''<?xml version="1.0" encoding="utf-8" ?>
<methodCall>
<params>
<_filter>widget_login</_filter>
<error_return_url>/xe/login</error_return_url>
<mid>login</mid>
<user_id>%s</user_id>
<password>%s</password>
<module>member</module>
<act>procMemberLogin</act>
</params>
</methodCall>'''%(x,y)
def main(id,password):
list_new_notice=[]
with requests.Session() as s:
r=s.post(url,headers=headers,data=data_gaonnuri(id,password))
if r.text==right_string:
toast = ToastNotifier()
toast.show_toast(title="성공!",duration=1, msg="시작합니다!", icon_path='icon.ico')
r=s.get('http://gaonnuri.ksain.net/xe/board_notice',headers=headers2)
soup=BeautifulSoup(r.text,features="html.parser")
list_link=soup.find_all("td", class_="title")
for x in list_link:
a=x.find('a')
list_new_notice.append(a['href'])
else:
toast = ToastNotifier()
toast.show_toast(title="비밀 번호나 아이디가 틀렸어요ㅜㅠ",duration=1, msg="다시 입력해 주세요!", icon_path='icon.ico')
get_input()
exit()
file = open("url.url", "r")
content = file.readlines()
content = [x.strip() for x in content]
list_final=list(set(list_new_notice).difference(content))
file.close()
if x!=[]:
for x in list_final:
nofify(x)
time.sleep(10)
file = open("url.url", "a")
for x in list_final:
file.write(x+'\n')
file.close()
def get_input():
a=simpledialog.askstring(title="아이디",prompt="아이디를 적어주세요:")
b=simpledialog.askstring(title="비밀번호",prompt="가온누리 비밀번호를 적어주세요:")
file=open('login.info','w')
file.write(a+' '+b)
file.close()
while True:
main(a,b)
time.sleep(600)
def read_input():
file=open('login.info','r')
list_1=file.readline().split()
file.close()
a=list_1[0]
b=list_1[1]
while True:
main(a,b)
time.sleep(600)
if os.path.isfile('login.info'):
read_input()
else:
get_input()
get_input()
'프로젝트 저장소' 카테고리의 다른 글
Html로 게임 만들기 (0) | 2020.04.26 |
---|---|
멜론 플레이리스트 다운로더 / 다운로드 방법 (4) | 2020.04.26 |