-
Notifications
You must be signed in to change notification settings - Fork 0
/
tinder_bot.py
146 lines (113 loc) · 4.73 KB
/
tinder_bot.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
from asyncio.format_helpers import extract_stack
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from login_details import email, password
from selenium.webdriver.common.keys import Keys
import random
class TinderBot():
def __init__(self): # automatically run
self.driver = webdriver.Chrome() # control de browser
# Test open tinder
def open_tinder(self):
self.driver.get('https://tinder.com')
sleep(2)
login = self.driver.find_element(
'xpath', '/html/body/div[1]/div/div[1]/div/main/div[1]/div/div/div/div/header/div/div[2]/div[2]/a/div[2]/div[2]') # select the login element
login.click()
sleep(1)
self.facebook_login()
sleep(6)
try:
allow_location_button = self.driver.find_element(
'xpath', '/html/body/div[2]/main/div/div/div/div[3]/button[1]/span')
allow_location_button.click()
except:
print('no location popup')
try:
allow_notification_button = self.driver.find_element(
'xpath', '/html/body/div[2]/main/div/div/div/div[3]/button[2]')
allow_notification_button.click()
except:
print('no notification popup')
sleep(1)
# cookies close wd
cookies_denied_btn = self.driver.find_element(
'xpath', '/html/body/div[1]/div/div[2]/div/div/div[1]/div[2]/button')
cookies_denied_btn.click()
sleep(5)
# close welcome promotion
""" base_window = self.driver.window_handles[0] # Tinder window
waiting_matches_popup_wd = self.driver.window_handles[1]
self.driver.switch_to.window(waiting_matches_popup_wd)
mayb_after_btn = self.driver.find_element('xpath','/html/body/div[2]/main/div/div/div[3]/button[2]')
mayb_after_btn.click()
self.driver.switch_to.window(base_window) """
mayb_after_popup = self.driver.find_element(
'xpath', '/html/body/div[2]/main/div/div/div[3]/button[2]/span')
mayb_after_popup.click()
""" add_to_principal_popup = self.driver.find_element('xpath','/html/body/div[2]/main/div/div[2]/button[2]/div[2]/div[2]')
add_to_principal_popup.click() """
# fb login
def facebook_login(self):
# find and clck fb login btn
login_with_fb = self.driver.find_element(
'xpath', '/html/body/div[2]/main/div/div[1]/div/div/div[3]/span/div[2]/button')
login_with_fb.click()
# save references to main and fb windows
sleep(2)
base_window = self.driver.window_handles[0] # Tinder window
fb_popup_wd = self.driver.window_handles[1]
# Switch to Fb window
self.driver.switch_to.window(fb_popup_wd)
# find enter email, pwd, login
# cookies fb
# cookies_accept_button = self.driver.find_element('xpath',)
# cookies_accept_button.click()
# Login to FB
email_field = self.driver.find_element(
'xpath', '/html/body/div/div[2]/div[1]/form/div/div[1]/div/input')
pwd_field = self.driver.find_element(
'xpath', '/html/body/div/div[2]/div[1]/form/div/div[2]/div/input')
login_btn = self.driver.find_element(
'xpath', '/html/body/div/div[2]/div[1]/form/div/div[3]/label[2]/input')
# enter email, pwd and login
email_field.send_keys(email)
pwd_field.send_keys(password)
login_btn.click()
self.driver.switch_to.window(base_window)
def extra_popup(self):
self.driver.find_element(
By.CSS_SELECTOR, ".Mx\\(a\\) .l17p5q9z").click()
def riht_swipe(self):
doc = self.driver.find_element('xpath', '//*[@id="Tinder"]/body')
doc.send_keys(Keys.ARROW_RIGHT)
try:
self.extra_popup()
except:
c=0
def dislike(self):
doc = self.driver.find_element('xpath', '//*[@id="Tinder"]/body')
doc.send_keys(Keys.ARROW_LEFT)
def auto_swipe(self): # keep swiping
liking_odds = .95
while True:
if random.random() < liking_odds:
try:
self.riht_swipe()
except:
self.close_match()
else:
self.dislike()
random_sleep = random.random() * 2
sleep(random_sleep) # time.sleep
def close_match(self):
match_popup = self.driver.find_element(
'xpath', '//*[@id="modal-manager-canvas"]/div/div/div[1]/div/div[3]/a')
match_popup.click()
# mimicking human behaivour
bot = TinderBot()
bot.open_tinder()
sleep(10)
bot.auto_swipe()
# based on https://github.com/tuomaskivioja/tinderBot/blob/master/tinder_bot.py