Last active
November 10, 2015 12:28
-
-
Save Erliz/b4c7801d1452bdcfa99d to your computer and use it in GitHub Desktop.
Slack news sender from yandex main page
This file contains hidden or 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
| from lxml import html | |
| import os.path | |
| import requests | |
| import json | |
| if os.path.isfile("settings.py"): | |
| from settings import * | |
| else: | |
| webHookData = { | |
| "text": "test", | |
| "username": "bot-name", | |
| "channel": "#general" | |
| } | |
| webHookUrl = 'http://localhost' | |
| def getTopMoscowNews(): | |
| page = requests.get('https://www.yandex.ru/') | |
| tree = html.fromstring(page.content) | |
| rawNews = tree.xpath('//div[@class="b-tabs__block i-hidden"]/ul[@class="b-news-list"]/li[@class="b-news-list__item"]/a[@class="b-link b-link_type_colored"]') | |
| newsPost = '' | |
| newsCounter = 1 | |
| for news in rawNews: | |
| newsPost += str(newsCounter) + '. ' + news.text_content() + "\n" | |
| newsCounter += 1 | |
| return newsPost | |
| def getTopBreakingMadNews(): | |
| page = requests.get('http://breakingmad.me/ru/comedy/') | |
| tree = html.fromstring(page.content) | |
| rawNews = tree.xpath('//div[@class="news-row"]/h2') | |
| newsPost = '' | |
| newsCounter = 1 | |
| for news in rawNews: | |
| if newsCounter > 5: | |
| break | |
| newsPost += str(newsCounter) + '. ' + news.text_content() + "\n" | |
| newsCounter += 1 | |
| return newsPost | |
| webHookData['text'] = getTopBreakingMadNews() | |
| print("sending " + str(webHookData['text'].count('\n')) + " news to channel " + webHookData['channel'] + "\n") | |
| requests.post(webHookUrl, None, webHookData) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment