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

Side by Side Diff: sitescripts/crawler/bin/extract_sites.py

Issue 9045097: sitescripts: Unmerged changes (Closed)
Patch Set: Created Dec. 21, 2012, 9:39 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # coding: utf-8
2
3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2012 Eyeo GmbH
5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation.
9 #
10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17
18 import MySQLdb, os, re, subprocess
19 from sitescripts.utils import get_config
20
21 def hg(args):
22 return subprocess.Popen(["hg"] + args, stdout = subprocess.PIPE)
23
24 def extract_urls(filter_list_dir):
25 os.chdir(filter_list_dir)
26 process = hg(["log", "--template", "{desc}\n"])
27 urls = set([])
28
29 for line in process.stdout:
30 match = re.search(r"\b(https?://\S*)", line)
31 if not match:
32 continue
33
34 url = match.group(1).strip()
35 urls.add(url)
36
37 return urls
38
39 def print_statements(urls):
40 for url in urls:
41 escaped_url = MySQLdb.escape_string(url)
42 print "INSERT INTO crawler_sites (url) VALUES ('" + escaped_url + "');"
43
44 if __name__ == "__main__":
45 filter_list_dir = get_config().get("crawler", "filter_list_repository")
46 urls = extract_urls(filter_list_dir)
47 print_statements(urls)
OLDNEW

Powered by Google App Engine
This is Rietveld