# HG changeset patch # User Peter Sanchez # Date 1449892701 28800 # Fri Dec 11 19:58:21 2015 -0800 # Node ID 7e09f21a22f2abc4aaabd5139946bc1195625c56 # Parent f2e2f4981b37c7ebaf70ec479a866bb28f945f32 Added Instagram model and data support diff --git a/tinder/models.py b/tinder/models.py --- a/tinder/models.py +++ b/tinder/models.py @@ -126,6 +126,39 @@ return self.filename +class InstagramPhoto(object): + def __init__(self, data_dict): + self._data = data_dict + self.image = data_dict['image'] + self.link = data_dict['link'] + self.thumbnail = data_dict['thumbnail'] + self.timestamp = \ + datetime.datetime.fromtimestamp(float(data_dict['ts'])) + + def __str__(self): + return self.__unicode__() + + def __unicode__(self): + return self.image + + +class InstagramUser(object): + def __init__(self, data_dict, tinder_user): + self._data = data_dict + self._tinder_user = tinder_user + self.username = data_dict['username'] + self.profile_picture = data_dict['profile_picture'] + self.media_count = data_dict['media_count'] + self.last_fetch_time = pull_date(data_dict['last_fetch_time']) + self.photos = [InstagramPhoto(x) for x in data_dict['photos']] + + def __str__(self): + return self.__unicode__() + + def __unicode__(self): + return u'{0}: {1}'.format(self.username, self.profile_picture) + + class User(BaseModel): bio = FieldDescriptor('bio') gender = GenderDescriptor('gender') @@ -191,6 +224,12 @@ def schools(self): return [x['name'] for x in self._data.get('schools', [])] + @property + def instagram(self): + if 'instagram' not in self._data: + return None + return InstagramUser(self._data['instagram'], self) + def like(self): return self._api.like(self.id)