-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbot.py
More file actions
82 lines (63 loc) · 2.42 KB
/
bot.py
File metadata and controls
82 lines (63 loc) · 2.42 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import time
import requests
import logging
import subprocess
import urllib.request
import time
import feedparser
from bs4 import BeautifulSoup
from datetime import datetime, date, timedelta
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
def start(update, context):
username = update.message.chat.username
update.message.reply_text('Hi master %s, I\'m here to serve you!' % (username))
logger.info("Command /start from %s" % (username))
def conferencias(update, context):
reader = open('/home/pi/Scripts/Bots/HackerOpsBot/conferencias.txt','r')
try:
update.message.reply_text(reader.read())
finally:
reader.close()
username = update.message.chat.username
logger.info("Command /conferencias from %s" % (username))
def thehackernews(update, context):
url = 'https://thehackernews.com/'
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
tags = soup.findAll('a',{"class": "story-link"})
for tag in tags[:3]:
update.message.reply_text(tag.get("href"))
username = update.message.chat.username
logger.info("Command /noticias from %s" % (username))
def threatpost(update, context):
NewsFeed = feedparser.parse("https://threatpost.com/feed/")
username = update.message.chat.username
for entry in NewsFeed.entries[:3]:
update.message.reply_text(entry.link)
def SANSInternetStormCenter(update, context):
NewsFeed = feedparser.parse("https://isc.sans.edu/rssfeed_full.xml")
username = update.message.chat.username
for entry in NewsFeed.entries[:3]:
update.message.reply_text(entry.link)
def error(update, context):
logger.warning('Update "%s" caused error "%s"', update, context.error)
def main():
updater = Updater("<API_KEY>", use_context=True)
logger.info("Bot encendido")
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("conferencias", conferencias))
dp.add_handler(CommandHandler("thehackernews", thehackernews))
dp.add_handler(CommandHandler("threatpost", threatpost))
dp.add_handler(CommandHandler("internetStormCenter", SANSInternetStormCenter))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()