-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwlm_notify.py
46 lines (41 loc) · 1.34 KB
/
wlm_notify.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
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Wikipedia Loves Monuments helper script, notifies indafoto users with wrong image metadata.
"""
inda_user = '[email protected]'
mail_id = 1
delay = 5
import codecs, time
from pg8000 import DBAPI
import wikipedia as pywikibot
import indafoto
def db_gen(cursor, sql, limit = None):
cursor.execute(sql)
rows = cursor.fetchall()
i = 1
for row in rows:
if limit and i > limit:
break
yield row
i = i + 1
def main():
global inda_user, mail_id, delay
inda = indafoto.Session(inda_user)
conn = DBAPI.connect(host='1.2.3.4', port=12345, database='wikiloves', user='wlm_web', password='XXX')
cursor = conn.cursor()
text = codecs.open('wlm_mail.txt', 'rt', 'utf-8').read()
for (name, page) in db_gen(cursor, 'SELECT DISTINCT inda.author_name, inda.author_url FROM inda JOIN inda_mail ON inda.author_url = inda_mail.author_url AND mail_id = %d WHERE status = 2 AND NOT sent' % mail_id):
username = page[19:]
if inda.sendMessage(username, text.format(user = name)):
pywikibot.output('%s (%s) - OK' % (page, name))
cursor.execute('UPDATE inda_mail SET sent = true WHERE author_url = %s AND mail_id = %s', (page, mail_id))
conn.commit()
else:
pywikibot.output('%s (%s) - error' % (page, name))
time.sleep(delay)
if __name__ == "__main__":
try:
main()
finally:
pywikibot.stopme()