From b3aae7f647da433e7a793a4c37281611a462e78a Mon Sep 17 00:00:00 2001 From: louisabraham Date: Sun, 1 Jul 2018 15:57:50 +0200 Subject: [PATCH 1/9] PEP08 --- pynder/api.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pynder/api.py b/pynder/api.py index ecb9de0..0fdd102 100644 --- a/pynder/api.py +++ b/pynder/api.py @@ -23,7 +23,8 @@ def _full_url(self, url): return constants.API_BASE + url def auth(self, facebook_id, facebook_token): - data = {"facebook_id": str(facebook_id), "facebook_token": facebook_token} + data = {"facebook_id": str(facebook_id), + "facebook_token": facebook_token} result = self._session.post( self._full_url('/auth'), json=data, proxies=self._proxies).json() if 'token' not in result: @@ -65,10 +66,10 @@ def meta(self): def add_profile_photo(self, fbid, x_dist, y_dist, x_offset, y_offset): data = { - "transmit": "fb", - "assets": [{"id": str(fbid), "xdistance_percent": float(x_dist), "ydistance_percent": float(y_dist), - "xoffset_percent": float(x_offset), "yoffset_percent": float(y_offset)}] - } + "transmit": "fb", + "assets": [{"id": str(fbid), "xdistance_percent": float(x_dist), "ydistance_percent": float(y_dist), + "xoffset_percent": float(x_offset), "yoffset_percent": float(y_offset)}] + } return self._request("post", constants.CONTENT_BASE + "/media", data=data) From c7640fd160d1b2e80e5354f758beb5ee95e55f1e Mon Sep 17 00:00:00 2001 From: louisabraham Date: Sun, 1 Jul 2018 15:58:15 +0200 Subject: [PATCH 2/9] raise error for like fail --- pynder/api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pynder/api.py b/pynder/api.py index 0fdd102..e9f9140 100644 --- a/pynder/api.py +++ b/pynder/api.py @@ -91,7 +91,10 @@ def update_profile(self, profile): return self._post("/profile", profile) def like(self, user): - return self._get("/like/{}".format(user)) + ans = self._get("/like/{}".format(user)) + if 'rate_limited_until' in ans: + raise errors.RequestError('Like limit exceeded') + return ans def dislike(self, user): return self._get("/pass/{}".format(user)) From d0018fab38ea582e9439b55565d685191101c974 Mon Sep 17 00:00:00 2001 From: louisabraham Date: Sun, 1 Jul 2018 16:13:51 +0200 Subject: [PATCH 3/9] pep8 --- pynder/models/user.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pynder/models/user.py b/pynder/models/user.py index 05c8407..cd182fc 100644 --- a/pynder/models/user.py +++ b/pynder/models/user.py @@ -23,10 +23,14 @@ def __init__(self, data, session): self.schools = {} self.jobs = [] try: - self.schools.update({school["id"]: school["name"] for school in data['schools'] if 'id' in school and 'name' in school}) - self.jobs.extend(["%s @ %s" % (job["title"]["name"], job["company"]["name"]) for job in data['jobs'] if 'title' in job and 'company' in job]) - self.jobs.extend(["%s" % (job["company"]["name"],) for job in data['jobs'] if 'title' not in job and 'company' in job]) - self.jobs.extend(["%s" % (job["title"]["name"],) for job in data['jobs'] if 'title' in job and 'company' not in job]) + self.schools.update({school["id"]: school["name"] + for school in data['schools'] if 'id' in school and 'name' in school}) + self.jobs.extend(["%s @ %s" % (job["title"]["name"], job["company"]["name"]) + for job in data['jobs'] if 'title' in job and 'company' in job]) + self.jobs.extend(["%s" % (job["company"]["name"],) + for job in data['jobs'] if 'title' not in job and 'company' in job]) + self.jobs.extend(["%s" % (job["title"]["name"],) + for job in data['jobs'] if 'title' in job and 'company' not in job]) except (ValueError, KeyError): pass @@ -128,7 +132,7 @@ def __init__(self, match, _session): self.id = match["_id"] self.user, self.messages = None, [] self.match_date = datetime.datetime.strptime( - match["created_date"], "%Y-%m-%dT%H:%M:%S.%fZ" + match["created_date"], "%Y-%m-%dT%H:%M:%S.%fZ" ) if 'person' in match: user_data = _session._api.user_info( From 45654fe14e9d372e059df23f7ad15c1d0c4f490c Mon Sep 17 00:00:00 2001 From: louisabraham Date: Sun, 1 Jul 2018 16:14:05 +0200 Subject: [PATCH 4/9] add reload function --- pynder/models/user.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pynder/models/user.py b/pynder/models/user.py index cd182fc..b92929b 100644 --- a/pynder/models/user.py +++ b/pynder/models/user.py @@ -34,6 +34,10 @@ def __init__(self, data, session): except (ValueError, KeyError): pass + def reload(self): + data = self._session._api.user_info(self.id) + return User(data['results'], self._session) + @property def instagram_username(self): if "instagram" in self._data: From 92c76549f7d7ea27c02c82f121eb39139a4f8fe9 Mon Sep 17 00:00:00 2001 From: louisabraham Date: Sun, 1 Jul 2018 16:18:04 +0200 Subject: [PATCH 5/9] fix #199 --- pynder/models/user.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pynder/models/user.py b/pynder/models/user.py index b92929b..0da88d5 100644 --- a/pynder/models/user.py +++ b/pynder/models/user.py @@ -1,13 +1,13 @@ import itertools import datetime import dateutil.parser -import six +from future.utils import python_2_unicode_compatible from pynder.models.base import Model from pynder.constants import GENDER_MAP, SIMPLE_FIELDS, VALID_PHOTO_SIZES from pynder.models.message import Message - +@python_2_unicode_compatible class User(Model): def __init__(self, data, session): @@ -97,11 +97,8 @@ def age(self): def share_link(self): return self._session._api.share(self.id)['link'] - def __unicode__(self): - return u"{n} ({a})".format(n=self.name, a=self.age) - def __str__(self): - return six.text_type(self).encode('utf-8') + return u"{n} ({a})".format(n=self.name, a=self.age) def __repr__(self): return repr(self.name) From ef9a40d285836e4f74e0353a6417117afee71101 Mon Sep 17 00:00:00 2001 From: louisabraham Date: Sun, 1 Jul 2018 16:33:14 +0200 Subject: [PATCH 6/9] change repr of User --- pynder/models/user.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pynder/models/user.py b/pynder/models/user.py index 0da88d5..d722ebc 100644 --- a/pynder/models/user.py +++ b/pynder/models/user.py @@ -7,6 +7,7 @@ from pynder.constants import GENDER_MAP, SIMPLE_FIELDS, VALID_PHOTO_SIZES from pynder.models.message import Message + @python_2_unicode_compatible class User(Model): @@ -101,7 +102,10 @@ def __str__(self): return u"{n} ({a})".format(n=self.name, a=self.age) def __repr__(self): - return repr(self.name) + fmt = "User(name={n!r}, age={a}, id={i!r})" + return fmt.format(n=self.name, + a=self.age, + i=self.id) def report(self, cause, text=""): return self._session._api.report(self.id, cause, text) From 9b4427a27abf0177ccbecc3fb90f69f2da5b20e0 Mon Sep 17 00:00:00 2001 From: louisabraham Date: Sun, 1 Jul 2018 16:33:38 +0200 Subject: [PATCH 7/9] pep8 --- pynder/session.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pynder/session.py b/pynder/session.py index 8669bb8..9c4bff0 100644 --- a/pynder/session.py +++ b/pynder/session.py @@ -10,7 +10,8 @@ class Session(object): def __init__(self, facebook_token=None, XAuthToken=None, proxies=None, facebook_id=None): if facebook_token is None and XAuthToken is None: - raise InitializationError("Either XAuth or facebook token must be set") + raise InitializationError( + "Either XAuth or facebook token must be set") self._api = api.TinderAPI(XAuthToken, proxies) # perform authentication @@ -74,7 +75,8 @@ def can_like_in(self): Return the number of seconds before being allowed to issue likes """ now = int(time()) - limited_until = self._api.meta()['rating'].get('rate_limited_until', now) + limited_until = self._api.meta()['rating'].get( + 'rate_limited_until', now) return limited_until / 1000 - now @property From b23b69f9a858eeef177f4c053486d7bce81f6e19 Mon Sep 17 00:00:00 2001 From: louisabraham Date: Sun, 1 Jul 2018 16:40:15 +0200 Subject: [PATCH 8/9] add user_from_id function --- pynder/session.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pynder/session.py b/pynder/session.py index 9c4bff0..ef73bc1 100644 --- a/pynder/session.py +++ b/pynder/session.py @@ -22,6 +22,10 @@ def __init__(self, facebook_token=None, XAuthToken=None, proxies=None, facebook_ def profile(self): return Profile(self._api.profile(), self._api) + def user_from_id(self, id): + data = self._api.user_info(id) + return User(data['results'], self) + def nearby_users(self, limit=10): while True: response = self._api.recs(limit) From b2e7a0e246ed8aa17b85b6345ebe3c10a58c3622 Mon Sep 17 00:00:00 2001 From: louisabraham Date: Sun, 1 Jul 2018 16:41:08 +0200 Subject: [PATCH 9/9] profile shouldn't be a cached property --- pynder/session.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pynder/session.py b/pynder/session.py index ef73bc1..694def6 100644 --- a/pynder/session.py +++ b/pynder/session.py @@ -1,5 +1,4 @@ from time import time -from cached_property import cached_property import pynder.api as api from pynder.errors import InitializationError, RecsTimeout @@ -18,7 +17,7 @@ def __init__(self, facebook_token=None, XAuthToken=None, proxies=None, facebook_ if XAuthToken is None: self._api.auth(facebook_id, facebook_token) - @cached_property + @property def profile(self): return Profile(self._api.profile(), self._api)