Left: | ||
Right: |
OLD | NEW |
---|---|
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, |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
14 # | 14 # |
15 # You should have received a copy of the GNU General Public License | 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/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
18 import hashlib, hmac, base64, MySQLdb, os, re, marshal, subprocess | 18 import hashlib, hmac, base64, MySQLdb, os, re, marshal, subprocess |
19 from sitescripts.utils import get_config, cached, get_template, sendMail | 19 from sitescripts.utils import get_config, cached, get_template, anonymizeMail, s endMail |
20 | 20 |
21 def getReportSubscriptions(guid): | 21 def getReportSubscriptions(guid): |
22 cursor = get_db().cursor(MySQLdb.cursors.DictCursor) | 22 cursor = get_db().cursor(MySQLdb.cursors.DictCursor) |
23 executeQuery(cursor, | 23 executeQuery(cursor, |
24 '''SELECT url, hasmatches FROM #PFX#sublists INNER JOIN | 24 '''SELECT url, hasmatches FROM #PFX#sublists INNER JOIN |
25 #PFX#subscriptions ON (#PFX#sublists.list = #PFX#subscriptions.id) | 25 #PFX#subscriptions ON (#PFX#sublists.list = #PFX#subscriptions.id) |
26 WHERE report = %s''', | 26 WHERE report = %s''', |
27 (guid)) | 27 (guid)) |
28 rows = cursor.fetchall() | 28 rows = cursor.fetchall() |
29 cursor.close() | 29 cursor.close() |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 if id != None: | 95 if id != None: |
96 filterMatch = lambda f: any(u == sn['id'] for u in f.get('subscriptions' , [])) | 96 filterMatch = lambda f: any(u == sn['id'] for u in f.get('subscriptions' , [])) |
97 hasMatches = any(filterMatch(f) for f in reportData.get('filters', [])) | 97 hasMatches = any(filterMatch(f) for f in reportData.get('filters', [])) |
98 executeQuery(cursor, | 98 executeQuery(cursor, |
99 '''INSERT IGNORE INTO #PFX#sublists (report, list, hasmatches) VA LUES (%s, %s, %s)''', | 99 '''INSERT IGNORE INTO #PFX#sublists (report, list, hasmatches) VA LUES (%s, %s, %s)''', |
100 (guid, id[0], hasMatches)) | 100 (guid, id[0], hasMatches)) |
101 | 101 |
102 get_db().commit() | 102 get_db().commit() |
103 | 103 |
104 reportData['guid'] = guid | 104 reportData['guid'] = guid |
105 if contact: | |
Wladimir Palant
2012/11/07 08:38:15
What if there is an email field but no contact? Th
Andrey Novikov
2012/11/07 09:38:48
Few lines above we have:
contact = getUserId(repor
| |
106 email = reportData['email'] | |
107 email = re.sub(r' at ', r'@', email) | |
108 email = re.sub(r' dot ', r'.', email) | |
109 reportData['email'] = anonymizeMail(email) | |
110 reportData['uid'] = contact | |
111 | |
105 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.html') | 112 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.html') |
106 dir = os.path.dirname(file) | 113 dir = os.path.dirname(file) |
107 if not os.path.exists(dir): | 114 if not os.path.exists(dir): |
108 os.makedirs(dir) | 115 os.makedirs(dir) |
109 template = get_template(get_config().get('reports', 'webTemplate')) | 116 template = get_template(get_config().get('reports', 'webTemplate')) |
110 template.stream(reportData).dump(file, encoding='utf-8') | 117 template.stream(reportData).dump(file, encoding='utf-8') |
111 | 118 |
112 def removeReport(guid): | 119 def removeReport(guid): |
113 cursor = get_db().cursor() | 120 cursor = get_db().cursor() |
114 executeQuery(cursor, | 121 executeQuery(cursor, |
115 '''DELETE FROM #PFX#reports WHERE guid = %s''', | 122 '''DELETE FROM #PFX#reports WHERE guid = %s''', |
116 (guid)) | 123 (guid)) |
117 get_db().commit() | 124 get_db().commit() |
118 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.html') | 125 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.html') |
119 if os.path.isfile(file): | 126 if os.path.isfile(file): |
120 os.remove(file) | 127 os.remove(file) |
121 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.png') | 128 file = os.path.join(get_config().get('reports', 'dataPath'), guid[0], guid[1], guid[2], guid[3], guid + '.png') |
122 if os.path.isfile(file): | 129 if os.path.isfile(file): |
123 os.remove(file) | 130 os.remove(file) |
124 | 131 |
132 def getUser(contact): | |
133 cursor = get_db().cursor(MySQLdb.cursors.DictCursor) | |
134 executeQuery(cursor, | |
135 '''SELECT reports, positive, negative FROM #PFX#users WHERE id = % s''', | |
136 (contact)) | |
137 user = cursor.fetchone() | |
138 return user | |
139 | |
125 @cached(3600) | 140 @cached(3600) |
126 def getUserUsefulnessScore(contact): | 141 def getUserUsefulnessScore(contact): |
127 if contact == None: | 142 if contact == None: |
128 return 0 | 143 return 0 |
129 | 144 |
130 cursor = get_db().cursor() | 145 cursor = get_db().cursor() |
131 # source from http://www.evanmiller.org/how-not-to-sort-by-average-rating.html | 146 # source from http://www.evanmiller.org/how-not-to-sort-by-average-rating.html |
132 executeQuery(cursor, | 147 executeQuery(cursor, |
133 '''SELECT ((positive + 1.9208) / (positive + negative) | 148 '''SELECT ((positive + 1.9208) / (positive + negative) |
134 - 1.96 * SQRT((positive * negative) / (positive + negati ve) + 0.9604) / (positive + negative)) | 149 - 1.96 * SQRT((positive * negative) / (positive + negati ve) + 0.9604) / (positive + negative)) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 dbpasswd = get_config().get('reports', 'dbpassword') | 243 dbpasswd = get_config().get('reports', 'dbpassword') |
229 if os.name == 'nt': | 244 if os.name == 'nt': |
230 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8', named_pipe=True) | 245 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8', named_pipe=True) |
231 else: | 246 else: |
232 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8') | 247 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, use_unicod e=True, charset='utf8') |
233 | 248 |
234 def executeQuery(cursor, query, args=None): | 249 def executeQuery(cursor, query, args=None): |
235 tablePrefix = get_config().get('reports', 'dbprefix') | 250 tablePrefix = get_config().get('reports', 'dbprefix') |
236 query = re.sub(r'#PFX#', tablePrefix, query) | 251 query = re.sub(r'#PFX#', tablePrefix, query) |
237 cursor.execute(query, args) | 252 cursor.execute(query, args) |
OLD | NEW |