-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
144 lines (110 loc) · 3.78 KB
/
main.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
from fastapi import FastAPI, Response
import uvicorn
import argparse
from typing import Dict
from driver.connectors.tnd_conn import TinderConnector
from driver.driver import start_driver
import AI_logic.respond
import AI_logic.opener
import AI_logic.airtable
from dotenv import load_dotenv, find_dotenv
from importlib import reload
import os
load_dotenv(find_dotenv())
use_tindebielik = os.getenv('USE_TINDEBIELIK')
if use_tindebielik:
import AI_logic.respond_tindebielik
app = FastAPI()
parser = argparse.ArgumentParser()
parser.add_argument('-he', '--head', action='store_true',
help='selenium in head (non-headless) option')
args = parser.parse_args()
@app.get('/')
def check_driver_state():
response = "Driver up and running" if dating_connector.driver else "Driver not running"
return response
@app.get('/start_tnd')
def load_main_page_tnd():
print("main page request arrived")
global dating_connector
dating_connector = tinder_connector
dating_connector.load_main_page()
return 200
@app.get('/respond/{girl_nr}')
def respond_nr(girl_nr: int = None):
print("msgs request arrived")
messages = dating_connector.get_msgs(girl_nr)
name_age = dating_connector.get_name_age()
if not use_tindebielik:
response = AI_logic.respond.respond_to_girl(name_age, messages)
else:
response = AI_logic.respond_tindebielik.respond_to_girl_tindebielik(name_age, messages)
send_messages_endpoint(payload={'message': response})
return 200
@app.get('/respond')
def respond():
return respond_nr()
@app.get('/respond_all')
def respond_to_all():
print("respond all request arrived")
new_messages_nr = dating_connector.count_new_messages()
for i in range(new_messages_nr):
respond()
return 200
@app.get('/opener')
def write_opener():
print("opener request arrived")
name, bio = dating_connector.get_bio()
message = AI_logic.opener.generate_opener(name, bio)
send_messages_endpoint({'message': message})
return 200
# function to send predefined nr of openers
@app.get('/batch_openers/{nr_openers}')
def write_openers(nr_openers: int = None):
print("batch of openers request arrived")
for i in range(nr_openers):
name, bio = dating_connector.get_bio()
message = AI_logic.opener.generate_opener(name, bio)
send_messages_endpoint({'message': message})
return 200
@app.get('/opener/{girl_nr}')
def write_opener(girl_nr: int = None):
print("opener request arrived")
name, bio = dating_connector.get_bio(girl_nr)
message = AI_logic.opener.generate_opener(name, bio)
send_messages_endpoint({'message': message})
return 200
@app.get('/rise')
def rise_girls():
print("Rise request arrived")
dating_connector.rise_girls()
return 200
@app.get('/clear_base')
def remove_expired():
print("Clear base request arrived")
AI_logic.airtable.remove_expired_girls()
return 200
@app.post("/send_message")
def send_messages_endpoint(payload: Dict[str, str]):
print("message request arrived")
dating_connector.send_messages(payload['message'])
return 200
@app.get("/close")
def close_app():
dating_connector.close_app()
return 200
# use that endpoint to reload AI modules after providing changes on propmts or AI modules code
# without restarting whole application
@app.get('/reload')
async def reload_modules():
reload(AI_logic.respond)
reload(AI_logic.opener)
reload(AI_logic.airtable)
return {"message": "Modules reloaded"}
if __name__ == '__main__':
driver = start_driver(args.head)
tinder_connector = TinderConnector(driver)
#badoo_connector = BadooConnector(driver)
#bumble_connector = BumbleConnector(driver)
dating_connector = tinder_connector
uvicorn.run(app, host='127.0.0.1', port=8080)