Skip to content

Commit

Permalink
Improve handling of realtime debug_output as json in servicecall
Browse files Browse the repository at this point in the history
  • Loading branch information
vingerha committed May 5, 2024
1 parent 3253ee1 commit a6433ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
24 changes: 16 additions & 8 deletions custom_components/gtfs2/gtfs_rt_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,22 @@ def get_gtfs_rt(hass, path, data):
_LOGGER.error("Ìssues with downloading GTFS RT data to: %s", os.path.join(gtfs_dir, file))
return "no_rt_data_file"
if data.get("debug_output", False):
data_out = ""
feed_entities = get_gtfs_feed_entities(
url=data.get("url", None),
headers=_headers,
label="converting",
)
file_all = data["file"] + "_converted.txt"
open(os.path.join(gtfs_dir, file_all), "w").write(json.dumps(feed_entities, indent=4))
try:
data_out = ""
feed_entities = get_gtfs_feed_entities(
url=data.get("url", None),
headers=_headers,
label=data.get("rt_type", "-"),
)
file_all = data["file"] + "_converted.txt"
except Exception as ex: # pylint: disable=broad-except
_LOGGER.info("Ìssues with converting GTFS RT data to JSON, output to string")
# check if content is json else write without format
try:
open(os.path.join(gtfs_dir, file_all), "w").write(json.dumps(feed_entities, indent=4))
except Exception as ex:
_LOGGER.debug("Not writing to file as json because of error: %s", ex)
open(os.path.join(gtfs_dir, file_all), "w").write(str(feed_entities))
return "ok"

class LocalFileAdapter(requests.adapters.HTTPAdapter):
Expand Down
13 changes: 13 additions & 0 deletions custom_components/gtfs2/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ update_gtfs_rt_local:
required: true
selector:
boolean:

rt_type:
name: Indicate type of realtime data
description: Select if you update from url or zip
required: true
default: "trip_data"
selector:
select:
translation_key: "extract_from"
options:
- "trip_data"
- "vehicle_positions"
- "alerts"

debug_output:
name: Save all to local file in readable format
Expand Down

0 comments on commit a6433ef

Please sign in to comment.