Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: components/ntp_tiles/update_default_sites_resources.py

Issue 2695713004: Add baked-in favicons for default popular sites on NTP (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
sfiera 2017/02/13 18:36:35 Is this file written according to http://google.gi
fhorschig 2017/02/14 17:29:02 Thanks for the link! It was not (minimal linting/p
2 # Copyright 2017 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import sys, requests, os, json, urllib, re
7
8 kDefaultPopularSites =
9 'https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json'
10 kSiteIconName = 'icon'
11 kNtpTilesResourcePath = os.path.join(
12 os.path.dirname(os.path.realpath(__file__)), 'resources')
13 kDefaultPopularSitesPath = os.path.join(kNtpTilesResourcePath,
14 'default_popular_sites.json')
15
16 print("Downloading default popular sites... (" + kDefaultPopularSites + ")")
17 data = requests.get(url=kDefaultPopularSites).json()
18 print("... done. (" + str(len(data)) + " sites found)")
sfiera 2017/02/13 18:36:35 print("... done. (%d sites found)" % len(data))
fhorschig 2017/02/15 18:14:34 Done.
19
20 with open(kDefaultPopularSitesPath, 'w') as f:
21 json.dump(data, f)
22 print("JSON was written to " + kDefaultPopularSitesPath)
23
24 """Deleting old icons explicitly avoids wrong icons for pages without such."""
sfiera 2017/02/13 18:36:35 Regular comments are #. Only docstrings have """
fhorschig 2017/02/15 18:14:34 Done.
25 print("Deleting old icons..")
26 for f in os.listdir(kNtpTilesResourcePath):
27 if re.search(kSiteIconName + "*", f):
sfiera 2017/02/13 18:36:35 I think you are looking for https://docs.python.or
fhorschig 2017/02/15 18:14:35 nice! (Yes, it was intentional but not entirely co
28 os.remove(os.path.join(kNtpTilesResourcePath, f))
29 print("... done.")
30
31 for i in range(len(data)):
32 print("Downloading icon for \"" + data[i]['title']) +"\"..."
33 print("(Source: " + data[i]['large_icon_url']) +")"
sfiera 2017/02/13 18:36:35 Not all sites have large_icon_url. It's probably s
fhorschig 2017/02/15 18:14:34 Done.
34 urllib.urlretrieve(data[i]['large_icon_url'],
sfiera 2017/02/13 18:36:35 Why are you using requests above and urllib here?
fhorschig 2017/02/14 17:29:02 Requests is an easy way to get the response as JSO
fhorschig 2017/02/15 18:14:34 I used urllib everywhere. requests ran into some p
35 os.path.join(kNtpTilesResourcePath,
36 kSiteIconName + str(i)))
37 print("... done. (Stored as " + kSiteIconName + str(i) + ")");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698