forked from Pascalco/DeltaBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
removeHiddenChar.py
33 lines (28 loc) · 1.12 KB
/
removeHiddenChar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# licensed under CC-Zero: https://creativecommons.org/publicdomain/zero/1.0
import MySQLdb
import pywikibot
import re
site = pywikibot.Site('wikidata', 'wikidata')
repo = site.data_repository()
db = MySQLdb.connect(host='wikidatawiki.labsdb', db='wikidatawiki_p', read_default_file='~/replica.my.cnf')
cur = db.cursor()
cur.execute('SELECT rc_title, comment_text FROM recentchanges JOIN comment_recentchanges ON rc_comment_id=comment_id WHERE rc_namespace=0 AND HEX(comment_text) LIKE "%E2808F";')
for row in cur.fetchall():
try:
res = re.search('\[\[Property:(P\d+)\]\]', row[1])
if not res:
continue
p = res.group(1)
item = pywikibot.ItemPage(repo, row[0])
item.get()
if p in item.claims:
for claim in item.claims[p]:
if claim.type in ['string', 'url', 'external-id']:
value = claim.getTarget()
if u'\u200f' in value:
newvalue = value.replace(u'\u200f', '').strip()
claim.changeTarget(newvalue)
except:
pass