forked from fbessez/Tinder
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfeatures.py
160 lines (131 loc) · 5.3 KB
/
features.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
import random
from datetime import date, datetime
from time import sleep
import tinder_api as api
"""
This file collects important data on your matches,
allows you to sort them by last_activity_date, age,
gender, message count, and their average successRate.
"""
def get_match_info():
"""Collect data on Tinder matches and return detailed information for each match."""
matches = api.get_updates()["matches"]
datetime.utcnow()
match_info = {}
n = len(matches)
print("\nDownloading match info...", end="")
for i, match in enumerate(matches[:n]):
try:
person = match["person"]
if "bio" not in person:
person["bio"] = ""
match_info[i] = {
"name": person["name"],
"person_id": person["_id"], # This ID for looking up person
"match_id": match["id"], # This ID for messaging
"message_count": match["message_count"],
"photos": get_photos(person),
"bio": person["bio"],
"gender": person["gender"],
"avg_successRate": get_avg_successRate(person),
"messages": match["messages"],
"age": calculate_age(match["person"]["birth_date"]),
"distance": 0, # api.get_person(person_id)['results']['distance_mi'], # very slow
"last_activity_date": match["last_activity_date"],
}
except Exception as ex:
template = "An exception of type {0} occurred. Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)
print(message)
# continue
print(f" {n:g} matches... Done.")
return match_info
def get_match_id_by_name(name):
"""Returns a list_of_ids that have the same name as your input."""
global match_info
if list_of_ids := [match_info[match]["match_id"] for match in match_info if match_info[match]["name"] == name]:
return list_of_ids
return {"error": f"No matches by name of {name}"}
def get_photos(person):
"""Returns a list of photo urls."""
photos = person["photos"]
return [photo["url"] for photo in photos]
def calculate_age(birthday_string):
"""Converts from '1997-03-25T22:49:41.151Z' to an integer (age)."""
birthyear = int(birthday_string[:4])
birthmonth = int(birthday_string[5:7])
birthday = int(birthday_string[8:10])
today = date.today()
return today.year - birthyear - ((today.month, today.day) < (birthmonth, birthday))
def get_avg_successRate(person):
"""SuccessRate is determined by Tinder for their 'Smart Photos' feature."""
photos = person["photos"]
curr_avg = 0
for photo in photos:
try:
photo_successRate = photo["successRate"]
curr_avg += photo_successRate
except Exception:
return -1
return curr_avg / len(photos)
def sort_by_value(sortType):
"""
Sort options are:
'age', 'message_count', 'gender'.
"""
global match_info
return sorted(match_info.items(), key=lambda x: x[1][sortType], reverse=True)
def see_friends_profiles(name=None):
"""Retrieve friend profiles, optionally filtered by name, upcasing the first character of each word."""
friends = api.see_friends()
if name is None:
return friends
name = name.title() # upcases first character of each word
result_dict = {friend["name"]: friend for friend in friends if name in friend["name"]}
return result_dict or "No friends by that name"
def convert_from_datetime(difference):
"""Convert a timedelta object into a human-readable string format 'X days, X hrs XX min XX sec'."""
secs = difference.seconds
days = difference.days
m, s = divmod(secs, 60)
h, m = divmod(m, 60)
return "%d days, %d hrs %02d min %02d sec" % (days, h, m, s)
def get_last_activity_date(now, ping_time):
"""Calculate the time difference between current time and last ping time, returning it in a human-readable
format.
"""
ping_time = ping_time[: len(ping_time) - 5]
datetime_ping = datetime.strptime(ping_time, "%Y-%m-%dT%H:%M:%S")
difference = now - datetime_ping
return convert_from_datetime(difference)
def how_long_has_it_been():
"""Calculate the time difference between the current time and each person's last activity date in a human-readable
format.
"""
global match_info
now = datetime.utcnow()
times = {}
for person in match_info:
name = match_info[person]["name"]
ping_time = match_info[person]["last_activity_date"]
since = get_last_activity_date(now, ping_time)
times[name] = since
print(name, "----->", since)
return times
def pause():
"""
In order to appear as a real Tinder user using the app...
When making many API calls, it is important to pause a...
realistic amount of time between actions to not make Tinder...
suspicious!
"""
nap_length = 3 * random.random()
print(f"Napping for {nap_length:f} seconds...")
sleep(nap_length)
if __name__ == "__main__":
if api.authverif() is True:
print("Gathering Data on your matches...")
match_info = get_match_info()
else:
print("Something went wrong. You were not authorized.")