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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_tiles/update_default_sites_resources.py
diff --git a/components/ntp_tiles/update_default_sites_resources.py b/components/ntp_tiles/update_default_sites_resources.py
new file mode 100755
index 0000000000000000000000000000000000000000..60ae27c9dbe8f3cf2d73adf479a7300b71328f92
--- /dev/null
+++ b/components/ntp_tiles/update_default_sites_resources.py
@@ -0,0 +1,37 @@
+#!/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
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import sys, requests, os, json, urllib, re
+
+kDefaultPopularSites =
+ 'https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json'
+kSiteIconName = 'icon'
+kNtpTilesResourcePath = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)), 'resources')
+kDefaultPopularSitesPath = os.path.join(kNtpTilesResourcePath,
+ 'default_popular_sites.json')
+
+print("Downloading default popular sites... (" + kDefaultPopularSites + ")")
+data = requests.get(url=kDefaultPopularSites).json()
+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.
+
+with open(kDefaultPopularSitesPath, 'w') as f:
+ json.dump(data, f)
+print("JSON was written to " + kDefaultPopularSitesPath)
+
+"""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.
+print("Deleting old icons..")
+for f in os.listdir(kNtpTilesResourcePath):
+ 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
+ os.remove(os.path.join(kNtpTilesResourcePath, f))
+print("... done.")
+
+for i in range(len(data)):
+ print("Downloading icon for \"" + data[i]['title']) +"\"..."
+ 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.
+ 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
+ os.path.join(kNtpTilesResourcePath,
+ kSiteIconName + str(i)))
+ print("... done. (Stored as " + kSiteIconName + str(i) + ")");

Powered by Google App Engine
This is Rietveld 408576698