From: Josh Roesslein Date: Mon, 6 Jul 2009 00:34:46 +0000 (-0500) Subject: Added datetime parsing. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=03ad0a2ee75db5d1ee6a1b42943ef39bb3e1f9d5;p=tweepy.git Added datetime parsing. --- diff --git a/parsers.py b/parsers.py index 8330b84..b8866fc 100644 --- a/parsers.py +++ b/parsers.py @@ -1,3 +1,5 @@ +from datetime import datetime + try: import json except ImportError: @@ -7,6 +9,10 @@ def parse_error(data): return json.loads(data)['error'] +def _parse_datetime(str): + + return datetime.strptime(str, '%a %b %d %H:%M:%S +0000 %Y') + def _parse_user(obj, classes): user = classes['user']() @@ -27,6 +33,8 @@ def _parse_status(obj, classes): for k,v in obj.items(): if k == 'user': setattr(status, k, _parse_user(v, classes)) + elif k == 'created_at': + setattr(status, k, _parse_datetime(v)) else: setattr(status, k, v) return status