-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Transport for EMF HAFAS #15
base: main
Are you sure you want to change the base?
Changes from 5 commits
bf71ead
fc8cb2c
f04f8bc
496c169
dc47f7d
c7937d1
21ea268
d85830b
fa9ca94
e732b11
204d726
df66259
b7fdd27
8d5dee8
963b6a8
02b98d8
35c0ef7
c074747
928e6e0
b7d1ba8
03daf91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,3 @@ config.json | |
*.pyc | ||
.venv | ||
*.swp | ||
#*.ttf | ||
*.TTF |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noticed we're missing licensing information for the newly added fonts and the NRE logo. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import json | ||
import pytz | ||
from itertools import islice | ||
|
||
from requests import get | ||
|
||
from hafas_event import HAFASEvent | ||
from helper import Helper, log | ||
from hosted import CONFIG | ||
from mapping import API_MAPPING | ||
from mapping import API_MAPPING, SYMBOL_IS_GROUP | ||
|
||
|
||
class HAFASFetcher: | ||
def __init__(self): | ||
self.data_sources = CONFIG["data_sources"] | ||
self.tz = pytz.timezone(CONFIG["timezone"]) | ||
self.departures = [] | ||
self.arrivals = [] | ||
self.events = [] | ||
|
@@ -25,12 +27,17 @@ def fetch_and_parse(self, stop_id): | |
departures = sorted(departures) | ||
for n, dep in enumerate(departures): | ||
for follow in islice(departures, n + 1, None): | ||
if dep.symbol == follow.symbol and ( | ||
(dep.platform != "" and dep.platform == follow.platform) | ||
or dep.destination == follow.destination | ||
): | ||
dep.follow = follow | ||
break | ||
if SYMBOL_IS_GROUP[CONFIG["api_provider"]]: | ||
if dep.symbol == follow.symbol and ( | ||
(dep.platform != "" and dep.platform == follow.platform) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation seems wrong here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what clicking "reformat code" in PyCharm outputs |
||
or dep.destination == follow.destination | ||
): | ||
dep.follow = follow | ||
break | ||
else: | ||
if dep.category == follow.category and dep.destination == follow.destination and dep.id != follow.id: | ||
dep.follow = follow | ||
break | ||
self.departures.extend(departures) | ||
|
||
arrivals = [] | ||
|
@@ -86,6 +93,7 @@ def _fetch(self, stop_id): | |
stop=stop_id, | ||
minutes=CONFIG["request_hours"] * 60, | ||
key=key, | ||
language=CONFIG["language"], | ||
) | ||
|
||
if not self.data_sources == "arrivals": | ||
|
@@ -154,17 +162,18 @@ def write_json(self): | |
"icon": dep.category_icon, | ||
"id": dep.id, | ||
"next_time": ( | ||
dep.follow.realtime.strftime("%H:%M") if dep.follow else "" | ||
dep.follow.realtime.astimezone(self.tz).strftime("%H:%M") if dep.follow else "" | ||
TheEnbyperor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
"next_timestamp": ( | ||
Helper.to_unixtimestamp(dep.follow.realtime) if dep.follow else 0 | ||
), | ||
"notes": dep.notes, | ||
"operator": dep.operator, | ||
"operator_name": dep.operatorName, | ||
"platform": dep.platform, | ||
"stop": dep.stop, | ||
"symbol": dep.symbol, | ||
"time": dep.realtime.strftime("%H:%M"), | ||
"time": dep.realtime.astimezone(self.tz).strftime("%H:%M"), | ||
"timestamp": Helper.to_unixtimestamp(dep.realtime), | ||
} | ||
departure.update(dep.line_colour) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from helper import Helper | ||
|
||
MAPPING_TFEMF = { | ||
"AW": (Helper.int2rgb(255, 1, 0), (1, 1, 1)), # Transport for Wales | ||
"CC": (Helper.int2rgb(188, 0, 135), (1, 1, 1)), # c2c | ||
"CH": (Helper.int2rgb(13, 155, 213), Helper.int2rgb(28, 45, 71)), # Chiltern Railways | ||
"CS": (Helper.int2rgb(0, 57, 65), (1, 1, 1)), # Caledonian Sleeper | ||
"EM": (Helper.int2rgb(43, 12, 35), (1, 1, 1)), # East Midlands Railway | ||
"ES": (Helper.int2rgb(0, 40, 106), (1, 1, 1)), # Eurostar | ||
"GC": (Helper.int2rgb(51, 49, 50), (1, 1, 1)), # Grand Central | ||
"GN": (Helper.int2rgb(67, 22, 92), (1, 1, 1)), # Great Northern | ||
"GR": (Helper.int2rgb(206, 14, 45), (1, 1, 1)), # London North Eastern Railway | ||
"GW": (Helper.int2rgb(10, 73, 62), (1, 1, 1)), # Great Western Railway | ||
"GX": (Helper.int2rgb(200, 40, 40), (1, 1, 1)), # Gatwick Express | ||
"HC": (Helper.int2rgb(0, 0, 0), (1, 1, 1)), # Heathrow Connect | ||
"HT": (Helper.int2rgb(0, 0, 51), (1, 1, 1)), # Hull Trains | ||
"HX": (Helper.int2rgb(93, 34, 108), (1, 1, 1)), # Heathrow Express | ||
"IL": (Helper.int2rgb(0, 146, 203), (1, 1, 1)), # Island Line | ||
"LD": (Helper.int2rgb(29, 0, 250), (1, 1, 1)), # Lumo | ||
"LE": (Helper.int2rgb(218, 26, 53), (1, 1, 1)), # Greater Anglia | ||
"LM": (Helper.int2rgb(255, 130, 0), (1, 1, 1)), # West Midlands Trains | ||
"LO": (Helper.int2rgb(2380, 118, 35), (1, 1, 1)), # London Overground | ||
"LT": (Helper.int2rgb(225, 37, 31), (1, 1, 1)), # London Underground | ||
"ME": (Helper.int2rgb(255, 235, 55), (0, 0, 0)), # Merseyrail | ||
"NT": (Helper.int2rgb(38, 34, 98), (1, 1, 1)), # Northern Trains | ||
"NY": (Helper.int2rgb(0, 0, 0), (1, 1, 1)), # North Yorkshire Moors Railway | ||
"PC": (Helper.int2rgb(0, 0, 0), (1, 1, 1)), # Private Charter | ||
"RT": (Helper.int2rgb(0, 0, 0), (1, 1, 1)), # Network Rail | ||
"SE": (Helper.int2rgb(50, 190, 240), Helper.int2rgb(30, 30, 80)), # Southeastern | ||
"SJ": (Helper.int2rgb(0, 155, 119), (1, 1, 1)), # Sheffield Supertram | ||
"SN": (Helper.int2rgb(0, 63, 46), (1, 1, 1)), # Southern | ||
"SP": (Helper.int2rgb(0, 0, 0), (1, 1, 1)), # Swanage | ||
"SR": (Helper.int2rgb(0, 38, 100), (1, 1, 1)), # ScotRail | ||
"SW": (Helper.int2rgb(0, 146, 203), (1, 1, 1)), # South Western Railway | ||
"TL": (Helper.int2rgb(226, 17, 133), (1, 1, 1)), # Thameslink | ||
"TP": (Helper.int2rgb(32, 35, 78), (1, 1, 1)), # TransPennine Express | ||
"TW": (Helper.int2rgb(255, 201, 73), (0, 0, 0)), # Tyne and Wear Metro | ||
"VT": (Helper.int2rgb(19, 30, 41), (1, 1, 1)), # Avanti West Coast | ||
"WR": (Helper.int2rgb(0, 0, 0), (1, 1, 1)), # West Coast Railway Company | ||
"XC": (Helper.int2rgb(202, 18, 63), (1, 1, 1)), # CrossCountry | ||
"XR": (Helper.int2rgb(119, 61, 189), (1, 1, 1)), # Elizabeth Line | ||
"ZB": (Helper.int2rgb(0, 0, 0), (1, 1, 1)), # Bus Operator | ||
"ZF": (Helper.int2rgb(0, 0, 0), (1, 1, 1)), # Ferry Operator | ||
"ZM": (Helper.int2rgb(0, 0, 0), (1, 1, 1)), # West Somerset Railway | ||
"ZZ": (Helper.int2rgb(0, 0, 0), (1, 1, 1)), # Unknown | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add
.idea
to your global gitignore? We should not have editor configs in this repository.