From 7281dd61063f0a0a528f1aba0d0dcb6259e38e40 Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Sun, 5 Jul 2009 21:08:58 -0500 Subject: [PATCH] Added some api endpoints to user model. --- api.py | 3 +++ binder.py | 2 +- models.py | 9 ++++++++- parsers.py | 30 ++++++++++++++++-------------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/api.py b/api.py index 369db0a..2e9068b 100644 --- a/api.py +++ b/api.py @@ -17,6 +17,9 @@ class API(object): self.secure = secure self.classes = classes + if username: + self.me = self.get_user(screen_name=username) + """Get public timeline""" public_timeline = bind_api( path = '/statuses/public_timeline.json', diff --git a/binder.py b/binder.py index 143a13e..8e3caeb 100644 --- a/binder.py +++ b/binder.py @@ -45,7 +45,7 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False) raise TweepError(parse_error(resp.read())) # Pass returned body into parser and return parser output - out = parser(resp.read(), api.classes) + out = parser(resp.read(), api) # close connection and return data conn.close() diff --git a/models.py b/models.py index fd765f1..b99af3c 100644 --- a/models.py +++ b/models.py @@ -4,4 +4,11 @@ class Status(object): class User(object): - pass + def timeline(self, **kargs): + return self._api.user_timeline(**kargs) + def mentions(self, **kargs): + return self._api.mentions(**kargs) + def friends(self, **kargs): + return self._api.friends(id=self.id, **kargs) + def followers(self, **kargs): + return self._api.followers(id=self.id, **kargs) diff --git a/parsers.py b/parsers.py index 7b7782c..f6037cb 100644 --- a/parsers.py +++ b/parsers.py @@ -13,48 +13,50 @@ def _parse_datetime(str): return datetime.strptime(str, '%a %b %d %H:%M:%S +0000 %Y') -def _parse_user(obj, classes): +def _parse_user(obj, api): - user = classes['user']() + user = api.classes['user']() + user._api = api for k,v in obj.items(): if k == 'created_at': setattr(user, k, _parse_datetime(v)) elif k == 'status': - setattr(user, k, _parse_status(v, classes)) + setattr(user, k, _parse_status(v, api)) else: setattr(user, k, v) return user -def parse_user(data, classes): +def parse_user(data, api): - return _parse_user(json.loads(data), classes) + return _parse_user(json.loads(data), api) -def parse_users(data, classes): +def parse_users(data, api): users = [] for obj in json.loads(data): - users.append(_parse_user(obj, classes)) + users.append(_parse_user(obj, api)) return users -def _parse_status(obj, classes): +def _parse_status(obj, api): - status = classes['status']() + status = api.classes['status']() + status._api = api for k,v in obj.items(): if k == 'user': - setattr(status, k, _parse_user(v, classes)) + setattr(status, k, _parse_user(v, api)) elif k == 'created_at': setattr(status, k, _parse_datetime(v)) else: setattr(status, k, v) return status -def parse_status(data, classes): +def parse_status(data, api): - return _parse_status(json.loads(data), classes) + return _parse_status(json.loads(data), api) -def parse_statuses(data, classes): +def parse_statuses(data, api): statuses = [] for obj in json.loads(data): - statuses.append(_parse_status(obj, classes)) + statuses.append(_parse_status(obj, api)) return statuses -- 2.25.1