Browse Source

Minor cleanup for afc_copyvios, mainly Unicode fixes.

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
becd135c52
1 changed files with 7 additions and 7 deletions
  1. +7
    -7
      earwigbot/tasks/afc_copyvios.py

+ 7
- 7
earwigbot/tasks/afc_copyvios.py View File

@@ -23,6 +23,7 @@
from hashlib import sha256 from hashlib import sha256
from os.path import expanduser from os.path import expanduser
from threading import Lock from threading import Lock
from urllib import quote


import oursql import oursql


@@ -86,9 +87,10 @@ class AFCCopyvios(Task):
confidence = "{0}%".format(round(result.confidence * 100, 2)) confidence = "{0}%".format(round(result.confidence * 100, 2))


if result.violation: if result.violation:
safeurl = quote(url.encode("utf8"), safe="/:").decode("utf8")
content = page.get() content = page.get()
template = "\{\{{0}|url={1}|confidence={2}\}\}\n"
template = template.format(self.template, url, confidence)
template = u"\{\{{0}|url={1}|confidence={2}\}\}\n"
template = template.format(self.template, safeurl, confidence)
newtext = template + content newtext = template + content
if "{url}" in self.summary: if "{url}" in self.summary:
page.edit(newtext, self.summary.format(url=url)) page.edit(newtext, self.summary.format(url=url))
@@ -110,9 +112,7 @@ class AFCCopyvios(Task):
with self.conn.cursor() as cursor: with self.conn.cursor() as cursor:
cursor.execute(query, (pageid,)) cursor.execute(query, (pageid,))
results = cursor.fetchall() results = cursor.fetchall()
if results:
return True
return False
return True if results else False


def log_processed(self, pageid): def log_processed(self, pageid):
"""Adds pageid to our database of processed pages. """Adds pageid to our database of processed pages.
@@ -138,8 +138,8 @@ class AFCCopyvios(Task):
be) retained for one day; this task does not remove old entries (that be) retained for one day; this task does not remove old entries (that
is handled by the Toolserver component). is handled by the Toolserver component).


This will only be called if "cache_results" == True in the task's
config, which is False by default.
This will only be called if ``cache_results == True`` in the task's
config, which is ``False`` by default.
""" """
pageid = page.pageid pageid = page.pageid
hash = sha256(page.get()).hexdigest() hash = sha256(page.get()).hexdigest()


Loading…
Cancel
Save