ran black and isort for sorting imports and reformating

main
Nikola Sebastian Munder 2026-01-05 12:00:41 +01:00
parent 3098403b65
commit 30e8fbc33e
2 changed files with 23 additions and 19 deletions

View File

@ -1,16 +1,18 @@
import glob import glob
import pandas as pd
import os import os
import pandas as pd
def main(): def main():
path = "./stundenwerte/*.csv" path = "./stundenwerte/*.csv"
files = glob.glob(path) files = glob.glob(path)
dfs = [] dfs = []
print("Working", end="", flush=True) print("Working", end="", flush=True)
for file in files: 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] 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) print(".", end="", flush=True)
max_df = pd.concat(dfs, ignore_index=True) max_df = pd.concat(dfs, ignore_index=True)
@ -18,7 +20,7 @@ def main():
# Mannheim subset # Mannheim subset
df_ma = max_df[max_df["domain_name"] == "Stadt Mannheim"] df_ma = max_df[max_df["domain_name"] == "Stadt Mannheim"]
df_ma.to_csv("../data/processed/hourly_bikes_mannheim.csv", index=False) df_ma.to_csv("../data/processed/hourly_bikes_mannheim.csv", index=False)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -1,29 +1,31 @@
# script to get hourly counters from 2014-present # script to get hourly counters from 2014-present
import requests
import gzip
import shutil
import os
import glob import glob
import gzip
import os
import shutil
import pandas as pd import pandas as pd
import requests
def main(): def main():
for year in range(2014,2026): for year in range(2014, 2026):
for month in range(1,13): for month in range(1, 13):
month = str(month) if len(str(month))==2 else f"0{month}" month = str(month) if len(str(month)) == 2 else f"0{month}"
year_month = f"{year}{month}" year_month = f"{year}{month}"
url = f"https://mobidata-bw.de/daten/eco-counter/v2/fahrradzaehler_stundenwerten_{year_month}.csv.gz" 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] filename = url.split("/")[-1]
with open(f"hourly_archives/{filename}", "wb") as f: with open(f"hourly_archives/{filename}", "wb") as f:
r = requests.get(url) r = requests.get(url)
f.write(r.content) f.write(r.content)
os.makedirs("stundenwerte", exist_ok=True) os.makedirs("stundenwerte", exist_ok=True)
with gzip.open(f"hourly_archives/{filename}", 'rb') as f_in: with gzip.open(f"hourly_archives/{filename}", "rb") as f_in:
f_name = "stundenwerte/"+filename.split(".")[0] f_name = "stundenwerte/" + filename.split(".")[0]
with open(f"{f_name}.csv", 'wb') as f_out: with open(f"{f_name}.csv", "wb") as f_out:
shutil.copyfileobj(f_in, f_out) shutil.copyfileobj(f_in, f_out)
if __name__ == "__main__": if __name__ == "__main__":
main() main()