-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bahnabfrage.py
153 lines (144 loc) · 6.42 KB
/
Bahnabfrage.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#dsfsf
import requests
import telebot
import datetime
import json
from datetime import datetime as DateTime
hour = datetime.datetime.now().hour
TOKEN='680737840:AAEaa7Vxl_kZz_LWS1_S-lH6Eda7HXqu6Y4'
ChatID='322673713'
tb = telebot.TeleBot(TOKEN)
ort = '/home/carsten/Scripts/'
ort = ''
Zeitstempel = DateTime.now().strftime('%Y_%m_%d_%H_%M_%S')
antwort=''
def mzwi():
url_zitat = 'https://dbf.finalrewind.org/mainzhbf.json?version=3'
resp_zitat = requests.get(url_zitat)
data_zitat = resp_zitat.json()
telegramm = 'Mainz - Wiesbaden\n'
with open(ort + str(Zeitstempel) + '_data.txt', 'w') as outfile:
json.dump(data_zitat, outfile)
for i in data_zitat['departures']:
if i['train'] == "S 8":
if i['destination'] == 'Wiesbaden Hbf':
antwort = (i['train'] + ' ' + i['platform'] + ' ' + str(i['scheduledDeparture']))
if i['isCancelled'] != 1:
if i['delayDeparture'] != 0:
antwort = antwort + (' Verspätung: ' + str(i['delayDeparture']) + ' Minuten')
else:
antwort = antwort + ' PÜNKTLICH'
else:
antwort = antwort + 'CANCELLED!!!'
telegramm = telegramm + antwort + '\n'
if i['train'] == "RB 75":
if i['isCancelled'] != 1:
if i['delayDeparture'] != 0:
antwort = antwort + (' Verspätung: ' + str(i['delayDeparture']) + ' Minuten')
else:
antwort = antwort + ' PÜNKTLICH'
else:
antwort = antwort + 'CANCELLED!!!'
telegramm = telegramm + antwort + '\n'
return telegramm
def wimz():
url_zitat = 'https://dbf.finalrewind.org/Wiesbadenhbf.json?version=3'
resp_zitat = requests.get(url_zitat)
data_zitat = resp_zitat.json()
telegramm = 'Wiesbaden - Mainz\n'
with open(ort + str(Zeitstempel) + '_data.txt', 'w') as outfile:
json.dump(data_zitat, outfile)
for i in data_zitat['departures']:
if i['train'] == "S 8":
if i['destination'] == 'Offenbach(Main)Ost':
antwort = (i['train'] + ' ' + i['platform'] + ' ' + str(i['scheduledDeparture']))
if i['isCancelled'] != 1:
if i['delayDeparture'] != 0:
antwort = antwort + (' Verspätung: ' + str(i['delayDeparture']) + ' Minuten')
else:
antwort = antwort + ' PÜNKTLICH'
else:
antwort = antwort + 'CANCELLED!!!'
telegramm = telegramm + antwort + '\n'
if i['train'] == "RB 75":
if i['destination'] == 'Aschaffenburg Hbf':
antwort = (i['train'] + ' ' + i['platform'] + ' ' + str(i['scheduledDeparture']))
if i['isCancelled'] != 1:
if i['delayDeparture'] != 0:
antwort = antwort + (' Verspätung: ' + str(i['delayDeparture']) + ' Minuten')
else:
antwort = antwort + ' PÜNKTLICH'
else:
antwort = antwort + 'CANCELLED!!!'
telegramm = telegramm + antwort + '\n'
return telegramm
def mzaz():
url_zitat = 'https://dbf.finalrewind.org/mainzhbf.json?version=3'
resp_zitat = requests.get(url_zitat)
data_zitat = resp_zitat.json()
telegramm = 'Mainz - Alzey\n'
with open(ort + str(Zeitstempel) + '_data.txt', 'w') as outfile:
json.dump(data_zitat, outfile)
for i in data_zitat['departures']:
if i['train'] == "RE 13":
if i['delayDeparture'] != None:
antwort = (i['train'] + ' ' + i['platform'] + ' ' + str(i['scheduledDeparture']))
if i['isCancelled'] != 1:
if i['delayDeparture'] != 0:
antwort = antwort + (' Verspätung: ' + str(i['delayDeparture']) + ' Minuten')
else:
antwort = antwort + ' PÜNKTLICH'
else:
antwort = antwort + 'CANCELLED!!!'
telegramm = telegramm + antwort + '\n'
if i['train'] == "RB 31":
if i['delayDeparture'] != None:
antwort = (i['train'] + ' ' + i['platform'] + ' ' + str(i['scheduledDeparture']))
if i['isCancelled'] != 1:
if i['delayDeparture'] != 0:
antwort = antwort + (' Verspätung: ' + str(i['delayDeparture']) + ' Minuten')
else:
antwort = antwort + ' PÜNKTLICH'
else:
antwort = antwort + 'CANCELLED!!!'
telegramm = telegramm + antwort + '\n'
return telegramm
def azmz():
url_zitat = 'https://dbf.finalrewind.org/alzeyhbf.json?version=3'
resp_zitat = requests.get(url_zitat)
data_zitat = resp_zitat.json()
telegramm = 'Alzey - Mainz\n'
with open(ort + str(Zeitstempel) + '_data.txt', 'w') as outfile:
json.dump(data_zitat, outfile)
for i in data_zitat['departures']:
# print(i)
if i['train'] == "RE 13":
# print(i)
if i['destination'] == 'Mainz Hbf':
antwort = (i['train'] + ' ' + i['platform'] + ' ' + str(i['scheduledDeparture']))
if i['isCancelled'] != 1:
if i['delayDeparture'] != 0:
antwort = antwort + (' Verspätung: ' + str(i['delayDeparture']) + ' Minuten')
else:
antwort = antwort + ' PÜNKTLICH'
else:
antwort = antwort + 'CANCELLED!!!'
telegramm = telegramm + antwort + '\n'
if i['train'] == "RB 31":
if i['destination'] == 'Mainz Hbf':
antwort = (i['train'] + ' ' + i['platform'] + ' ' + str(i['scheduledDeparture']))
if i['isCancelled'] != 1:
if i['delayDeparture'] != 0:
antwort = antwort + (' Verspätung: ' + str(i['delayDeparture']) + ' Minuten')
else:
antwort = antwort + ' PÜNKTLICH'
else:
antwort = antwort + 'CANCELLED!!!'
telegramm = telegramm + antwort + '\n'
return telegramm
if hour <=12:
sendto=(azmz())+'\n'+mzwi()
tb.send_message(ChatID, sendto)
if hour >=13:
sendto = (wimz()) + '\n' + mzaz()
tb.send_message(ChatID, sendto)