Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/crawler/bin/extract_crawler_sites.py

Issue 8327353: Crawler backend (Closed)
Patch Set: README fix Created Sept. 14, 2012, 2:42 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sitescripts/crawler/bin/extract_crawler_sites.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/sitescripts/crawler/bin/extract_crawler_sites.py
@@ -0,0 +1,39 @@
+# coding: utf-8
+
+# This Source Code is subject to the terms of the Mozilla Public License
+# version 2.0 (the "License"). You can obtain a copy of the License at
+# http://mozilla.org/MPL/2.0/.
+
+import os, re, subprocess
+from sitescripts.utils import get_config
+
+def hg(args):
+ return subprocess.Popen(["hg"] + args, stdout = subprocess.PIPE)
+
+def extract_urls(filter_list_dir):
+ os.chdir(filter_list_dir)
+ process = hg(["log", "--template", "{desc}\n"])
+ urls = set([])
+
+ while True:
+ line = process.stdout.readline()
+ if line == "":
Wladimir Palant 2012/09/14 17:24:18 Is this really a good break condition? An empty co
Felix Dahlke 2012/09/26 15:20:30 Done. An empty commit line would be "\n", but you'
+ break
+
+ matches = re.match(r"[A-Z]:.*(https?://.*)", line)
Wladimir Palant 2012/09/14 17:24:18 What if we have some additional text following the
Felix Dahlke 2012/09/26 15:20:30 Done.
+ if not matches:
+ continue
+
+ url = matches.group(1).strip()
+ urls.add(url)
+
+ return urls
+
+def print_statements(urls):
+ for url in urls:
+ print "INSERT INTO crawler_sites (url) VALUES ('" + url + "');"
Wladimir Palant 2012/09/14 17:24:18 While this might not be a big issue here, failing
Felix Dahlke 2012/09/26 15:20:30 Done. I'd rather stick to generating a file with s
+
+if __name__ == "__main__":
+ filter_list_dir = get_config().get("crawler", "filter_list_repository")
+ urls = extract_urls(filter_list_dir)
+ print_statements(urls)

Powered by Google App Engine
This is Rietveld