ran black and isort for sorting imports and reformating
parent
3098403b65
commit
30e8fbc33e
|
|
@ -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()
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
main()
|
||||
|
|
|
|||
Loading…
Reference in New Issue