Created
September 17, 2017 07:28
-
-
Save return0927/6c9df0bf88cfa067ee8bf6a58c0df443 to your computer and use it in GitHub Desktop.
Naver CAFE Board Lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codecs, requests | |
from bs4 import BeautifulSoup as bs | |
from settings import * | |
from time import time | |
setting = {} | |
class report(): | |
def __init__(): | |
global setting | |
setting = settings.get() | |
def croll(): | |
global setting | |
req = requests.get( setting['url'] ) | |
soup = bs(req.text, 'html.parser') | |
articles = soup.findAll('li', attrs={'class':'board_box'}) | |
articles.reverse() | |
prop = [] | |
for article in articles: | |
no = int(article.find('a')['data-article-id']) | |
if no > setting['lastbrowse']: | |
prop.append( {'Title': article.find('strong').text.replace("\n","").replace(" ",""), 'AuthorNick': article.find('a').find('span', attrs={'class':'ellip'}).text, 'Time': article.find('div', attrs={'class':'user_area'}).find('span',attrs={'class':'time'}).text, 'ArticleNo': no, "ArticleUrl":"http://cafe.naver.com/kkutukorea/%s"%no}) | |
setting['lastbrowse'] = no | |
report.webhook(prop) | |
settings.save(json.dumps(setting)) | |
def webhook(prop): | |
for d in prop: | |
data = { | |
'username':"끄투코리아 카페", | |
'avatar_url':"http://cafe.naver.com/favicon.ico", | |
'tts':False, | |
'embeds': [{ | |
'color': 3447003, | |
'title': "Naver Cafe", | |
'description': "새 글이 등록되었습니다.", | |
'fields': [ {"name": key, "value": d[key], "inline":False} for key in d.keys() | |
] , | |
'footer': { | |
'text': "ⓒ KKuTu Korea" | |
} | |
}] | |
} | |
h = requests.post(setting['webhook'], data=json.dumps(data), headers={'Content-type':'multipart/form-data'}) | |
print(h.text) | |
report.__init__() | |
start = 0 | |
while True: | |
if time() - start > 30: | |
report.croll() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment