Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod committed Feb 1, 2024
1 parent 6c33f6a commit ebf900e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
7 changes: 4 additions & 3 deletions whotracksme/website/build/companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def company_page(template, company_data, data):
company_id = company_data['overview']['id']

company_name = get_company_name(company_data)
write_json(f'_site/{data.url_for("company", company_id)}',
write_json(f'_site/api/v2/organizations/{data.url_for("company", company_id)}.json',
demographics=company_data,
initials=company_name[:2]
)
Expand All @@ -122,8 +122,9 @@ def build_company_reach_chart_page(data):
top100 = company_reach(data.companies, n=100)
chart = Markup(overview_bars(top100, highlight=10, height=3000))
template = get_template(data, name='reach-chart-page.html', path_to_root='..')
write_json('_site/api/v2/companies.json',
top100=top100
write_json('_site/api/v2/organizations.json',
top100=top100,
organizations=data.companies
)
with open('_site/companies/reach-chart.html', 'w') as output:
output.write(render_template(
Expand Down
17 changes: 8 additions & 9 deletions whotracksme/website/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import pathlib
import os

def myconverter(o):
if isinstance(o, datetime.datetime):
return o.isoformat()
def write_json(path, **data):
def myconverter(o):
if isinstance(o, datetime.datetime):
return o.isoformat()

def write_json(aPath, **aDict):
pathlib.Path(os.path.dirname(aPath)).mkdir(parents=True, exist_ok=True)
jsonString = simplejson.dumps(aDict, indent=2, default = myconverter)
jsonFile = open(aPath, "w")
jsonFile.write(jsonString)
jsonFile.close()
pathlib.Path(os.path.dirname(path)).mkdir(parents=True, exist_ok=True)
json = simplejson.dumps(data, indent=2, default = myconverter)
with open(path, "w") as file:
file.write(json)

def without_keys(d, keys):
return {k: d[k] for k in d.keys() - keys}
Expand Down

0 comments on commit ebf900e

Please sign in to comment.