diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-02-05 18:21:06 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-02-05 18:21:06 +0100 |
commit | 943d0fde0b46b8da93e10d6c65e03b3052eb3130 (patch) | |
tree | 7a64a0a1845fa5b33be67835102d11c471de6d67 | |
parent | 945385ddfbdfe791f2f02f3fe3d0b0a3f81d4bb8 (diff) |
only write debug api output if `debug` file is present
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | autoplanner.py | 4 | ||||
-rw-r--r-- | shared.py | 7 | ||||
-rwxr-xr-x | storingen.py | 4 |
4 files changed, 10 insertions, 6 deletions
@@ -3,3 +3,4 @@ autoplanner.json venv/ __pycache__/ *-api-response.json +debug diff --git a/autoplanner.py b/autoplanner.py index fe3e728..6af5c6d 100755 --- a/autoplanner.py +++ b/autoplanner.py @@ -52,9 +52,7 @@ def get_trip(date): response = conn.getresponse() data = response.read() conn.close() - f = open("./autoplanner-api-response.json", "w+") - f.write(str(data, "utf-8")) - f.close() + debug_output("autoplanner", data) return data def leg2desc(leg): @@ -1,6 +1,7 @@ #!/bin/python3 import urllib.request import re +import os from uuid import uuid4 from bs4 import BeautifulSoup @@ -15,3 +16,9 @@ def read_file(filename): r = str(f.read()) f.close() return r + +def debug_output(name, data): + if not os.path.exists("./debug"): return + f = open(f"./{name}-api-response.json", "w+") + f.write(str(data, "utf-8")) + f.close() diff --git a/storingen.py b/storingen.py index 5eb9af7..2a93936 100755 --- a/storingen.py +++ b/storingen.py @@ -19,9 +19,7 @@ def get_disruptions(): response = conn.getresponse() data = response.read() conn.close() - f = open("./storingen-api-response.json", "w+") - f.write(str(data, "utf-8")) - f.close() + debug_output("storingen", data) return data def disruption2ical(disruption): |