Commit 33cf3157 authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Implemented json parser.

parent 1cd325d4
import urllib
import urllib2
from misc import *
from models import *
from misc import TweepError, require_auth
from models import Status, User
from parsers import *
"""
......@@ -30,7 +30,7 @@ class API(object):
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):
......@@ -61,6 +61,6 @@ class API(object):
# Send request
try:
return self._opener.open(req)
return self._opener.open(req).read()
except urllib2.HTTPError, e:
raise TweepError(parse_error(e.read()))
......@@ -3,6 +3,23 @@ try:
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment