-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwikidataedits.py
More file actions
45 lines (36 loc) · 884 Bytes
/
wikidataedits.py
File metadata and controls
45 lines (36 loc) · 884 Bytes
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
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import os
import cgi
import json
import sys
from wmflabs import db
def jsonify(response):
return json.dumps(response)
#Print header
print('Content-type: application/json')
print()
# Fetch params
if 'QUERY_STRING' in os.environ:
QS = os.environ['QUERY_STRING']
qs = cgi.parse_qs(QS)
try:
username = qs['user'][0].replace('_', ' ')
except:
print('{"error": "nouser"}')
sys.exit(0)
else:
print('{"error": "nouser"}')
sys.exit(0)
##### PROGRAM ####
conn = db.connect('wikidatawiki')
cur = conn.cursor()
with cur:
sql = 'select count(*) as edit_count from change_tag join revision on rev_id=ct_rev_id where ct_tag_id=155 and rev_actor=(select actor_id from actor where actor_name="' + username + '");'
cur.execute(sql)
data = cur.fetchall()
result = data[0][0]
response = {
'edits': result
}
print(jsonify(response))