summaryrefslogtreecommitdiffstats
path: root/get-mediawiki-data
diff options
context:
space:
mode:
Diffstat (limited to 'get-mediawiki-data')
-rwxr-xr-xget-mediawiki-data25
1 files changed, 22 insertions, 3 deletions
diff --git a/get-mediawiki-data b/get-mediawiki-data
index a525206..e8505fc 100755
--- a/get-mediawiki-data
+++ b/get-mediawiki-data
@@ -154,16 +154,36 @@ def recentchanges(wiki, date_start='', date_end='', namespaces=""):
def list_usercontribs(wiki, user, date_start='', date_end='', namespaces=""):
'''Return a dictionary of page names and commits'''
- # "https://fedoraproject.org/w/api.php?action=query&list=usercontribs&uclimit=100&ucuser=jlaska&ucnamespacestart=2010-11-11T00:00:00Z&ucend=2010-11-01T23:59:59Z"
+ # "https://fedoraproject.org/w/api.php?action=query&list=usercontribs&uclimit=100&ucuser=jlaska&ucstart=2010-11-11T00:00:00Z&ucend=2010-11-01T23:59:59Z"
# Build query arguments and call wiki
query = dict(action='query',
list='usercontribs',
uclimit=50,
ucuser=user)
# FIXME - validate date input (expected format "%Y-%m-%dT%H:%M:%S")
+ # FIXME - move this to parse_args()
+ def recognize_date(d):
+ yyyymmdd = re.match(r'^(\d{2,4})([ -])(\d{1,2})([ -])(\d{1,2})\s*(.*)$', d)
+ if yyyymmdd:
+ hhmmss = re.match(r'(\d{1,2})[ -:\.](\d{1,2})[ -:\.](\d{1,2})', yyyymmdd.group(6))
+ if hhmmss:
+ date = datetime.datetime.strptime(d, \
+ "%%Y%s%%m%s%%d %%H:%%M:%%S" % (yyyymmdd.group(2), yyyymmdd.group(4)))
+ else:
+ date = datetime.datetime.strptime(d, \
+ "%%Y%s%%m%s%%d" % (yyyymmdd.group(2), yyyymmdd.group(4)))
+ date_str = date.strftime('%Y-%m-%dT%H:%M:%SZ')
+ return date_str
+ else:
+ # FIXME - return error for unexpected date format
+ raise Exception("Unrecognized date format: %s" % d)
+
if date_start != '':
+ # Convert to expected format
+ date_start = recognize_date(date_start)
query['ucstart'] = date_start
if date_end != '':
+ date_end = recognize_date(date_end)
query['ucend'] = date_end
if namespaces != '':
query['ucnamespace'] = namespaces
@@ -176,10 +196,9 @@ def list_usercontribs(wiki, user, date_start='', date_end='', namespaces=""):
de = datetime.datetime.strptime(date_end, '%Y-%m-%d %H:%M:%S')
if ds < de:
query['ucdir'] = 'newer'
- except ValueError:
+ except ValueError, e:
pass
-
if opts.debug: print query
response = wiki.call(query)
if opts.debug: print response