Skip to content

Commit

Permalink
cmteb column order
Browse files Browse the repository at this point in the history
  • Loading branch information
pax committed Sep 10, 2023
1 parent 0b5b6b8 commit 682667b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15,360 deletions.
29 changes: 12 additions & 17 deletions cmteb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import json, re
# from bs4 import BeautifulSoup
import pandas as pd
from utils.common import fetch_data, order_bylatlong, save_json_to_file, data_root
from utils.common import fetch_data, order_bylatlong, order_by_denumire, save_json_to_file, data_root

ziurl = 'https://www.cmteb.ro/harta_stare_sistem_termoficare_bucuresti.php'
data_folder = data_root +'cmteb/'
Expand All @@ -43,34 +43,29 @@ def extract_json_from_html(html_content):
nicedata = json.loads(data_str)
for dx in nicedata:
dx['status'] = legend[color]
dx['Lat'] = dx['latitudine']
dx['Long'] = dx['longitudine']
del dx['latitudine']
del dx['longitudine']
# strip spaces from strings
for key, val in dx.items():
if type(val) is str:
dx[key] = val.strip()

# else:
# TODO: log errors
# print(f"Data for '{color}' not found in the HTML.")

stats[legend[color]] = len(nicedata)
alldata += nicedata

sorted_data = sorted(alldata, key=order_bylatlong)

# sorted_data = sorted(alldata, key=order_by_denumire)

print(stats)


return sorted_data

if __name__ == "__main__":
zidata = extract_json_from_html(fetch_data(ziurl))

ll = save_json_to_file(zidata, data_folder+outputFileRoot+'.json', 'pretty_ensure_ascii_false' )

if ll:
print('saved ' + str(len(zidata)) + ' records to ' + data_folder + outputFileRoot )
# save csvs
df = pd.read_json(json.dumps(zidata))
df.to_csv(data_folder + outputFileRoot + '.csv', encoding='utf-8', index=False)
else:
print('no changes in ' + outputFileRoot)
save_json_to_file(zidata, data_folder+outputFileRoot+'.json', 'pretty_ensure_ascii_false' )
df = pd.read_json(json.dumps(zidata))
df.to_csv(data_folder + outputFileRoot + '.csv', encoding='utf-8', index=False, columns = ['denumire','status','stare','tip','remediere','culoare','Lat','Long'])
print('saved ' + str(len(zidata)) + ' records to ' + data_folder + outputFileRoot + ' .csv/json' )

5,661 changes: 0 additions & 5,661 deletions data/cmteb/report.html

This file was deleted.

961 changes: 0 additions & 961 deletions data/cmteb/status-sistem-termoficare-bucuresti.csv

This file was deleted.

Loading

0 comments on commit 682667b

Please sign in to comment.