Skip to content

Commit 4553e11

Browse files
1Maxnet1jbruechert
andauthored
Initial GBFS attribution (#2284)
* Initial creation of GBFS attribution Currently the license URLs and attribution text are lacking probably for all feeds, but this at least lists the feeds on the attribution page. * Hide Original File Buttons for GBFS Here we do not have an Original or Processed File * Fix using wrong method Co-authored-by: Jonah Brüchert <jbb@kaidan.im> --------- Co-authored-by: Jonah Brüchert <jbb@kaidan.im>
1 parent b0e9672 commit 4553e11

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

src/generate-attribution.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,42 @@ def add_rt_attribution(attribution: dict, source: UrlSource) -> None:
169169

170170
attribution["rt"].append(rt_attribution)
171171

172+
def gbfs_source_attribution(source: UrlSource, source_id: str, region_data: dict):
173+
attribution = region_data
174+
175+
if source.license.spdx_identifier:
176+
attribution["spdx_license_identifier"] = \
177+
source.license.spdx_identifier
178+
if source.license.url:
179+
attribution["license_url"] = source.license.url
180+
if source.license.attribution_text:
181+
attribution["attribution_text"] = source.license.attribution_text
182+
183+
attribution["operators"] = []
184+
attribution["source"] = source.url
185+
186+
human_name: str = (
187+
source_id.split("_")[1].replace("-", " ")
188+
)
189+
human_name = " ".join(
190+
map(lambda w: w[0].upper() + w[1:] if len(w) > 0 else w, human_name.split(" "))
191+
)
192+
attribution["human_name"] = human_name
193+
194+
if source.license.publisher:
195+
attribution["publisher"] = {}
196+
attribution["publisher"]["name"] = source.license.publisher
197+
attribution["publisher"]["url"] = source.license.publisher_url
198+
199+
if (
200+
"operators" in attribution
201+
and len(attribution["operators"]) == 1
202+
and len(attribution["operators"][0]) > 1
203+
):
204+
attribution["human_name"] = attribution["operators"][0]
205+
206+
return attribution
207+
172208

173209
def get_region_data(code: str) -> dict:
174210
code = code.upper()
@@ -234,12 +270,19 @@ def attribute_sort_key(attr):
234270

235271
for source in resolved_sources:
236272
match source:
237-
case UrlSource() if source.spec == "gtfs-rt":
238-
if source_id not in attributions:
239-
print(f"Warning: Stray gtfs-rt source for {source_id} without a (locally available) static timetable")
240-
continue
241-
else:
242-
add_rt_attribution(attributions[source_id], source)
273+
case UrlSource():
274+
if source.spec == "gtfs-rt":
275+
if source_id not in attributions:
276+
print(f"Warning: Stray gtfs-rt source for {source_id} without a (locally available) static timetable")
277+
continue
278+
else:
279+
add_rt_attribution(attributions[source_id], source)
280+
elif source.spec == "gbfs":
281+
gbfs_attribution = gbfs_source_attribution(source, source_id, region_data.copy())
282+
if not gbfs_attribution:
283+
continue
284+
if source_id not in attributions:
285+
attributions[source_id] = gbfs_attribution
243286
case HttpSource():
244287
http_attribution = http_source_attribution(source, source_id, region_data.copy())
245288
if not http_attribution:

website/layouts/shortcodes/source-table.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ <h4>{{ .human_name }}</h4>
110110
</p>
111111
{{ end }}
112112

113+
{{ if $source.filename }}
113114
<a class="btn btn-outline-secondary" href="{{ $source.source }}">Original File</a>
114115
<a class="btn btn-outline-secondary" href="https://api.transitous.org/gtfs/{{ $source.filename }}">Processed File</a>
116+
{{ end }}
115117

116118
{{ if or $source.rt }}
117119
{{ range $rt_source := $source.rt }}

0 commit comments

Comments
 (0)