adding slack-bot

This commit is contained in:
2019-10-02 01:16:27 +01:00
parent cc1f1e8d71
commit 13123f372f
5 changed files with 100 additions and 0 deletions

54
slack-bot/scraper.py Normal file
View File

@@ -0,0 +1,54 @@
from bs4 import BeautifulSoup
from selenium import webdriver
import emoji
from datetime import datetime
url = 'http://www.trafficengland.com/traffic-alerts'
# prepare the option for the chrome driver
options = webdriver.ChromeOptions()
options.add_argument('headless')
# start the chrome driver
browser = webdriver.Chrome(chrome_options=options)
browser.get(url)
html = browser.page_source
soup = BeautifulSoup(html, features='lxml')
# soup.find_all(class_='alerts-severity-Severe')
def printBreak():
print('\n')
table = soup.find_all('td')
list = []
for item in table:
list.append(item)
for i in range(0, 4):
print(list[i])
printBreak()
totalItems = int(len(list) / 4)
for i in range(0, 4):
print(list[i].string)
printBreak()
newList = ([x.text for x in soup.find_all('td')])
currentTime = datetime.now().strftime('%H:%M:%S')
print(emoji.emojize('Did someone say M62 :anguished:!? Let'
'\'s check the latest updates from Highways'
' England! :police_car::rotating_light:',
use_aliases=True))
print(f'As of {currentTime}, there is currently a {newList[2]} {newList[1]}'
f' on the {newList[0]}')
# print(list[3].prettify())
print(str(list[3]))