Created
October 5, 2019 09:08
-
-
Save joelbarmettlerUZH/410a434a6f3603512d50e263c9e1c7ab to your computer and use it in GitHub Desktop.
Tinder Person class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from geopy.geocoders import Nominatim | |
TINDER_URL = "https://api.gotinder.com" | |
geolocator = Nominatim(user_agent="auto-tinder") | |
PROF_FILE = "./images/unclassified/profiles.txt" | |
class Person(object): | |
def __init__(self, data, api): | |
self._api = api | |
self.id = data["_id"] | |
self.name = data.get("name", "Unknown") | |
self.bio = data.get("bio", "") | |
self.distance = data.get("distance_mi", 0) / 1.60934 | |
self.birth_date = datetime.datetime.strptime(data["birth_date"], '%Y-%m-%dT%H:%M:%S.%fZ') if data.get( | |
"birth_date", False) else None | |
self.gender = ["Male", "Female", "Unknown"][data.get("gender", 2)] | |
self.images = list(map(lambda photo: photo["url"], data.get("photos", []))) | |
self.jobs = list( | |
map(lambda job: {"title": job.get("title", {}).get("name"), "company": job.get("company", {}).get("name")}, data.get("jobs", []))) | |
self.schools = list(map(lambda school: school["name"], data.get("schools", []))) | |
if data.get("pos", False): | |
self.location = geolocator.reverse(f'{data["pos"]["lat"]}, {data["pos"]["lon"]}') | |
def __repr__(self): | |
return f"{self.id} - {self.name} ({self.birth_date.strftime('%d.%m.%Y')})" | |
def like(self): | |
return self._api.like(self.id) | |
def dislike(self): | |
return self._api.dislike(self.id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment