|
4 | 4 | import urllib.request |
5 | 5 | import time |
6 | 6 | import datetime |
7 | | -"""Make a visual display that contains live information about the next trains |
| 7 | +"""Make a visual display that contains live information about the next trains |
8 | 8 | to depart a given SEPTA Regional Rail station using SEPTA's API. |
9 | 9 | """ |
10 | 10 |
|
@@ -73,15 +73,15 @@ def main(): |
73 | 73 |
|
74 | 74 | # Find the amount of minutes until the train departs |
75 | 75 | for index in range(len(depart_timestamps)): |
76 | | - # Create an int for the late time |
| 76 | + # Create a status message and an integer for the late time |
77 | 77 | late = "0" |
78 | 78 | if (status[index] == "On Time"): |
79 | 79 | pass |
80 | 80 | else: |
81 | 81 | for second_index in range(0, 3): |
82 | 82 | if (status[index][second_index] in ["0", "1", "2", "3", "4", |
83 | 83 | "5", "6", "7", "8", "9"]): |
84 | | - late = late + status[index][second_index] |
| 84 | + late += status[index][second_index] |
85 | 85 | status[index] = status[index] + " late" |
86 | 86 | late = int(late) |
87 | 87 | if (str(next_station[index]) == ""): |
@@ -160,9 +160,8 @@ def get_data_from_api(): |
160 | 160 | url = ("https://www3.septa.org/api/Arrivals/index.php?station=" + station |
161 | 161 | + "&direction=" + direction) |
162 | 162 | url = url.replace(" ", "%20") |
163 | | - site = urllib.request.urlopen(url) |
164 | | - raw_data = site.read() |
165 | | - site.close() |
| 163 | + with urllib.request.urlopen(url) as site: |
| 164 | + raw_data = str(site.read()) |
166 | 165 | return str(raw_data) |
167 | 166 |
|
168 | 167 |
|
@@ -209,12 +208,11 @@ def time_until_next_update(min_until_depart_int): |
209 | 208 | """Get the settings and create the display |
210 | 209 | """ |
211 | 210 | # Get the settings |
212 | | - settings = open("settings.txt", "r") |
213 | | - fullscreen = settings.readline().strip("\n") |
214 | | - maximum_results = int(settings.readline().strip("\n")) |
215 | | - station = settings.readline().strip("\n") |
216 | | - direction = settings.readline().strip("\n") |
217 | | - settings.close() |
| 211 | + with open("settings.txt", "r") as settings: |
| 212 | + fullscreen = settings.readline().strip("\n") |
| 213 | + maximum_results = int(settings.readline().strip("\n")) |
| 214 | + station = settings.readline().strip("\n") |
| 215 | + direction = settings.readline().strip("\n") |
218 | 216 |
|
219 | 217 | # Create the display |
220 | 218 | root = Tk() |
@@ -274,8 +272,13 @@ def time_until_next_update(min_until_depart_int): |
274 | 272 |
|
275 | 273 | # Make copyright disclaimer |
276 | 274 | copyright.append(Label(root)) |
277 | | - copyright[0].config(bg=BG_COLOR, fg=FG_COLOR, font=("Arial", int(root.winfo_screenwidth() / 130)), |
278 | | - text="This is an unofficial real-time information display that uses SEPTA's API. Visit septa.org for more information. The displayed data is Copyright Southeastern Pennsylvania Transportation Authority. All Rights Reserved.") |
| 275 | + copyright[0].config(bg=BG_COLOR, fg=FG_COLOR, |
| 276 | + font=("Arial", int(root.winfo_screenwidth() / 130)), |
| 277 | + text="This is an unofficial real-time information " |
| 278 | + "display that uses SEPTA's API. Visit septa.org for " |
| 279 | + "more information. The displayed data is Copyright " |
| 280 | + "Southeastern Pennsylvania Transportation Authority. " |
| 281 | + "All Rights Reserved.") |
279 | 282 | copyright[0].grid(row=(maximum_results - 1) * |
280 | 283 | 3 + 3, column=0, columnspan=4) |
281 | 284 | root.grid_rowconfigure((maximum_results - 1) * 3 + 3, weight=1) |
|
0 commit comments