in make_manifest.py [0:0]
def make_manifest(count, minwidth, topsitesfile, extrafile, saverawsitedata, loadrawsitedata):
results = []
if loadrawsitedata:
logging.info(f'Loading raw icon data from {loadrawsitedata}')
with open(loadrawsitedata) as infile:
sites_with_icons = json.loads(infile.read())
else:
sites_with_icons = collect_icons_for_top_sites(topsitesfile, extrafile, count)
if saverawsitedata:
logging.info(f'Saving raw icon data to {saverawsitedata}')
with open(saverawsitedata, 'w') as outfile:
json.dump(sites_with_icons, outfile, indent=4)
for site in sites_with_icons:
hostname = site.get('hostname')
url = site.get('url')
icon = site.get('best_icon_url')
icon_width = site.get('best_icon_width')
# check if there is a best icon that satisfies the minwidth criteria
if (icon is None) or ((icon_width != SVG_ICON_WIDTH) and (icon_width < minwidth)):
logging.info(f'No icon for "{url}" (best icon width: {icon_width})')
continue
existing = next((x for x in results if x.get('image_url') == icon), None)
if existing:
existing.get('domains').append(hostname)
else:
results.append({
'image_url': icon,
'domains': [hostname]
})
# Sort alphabetically
results = sorted(results, key=lambda site: site['domains'][0])
click.echo(json.dumps(results, indent=4))