OLD | NEW |
(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 sys, os, MySQLdb |
| 19 from sitescripts.utils import get_config, setupStderr |
| 20 |
| 21 """ |
| 22 This script adds domains supplied on the command line to the "correct domains" |
| 23 list permanently. This is useful for less popular domains that are commonly |
| 24 affected by false positives. |
| 25 """ |
| 26 |
| 27 def forceDomains(domains): |
| 28 db = _get_db() |
| 29 for domain in domains: |
| 30 cursor = db.cursor(MySQLdb.cursors.DictCursor) |
| 31 cursor.execute("""INSERT INTO domains(domain, forceinclusion) VALUES (%s, 1) |
| 32 ON DUPLICATE KEY UPDATE forceinclusion = 1""", domain) |
| 33 db.commit() |
| 34 |
| 35 def _get_db(): |
| 36 database = get_config().get("urlfixer", "database") |
| 37 dbuser = get_config().get("urlfixer", "dbuser") |
| 38 dbpasswd = get_config().get("urlfixer", "dbpassword") |
| 39 if os.name == "nt": |
| 40 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, |
| 41 use_unicode=True, charset="utf8", named_pipe=True) |
| 42 else: |
| 43 return MySQLdb.connect(user=dbuser, passwd=dbpasswd, db=database, |
| 44 use_unicode=True, charset="utf8") |
| 45 |
| 46 if __name__ == '__main__': |
| 47 setupStderr() |
| 48 |
| 49 if len(sys.argv) <= 1: |
| 50 print >>sys.stderr, "Please specify the domain names as command line paramet
ers" |
| 51 sys.exit(1) |
| 52 |
| 53 forceDomains(sys.argv[1:]) |
OLD | NEW |