summaryrefslogtreecommitdiffstats
path: root/get-mediawiki-data
diff options
context:
space:
mode:
authorJames Laska <jlaska@redhat.com>2011-10-04 08:40:05 -0400
committerJames Laska <jlaska@redhat.com>2011-10-04 08:40:05 -0400
commitc17f8a2a0ee23101408b28d8467386f5de6f2928 (patch)
tree329ce057cfb0a4739ec1fd33a88fd8231903c805 /get-mediawiki-data
parentf7279fc66994527fd49946c5e602885630950979 (diff)
downloadscripts-c17f8a2a0ee23101408b28d8467386f5de6f2928.tar.gz
scripts-c17f8a2a0ee23101408b28d8467386f5de6f2928.tar.xz
scripts-c17f8a2a0ee23101408b28d8467386f5de6f2928.zip
Attempt to parse date format, fail when unrecognized
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