completed full run script
This commit is contained in:
BIN
slack-bot/traffic-scraper/.DS_Store
vendored
Normal file
BIN
slack-bot/traffic-scraper/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -1 +0,0 @@
|
|||||||
["START", "Did someone say M62!? \ud83d\ude27 Let's check the latest updates from Highways England as of 00:30:21! \ud83d\ude93\ud83d\udea8", "There are currently no reported congestion incidents on the M62 \ud83e\udd14", "There are currently no reported accident incidents on the M62 \ud83e\udd14", "Hey Andy, have you thought about getting the train? \ud83d\ude85", "END"]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
["START", "Did someone say M62!? \ud83d\ude27 Let's check the latest updates from Highways England as of 01:47:03! \ud83d\ude93\ud83d\udea8", "There are currently no reported congestion incidents on the M62 \ud83e\udd14", "There are currently no reported accident incidents on the M62 \ud83e\udd14", "Don't fret, Andy can always work from home! \ud83c\udfe1", "END", "START", "Did someone say M62!? \ud83d\ude27 Let's check the latest updates from Highways England as of 01:47:03! \ud83d\ude93\ud83d\udea8", "There are currently no reported congestion incidents on the M62 \ud83e\udd14", "There are currently no reported accident incidents on the M62 \ud83e\udd14", "Don't fret, Andy can always work from home! \ud83c\udfe1", "END"]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
["START"]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
["Did someone say M62!? \ud83d\ude27 Let's check the latest updates from Highways England as of 01:47:03! \ud83d\ude93\ud83d\udea8"]
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
["There are currently no reported congestion incidents on the M62 \ud83e\udd14", "There are currently no reported accident incidents on the M62 \ud83e\udd14", "Don't fret, Andy can always work from home! \ud83c\udfe1", "END"]
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
8
slack-bot/traffic-scraper/prd/loadResults.py
Normal file
8
slack-bot/traffic-scraper/prd/loadResults.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
with open('/Users/dtomlinson/OneDrive - William Hill Organisation Limited'
|
||||||
|
'/Mac/git_repos/python-VM/slack-bot/traffic-scraper/'
|
||||||
|
'prd/12-10-2019_02:53:32.json', 'r') as jsonFile:
|
||||||
|
data = json.load(jsonFile)
|
||||||
|
for item in data:
|
||||||
|
print(item)
|
||||||
@@ -186,7 +186,7 @@ class getTrafficInfo(object):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
inst = getTrafficInfo.getTrafficURL('M62').findIncidents() \
|
# inst = getTrafficInfo.getTrafficURL('M62').findIncidents() \
|
||||||
.getIncidentInformation().generateOutput()
|
# .getIncidentInformation().generateOutput()
|
||||||
for i in inst.output:
|
# for i in inst.output:
|
||||||
print(i)
|
# print(i)
|
||||||
|
|||||||
@@ -127,34 +127,15 @@ class receiveFromSQS(object):
|
|||||||
)
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def generateOutput(self, type='json'):
|
# def generateOutput(self, outputType='json'):
|
||||||
if type == 'json':
|
# if outputType == 'json':
|
||||||
self.output = json.dumps(self.messages)
|
# self.output = json.dumps(self.messages)
|
||||||
return self.output
|
# return self.output
|
||||||
|
|
||||||
def savetoDisk(self, path):
|
def savetoDisk(self, path):
|
||||||
self.timeNow = datetime.now().strftime('%d-%m-%Y_%H:%M:%S')
|
self.timeNow = datetime.now().strftime('%d-%m-%Y_%H:%M:%S')
|
||||||
if self.output is None:
|
|
||||||
self.generateOutput()
|
|
||||||
if len(self.messages) > 0:
|
if len(self.messages) > 0:
|
||||||
with open(f'{path}/{self.timeNow}.json', 'w+') as outputFile:
|
with open(f'{path}/{self.timeNow}.json', 'w+') as outputFile:
|
||||||
outputFile.write(self.output)
|
json.dump(self.messages, outputFile)
|
||||||
else:
|
else:
|
||||||
print('No messages to save')
|
print('No messages to save')
|
||||||
|
|
||||||
|
|
||||||
inst = receiveFromSQS.createSession(
|
|
||||||
profileName='plex-aws',
|
|
||||||
queueURL='https://sqs.eu-west-1.amazonaws'
|
|
||||||
'.com/745437999005/slack-bot.fifo',
|
|
||||||
)
|
|
||||||
|
|
||||||
output = inst.receiveNMessages(numberOfMessages=4).generateOutput(type='json')
|
|
||||||
inst.savetoDisk(
|
|
||||||
'/Users/dtomlinson/OneDrive - William Hill'
|
|
||||||
' Organisation Limited/Mac/git_repos/python-VM/slack-bot/traffic-scraper'
|
|
||||||
'/prd'
|
|
||||||
)
|
|
||||||
# inst.receiveAllMessages()
|
|
||||||
for item in inst.messages:
|
|
||||||
print(item)
|
|
||||||
|
|||||||
@@ -45,19 +45,19 @@ class sendToSQS(object):
|
|||||||
print(msg['MessageId'])
|
print(msg['MessageId'])
|
||||||
|
|
||||||
|
|
||||||
inst = sendToSQS.createSession(
|
# inst = sendToSQS.createSession(
|
||||||
profileName='plex-aws',
|
# profileName='plex-aws',
|
||||||
queueURL='https://sqs.eu-west-1.amazonaws.com'
|
# queueURL='https://sqs.eu-west-1.amazonaws.com'
|
||||||
'/745437999005/slack-bot.fifo',
|
# '/745437999005/slack-bot.fifo',
|
||||||
)
|
# )
|
||||||
|
|
||||||
instM = (
|
# instM = (
|
||||||
getTrafficInfo.getTrafficURL('M62')
|
# getTrafficInfo.getTrafficURL('M62')
|
||||||
.findIncidents()
|
# .findIncidents()
|
||||||
.getIncidentInformation()
|
# .getIncidentInformation()
|
||||||
.generateOutput()
|
# .generateOutput()
|
||||||
)
|
# )
|
||||||
|
|
||||||
for _ in range(0, 5):
|
# for _ in range(0, 5):
|
||||||
for item in instM.output:
|
# for item in instM.output:
|
||||||
inst.sendMessage(message=item, messageGroupId='slack-bot-M62')
|
# inst.sendMessage(message=item, messageGroupId='slack-bot-M62')
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.path.append(os.getcwd())
|
sys.path.append(os.getcwd())
|
||||||
from getTrafficInfo import getTrafficInfo
|
import pullTrafficInfo
|
||||||
from sendToSQS import sendToSQS
|
from sendToSQS import sendToSQS
|
||||||
from receiveFromSQS import receiveFromSQS
|
from receiveFromSQS import receiveFromSQS
|
||||||
|
|
||||||
inst = (
|
inst = (
|
||||||
getTrafficInfo.getTrafficURL('M62')
|
pullTrafficInfo.getTrafficInfo.getTrafficURL('M62')
|
||||||
.findIncidents()
|
.findIncidents()
|
||||||
.getIncidentInformation()
|
.getIncidentInformation()
|
||||||
.generateOutput()
|
.generateOutput()
|
||||||
@@ -19,8 +19,8 @@ instSend = sendToSQS.createSession(
|
|||||||
'/745437999005/slack-bot.fifo',
|
'/745437999005/slack-bot.fifo',
|
||||||
)
|
)
|
||||||
|
|
||||||
for item in instSend.output:
|
for item in inst.output:
|
||||||
inst.sendMessage(message=item, messageGroupId='slack-bot-M62')
|
instSend.sendMessage(message=item, messageGroupId='slack-bot-M62')
|
||||||
|
|
||||||
instReceive = receiveFromSQS(
|
instReceive = receiveFromSQS(
|
||||||
instSend.session,
|
instSend.session,
|
||||||
@@ -28,9 +28,6 @@ instReceive = receiveFromSQS(
|
|||||||
'/slack-bot.fifo',
|
'/slack-bot.fifo',
|
||||||
)
|
)
|
||||||
|
|
||||||
output = instReceive.receiveNMessages(numberOfMessages=4).generateOutput(
|
instReceive.receiveAllMessages()
|
||||||
type='json'
|
|
||||||
)
|
instReceive.savetoDisk(f'{os.getcwd()}')
|
||||||
instReceive.savetoDisk(
|
|
||||||
f'{os.getcwd()}'
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user