updating initial slackBot
This commit is contained in:
Binary file not shown.
1
slack-bot/traffic-scraper/prd/jsonPayload.json
Normal file
1
slack-bot/traffic-scraper/prd/jsonPayload.json
Normal file
@@ -0,0 +1 @@
|
||||
{"attachments": [\n {\n "title": "",\n "pretext": "Did someone say M62!? \\ud83d\\ude27",\n "text": ",\n "mrkdwn_in": ["text", "pretext"],\n "footer": "ec2-54-246-210-90.eu-west-1.compute.amazonaws.com",\n "footer_icon": "https://i.imgur.com/ADsI87O.png",\n "ts": "1570917914",\n "fields": [\n\t\t \t{\n\t\t "title": ",\n\t\t "value": ",\n\t\t "short": false\n\t\t \t},\n\t\t \t{\n\t\t "title": ",\n\t\t "value": ",\n\t\t "short": false\n\t\t \t},\n\t \t\t{\n\t\t "title": ",\n\t\t "value": " ",\n\t\t "short": false\n\t\t \t}\n\t \t]\n }\n ]\n}
|
||||
@@ -145,8 +145,6 @@ class getTrafficInfo(object):
|
||||
# self.output.append('START')
|
||||
self.output.append(
|
||||
emoji.emojize(
|
||||
f'Did someone say {self.motorway}!?'
|
||||
' :anguished:'
|
||||
' Let\'s check the latest updates'
|
||||
' from Highways England as of'
|
||||
f' {currentTime}!'
|
||||
|
||||
@@ -3,9 +3,11 @@ import os
|
||||
import glob
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import requests
|
||||
import base64
|
||||
|
||||
sys.path.append(os.getcwd())
|
||||
import pullTrafficInfo
|
||||
import http.client
|
||||
|
||||
inst = (
|
||||
pullTrafficInfo.getTrafficInfo.getTrafficURL('M62')
|
||||
@@ -70,40 +72,71 @@ if accidentMessage is None:
|
||||
accidentMessage = data[accidentMessageStart:accidentMessageEnd]
|
||||
accidentMessage = ''.join(accidentMessage)
|
||||
|
||||
print(f'messageTitle: {messageTitle}' + '\n')
|
||||
print(f'congestionTitle: {congestionTitle}' + '\n')
|
||||
print(f'congestionMessage: {congestionMessage}' + '\n')
|
||||
print(f'accidentTitle: {accidentTitle}' + '\n')
|
||||
print(f'accidentMessage: {accidentMessage}' + '\n')
|
||||
print(f'end: {end}')
|
||||
# print(f'messageTitle: {messageTitle}' + '\n')
|
||||
# print(f'congestionTitle: {congestionTitle}' + '\n')
|
||||
# print(f'congestionMessage: {congestionMessage}' + '\n')
|
||||
# print(f'accidentTitle: {accidentTitle}' + '\n')
|
||||
# print(f'accidentMessage: {accidentMessage}' + '\n')
|
||||
# print(f'end: {end}')
|
||||
|
||||
conn = http.client.HTTPConnection("hooks,slack,com")
|
||||
|
||||
payload = """{\"attachments\": [\n {\n \"title\": \"",\n \"pretext\": \"Did someone say M62!? \\ud83d\\ude27\",\n \"text\": \"\",\n \"mrkdwn_in\": [\"text\", \"pretext\"],\n \"footer\": \"ec2-54-246-210-90.eu-west-1.compute.amazonaws.com\",\n \"footer_icon\": \"https://i.imgur.com/ADsI87O.png\",\n \"ts\": \"1570917914\",\n \"fields\": [\n\t\t \t{\n\t\t \"title\": \"\",\n\t\t \"value\": \"\",\n\t\t \"short\": false\n\t\t \t},\n\t\t \t{\n\t\t \"title\": \"\",\n\t\t \"value\": \"\",\n\t\t \"short\": false\n\t\t \t},\n\t \t\t{\n\t\t \"title\": \"\",\n\t\t \"value\": \" \",\n\t\t \"short\": false\n\t\t \t}\n\t \t]\n }\n ]\n}"""
|
||||
payload = """{\"attachments\": [\n {\n \"title\": \"\",\n \"pretext\": \"Did someone say M62!? \\ud83d\\ude27\",\n \"text\": \"\",\n \"mrkdwn_in\": [\"text\", \"pretext\"],\n \"footer\": \"ec2-54-246-210-90.eu-west-1.compute.amazonaws.com\",\n \"footer_icon\": \"https://i.imgur.com/ADsI87O.png\",\n \"ts\": \"1570917914\",\n \"fields\": [\n\t\t \t{\n\t\t \"title\": \"\",\n\t\t \"value\": \"\",\n\t\t \"short\": false\n\t\t \t},\n\t\t \t{\n\t\t \"title\": \"\",\n\t\t \"value\": \"\",\n\t\t \"short\": false\n\t\t \t},\n\t \t\t{\n\t\t \"title\": \"\",\n\t\t \"value\": \" \",\n\t\t \"short\": false\n\t\t \t}\n\t \t]\n }\n ]\n}"""
|
||||
|
||||
jsonPayload = json.loads(payload)
|
||||
|
||||
timeNow = datetime.now().timestamp()
|
||||
|
||||
jsonPayload = json.loads(payload)
|
||||
print(jsonPayload)
|
||||
|
||||
jsonPayload['attachments'][0]['title'] = f'{messageTitle}'
|
||||
print(jsonPayload['attachments'][0]['title'])
|
||||
# print(jsonPayload['attachments'][0]['title'])
|
||||
|
||||
jsonPayload['attachments'][0]['ts'] = timeNow
|
||||
print(jsonPayload['attachments'][0]['ts'])
|
||||
# print(jsonPayload['attachments'][0]['ts'])
|
||||
|
||||
jsonPayload['attachments'][0]['fields'][0]['title'] = f'{congestionTitle}'
|
||||
print(jsonPayload['attachments'][0]['fields'][0]['title'])
|
||||
# print(jsonPayload['attachments'][0]['fields'][0]['title'])
|
||||
|
||||
jsonPayload['attachments'][0]['fields'][0]['value'] = f'{congestionMessage}'
|
||||
print(jsonPayload['attachments'][0]['fields'][0]['value'])
|
||||
# print(jsonPayload['attachments'][0]['fields'][0]['value'])
|
||||
|
||||
jsonPayload['attachments'][0]['fields'][1]['title'] = f'{accidentTitle}'
|
||||
print(jsonPayload['attachments'][0]['fields'][1]['title'])
|
||||
# print(jsonPayload['attachments'][0]['fields'][1]['title'])
|
||||
|
||||
jsonPayload['attachments'][0]['fields'][1]['value'] = f'{accidentMessage}'
|
||||
print(jsonPayload['attachments'][0]['fields'][1]['value'])
|
||||
# print(jsonPayload['attachments'][0]['fields'][1]['value'])
|
||||
|
||||
jsonPayload['attachments'][0]['fields'][2]['value'] = f'{end}'
|
||||
print(jsonPayload['attachments'][0]['fields'][2]['value'])
|
||||
# print(jsonPayload['attachments'][0]['fields'][2]['value'])
|
||||
|
||||
newJsonPayload = json.dumps(jsonPayload)
|
||||
# print(newJsonPayload)
|
||||
|
||||
with open(f'{os.getcwd()}/slackURL.json', 'r') as slackURL:
|
||||
url = json.load(slackURL)
|
||||
|
||||
url = base64.b64decode(url.encode()).decode()
|
||||
|
||||
querystring = {"": ""}
|
||||
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'User-Agent': 'PostmanRuntime/7.17.1',
|
||||
'Accept': '*/*',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Postman-Token': 'a4b63f2d-43b1-4ce7-898a-2fd03952ad7d,46ba7deb-472c-4328'
|
||||
'-a261-9c2000da2f11',
|
||||
'Host': 'hooks.slack.com',
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Content-Length': '1277',
|
||||
'Connection': 'keep-alive',
|
||||
'cache-control': 'no-cache',
|
||||
}
|
||||
|
||||
response = requests.request(
|
||||
'POST',
|
||||
url,
|
||||
data=newJsonPayload.encode(),
|
||||
headers=headers,
|
||||
params=querystring,
|
||||
)
|
||||
|
||||
print(response.text)
|
||||
|
||||
1
slack-bot/traffic-scraper/prd/slackURL.json
Normal file
1
slack-bot/traffic-scraper/prd/slackURL.json
Normal file
@@ -0,0 +1 @@
|
||||
"aHR0cHM6Ly9ob29rcy5zbGFjay5jb20vc2VydmljZXMvVDAyRDExQjRLL0JQQkFGUFA3WC9kTk8xRTBCaVg1WUlHMWgxblZtU0E3c28="
|
||||
@@ -1,30 +1,23 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
import requests
|
||||
|
||||
payload = """{\"attachments\": [\n {\n \"title\": \"{title}",\n \"pretext\": \"Did someone say M62!? \\ud83d\\ude27\",\n \"text\": \"\",\n \"mrkdwn_in\": [\"text\", \"pretext\"],\n \"footer\": \"ec2-54-246-210-90.eu-west-1.compute.amazonaws.com\",\n \"footer_icon\": \"https://i.imgur.com/ADsI87O.png\",\n \"ts\": \"1570917914\",\n \"fields\": [\n\t\t \t{\n\t\t \"title\": \"{congestionTitle}\",\n\t\t \"value\": \"{congestionMessage}\",\n\t\t \"short\": false\n\t\t \t},\n\t\t \t{\n\t\t \"title\": \"{accidentTitle}\",\n\t\t \"value\": \"{accidentMessage}\",\n\t\t \"short\": false\n\t\t \t},\n\t \t\t{\n\t\t \"title\": \"\",\n\t\t \"value\": \"{end} \",\n\t\t \"short\": false\n\t\t \t}\n\t \t]\n }\n ]\n}"""
|
||||
url = "https://hooks.slack.com/services/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"
|
||||
|
||||
timeNow = datetime.now().timestamp()
|
||||
querystring = {"":""}
|
||||
|
||||
jsonPayload = json.loads(payload)
|
||||
print(jsonPayload)
|
||||
payload = "{\"attachments\": [\n {\n \"title\": \"Let's check the latest updates from Highways England as of 22:30:12! \\ud83d\\ude93\\ud83d\\udea8\",\n \"pretext\": \"Did someone say M62!? \\ud83d\\ude27\",\n \"text\": \"\",\n \"mrkdwn_in\": [\"text\", \"pretext\"],\n \"footer\": \"ec2-54-246-210-90.eu-west-1.compute.amazonaws.com\",\n \"footer_icon\": \"https://i.imgur.com/ADsI87O.png\",\n \"ts\": \"1570917914\",\n \"fields\": [\n\t\t \t{\n\t\t \"title\": \"There are currently 1 reported congestion incidents on the M62 😱\",\n\t\t \"value\": \"Location : The M62 westbound exit slip at junction J32 .\\n Reason : Congestion.\\n Status : Currently Active.\\n Return To Normal : Normal traffic conditions are expected between 23:00 and 23:15 on 12 October 2019.\\n Delay : There are currently delays of 10 minutes against expected traffic.\",\n\t\t \"short\": false\n\t\t \t},\n\t\t \t{\n\t\t \"title\": \"Accident Incidents\",\n\t\t \"value\": \"There are currently no reported accident incidents on the M62 \\ud83e\\udd14\",\n\t\t \"short\": false\n\t\t \t},\n\t \t\t{\n\t\t \"title\": \"\",\n\t\t \"value\": \"Hey Andy, have you thought about getting the train? \\ud83d\\ude85 \",\n\t\t \"short\": false\n\t\t \t}\n\t \t]\n }\n ]\n}"
|
||||
headers = {
|
||||
'Content-Type': "application/json",
|
||||
'User-Agent': "PostmanRuntime/7.17.1",
|
||||
'Accept': "*/*",
|
||||
'Cache-Control': "no-cache",
|
||||
'Postman-Token': "a4b63f2d-43b1-4ce7-898a-2fd03952ad7d,46ba7deb-472c-4328-a261-9c2000da2f11",
|
||||
'Host': "hooks.slack.com",
|
||||
'Accept-Encoding': "gzip, deflate",
|
||||
'Content-Length': "1277",
|
||||
'Connection': "keep-alive",
|
||||
'cache-control': "no-cache"
|
||||
}
|
||||
|
||||
jsonPayload['attachments'][0]['title'] = f'{messageTitle}'
|
||||
print(jsonPayload['attachments'][0]['title'])
|
||||
response = requests.request("POST", url, data=payload.encode(), headers=headers, params=querystring)
|
||||
|
||||
jsonPayload['attachments'][0]['ts'] = timeNow
|
||||
print(jsonPayload['attachments'][0]['ts'])
|
||||
|
||||
jsonPayload['attachments'][0]['fields'][0]['title'] = f'{congestionTitle}'
|
||||
print(jsonPayload['attachments'][0]['fields'][0]['title'])
|
||||
|
||||
jsonPayload['attachments'][0]['fields'][0]['value'] = f'{congestionMessage}'
|
||||
print(jsonPayload['attachments'][0]['fields'][0]['value'])
|
||||
|
||||
jsonPayload['attachments'][0]['fields'][1]['title'] = f'{accidentTitle}'
|
||||
print(jsonPayload['attachments'][0]['fields'][1]['title'])
|
||||
|
||||
jsonPayload['attachments'][0]['fields'][1]['value'] = f'{accidentMessage}'
|
||||
print(jsonPayload['attachments'][0]['fields'][1]['value'])
|
||||
|
||||
jsonPayload['attachments'][0]['fields'][2]['value'] = f'{end}'
|
||||
print(jsonPayload['attachments'][0]['fields'][2]['value'])
|
||||
print(response.text)
|
||||
|
||||
Reference in New Issue
Block a user