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

Delta Between Two Patch Sets: sitescripts/urlfixer/bin/topDomains.py

Issue 8943045: Implemented extraction of URL Fixer data (Closed)
Left Patch Set: Created Nov. 28, 2012, 10:48 a.m.
Right Patch Set: Larger blacklist Created Nov. 28, 2012, 11:29 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/urlfixer/bin/forceDomains.py ('k') | sitescripts/urlfixer/schema.sql » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2012 Eyeo GmbH 4 # Copyright (C) 2006-2012 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 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 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 20 matching lines...) Expand all
31 def getTopDomains(count=5000): 31 def getTopDomains(count=5000):
32 db = _get_db() 32 db = _get_db()
33 cursor = db.cursor(MySQLdb.cursors.DictCursor) 33 cursor = db.cursor(MySQLdb.cursors.DictCursor)
34 cursor.execute("SELECT id, domain, forceinclusion FROM domains") 34 cursor.execute("SELECT id, domain, forceinclusion FROM domains")
35 35
36 domains = {} 36 domains = {}
37 mandatory = [] 37 mandatory = []
38 for result in cursor: 38 for result in cursor:
39 domain = result["domain"] 39 domain = result["domain"]
40 if ("." not in domain or not re.search(r"[a-zA-Z]", domain) or 40 if ("." not in domain or not re.search(r"[a-zA-Z]", domain) or
41 re.search(r"['\"_,<>;]|^\.|\.$|\.\.", domain)): 41 re.search(r"['\"_,<>:;!$%&/()*+#~]|^\.|\.$|\.\.", domain)):
42 continue 42 continue
43 43
44 typed = _get_weighted_count(db, result["id"], STATUS_TYPED) 44 typed = _get_weighted_count(db, result["id"], STATUS_TYPED)
45 correction = _get_weighted_count(db, result["id"], STATUS_CORRECTION) 45 correction = _get_weighted_count(db, result["id"], STATUS_CORRECTION)
46 typo = _get_weighted_count(db, result["id"], STATUS_TYPO) 46 typo = _get_weighted_count(db, result["id"], STATUS_TYPO)
47 fp = _get_weighted_count(db, result["id"], STATUS_FALSE_POSITIVE) 47 fp = _get_weighted_count(db, result["id"], STATUS_FALSE_POSITIVE)
48 correctness = _calculate_correctness(typed + correction, typo + fp) 48 correctness = _calculate_correctness(typed + correction, typo + fp)
49 49
50 domains[domain] = correctness 50 domains[domain] = correctness
51 if result["forceinclusion"]: 51 if result["forceinclusion"]:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 else: 86 else:
87 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, 87 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database,
88 use_unicode=True, charset="utf8") 88 use_unicode=True, charset="utf8")
89 89
90 if __name__ == '__main__': 90 if __name__ == '__main__':
91 setupStderr() 91 setupStderr()
92 92
93 domains = getTopDomains() 93 domains = getTopDomains()
94 for domain in domains: 94 for domain in domains:
95 print domain.encode("utf-8") 95 print domain.encode("utf-8")
LEFTRIGHT

Powered by Google App Engine
This is Rietveld