From 30e8fbc33e69a184e10c1e13f931984b2eefbd1b Mon Sep 17 00:00:00 2001 From: Niki Laptop <2212719@stud.hs-mannheim.de> Date: Mon, 5 Jan 2026 12:00:41 +0100 Subject: [PATCH] ran black and isort for sorting imports and reformating --- data/combine_hourly.py | 14 ++++++++------ data/hourly.py | 28 +++++++++++++++------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/data/combine_hourly.py b/data/combine_hourly.py index f21c769..0d57d5c 100644 --- a/data/combine_hourly.py +++ b/data/combine_hourly.py @@ -1,16 +1,18 @@ import glob -import pandas as pd import os +import pandas as pd + + def main(): - path = "./stundenwerte/*.csv" + path = "./stundenwerte/*.csv" files = glob.glob(path) dfs = [] print("Working", end="", flush=True) for file in files: - df_temp= pd.read_csv(file,low_memory=False) + df_temp = pd.read_csv(file, low_memory=False) df_temp["year"] = os.path.basename(file).split("_")[2].split(".")[0] - dfs.append(df_temp.astype({"year":int})) + dfs.append(df_temp.astype({"year": int})) print(".", end="", flush=True) max_df = pd.concat(dfs, ignore_index=True) @@ -18,7 +20,7 @@ def main(): # Mannheim subset df_ma = max_df[max_df["domain_name"] == "Stadt Mannheim"] df_ma.to_csv("../data/processed/hourly_bikes_mannheim.csv", index=False) - + if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/data/hourly.py b/data/hourly.py index ba2f75a..c78f6bc 100755 --- a/data/hourly.py +++ b/data/hourly.py @@ -1,29 +1,31 @@ # script to get hourly counters from 2014-present -import requests -import gzip -import shutil -import os import glob +import gzip +import os +import shutil + import pandas as pd +import requests + def main(): - for year in range(2014,2026): - for month in range(1,13): - month = str(month) if len(str(month))==2 else f"0{month}" + for year in range(2014, 2026): + for month in range(1, 13): + month = str(month) if len(str(month)) == 2 else f"0{month}" year_month = f"{year}{month}" url = f"https://mobidata-bw.de/daten/eco-counter/v2/fahrradzaehler_stundenwerten_{year_month}.csv.gz" - - os.makedirs("hourly_archives",exist_ok=True) + + os.makedirs("hourly_archives", exist_ok=True) filename = url.split("/")[-1] with open(f"hourly_archives/{filename}", "wb") as f: r = requests.get(url) f.write(r.content) os.makedirs("stundenwerte", exist_ok=True) - with gzip.open(f"hourly_archives/{filename}", 'rb') as f_in: - f_name = "stundenwerte/"+filename.split(".")[0] - with open(f"{f_name}.csv", 'wb') as f_out: + with gzip.open(f"hourly_archives/{filename}", "rb") as f_in: + f_name = "stundenwerte/" + filename.split(".")[0] + with open(f"{f_name}.csv", "wb") as f_out: shutil.copyfileobj(f_in, f_out) if __name__ == "__main__": - main() \ No newline at end of file + main()