import urllib
import urllib2
-from misc import *
-from models import *
+from misc import TweepError, require_auth
+from models import Status, User
from parsers import *
"""
self._opener = self._build_opener(username, password)
def public_timeline(self):
- return self._fetch('statuses/public_timelinee.json')
+ return parse_list(self._Status, self._fetch('statuses/public_timeline.json'))
@require_auth
def friends_timeline(self, since_id=None, max_id=None, count=None, page=None):
# Send request
try:
- return self._opener.open(req)
+ return self._opener.open(req).read()
except urllib2.HTTPError, e:
raise TweepError(parse_error(e.read()))
except ImportError:
import simplejson as json
-def parse_error(jsondata):
+def parse_error(data):
- return json.loads(jsondata)['error']
+ return json.loads(data)['error']
+
+def parse_item(type, data):
+ t = type()
+ for k,v in json.loads(data).items():
+ setattr(t, k, v)
+ return t
+
+def parse_list(type, data):
+ types = []
+
+ for obj in json.loads(data):
+ t = type()
+ for k,v in obj.items():
+ setattr(t, k, v)
+ types.append(t)
+
+ return types