Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,131 @@
|
|
| 1 |
from fastapi.responses import JSONResponse, StreamingResponse
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from playwright.sync_api import sync_playwright
|
|
|
|
| 4 |
from fastapi import FastAPI
|
| 5 |
-
from
|
| 6 |
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
#-------------------------------------------------- << RUN >> --------------------------------------------------#
|
| 9 |
|
| 10 |
# uvicorn app:app
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
#-------------------------------------------------- << FUNCTIONS >> --------------------------------------------------#
|
| 13 |
|
| 14 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
captcha_element = page.query_selector('body > div.c526f8a4f.c8a792eff > main > section > div > div > div > form > div.c8b219657.c9a020846 > div.c8b219657.c1f2d1695 > div > div.cc9af1055.cddcd8014 > div.c4026b06e.cb1295f34 > img')
|
| 27 |
|
| 28 |
captcha_base64 = captcha_element.screenshot(type = 'png')
|
| 29 |
|
|
@@ -35,34 +137,102 @@ def get_captcha():
|
|
| 35 |
|
| 36 |
captcha_buffer.seek(0)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
# did = [cookie['value'] for cookie in cookies if cookie['name'] == 'did'][0]
|
| 42 |
-
# auth0 = [cookie['value'] for cookie in cookies if cookie['name'] == 'auth0'][0]
|
| 43 |
-
# did_compat = [cookie['value'] for cookie in cookies if cookie['name'] == 'did_compat'][0]
|
| 44 |
-
# auth0_compat = [cookie['value'] for cookie in cookies if cookie['name'] == 'auth0_compat'][0]
|
| 45 |
-
|
| 46 |
-
# print(state)
|
| 47 |
-
# print(did)
|
| 48 |
-
# print(auth0)
|
| 49 |
-
# print(did_compat)
|
| 50 |
-
# print(auth0_compat)
|
| 51 |
-
|
| 52 |
-
browser.close()
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
#-------------------------------------------------- << APP >> --------------------------------------------------#
|
| 61 |
|
| 62 |
app = FastAPI()
|
| 63 |
|
| 64 |
app.add_middleware(CORSMiddleware, allow_origins = ['*'], allow_credentials = True, allow_methods = ['*'], allow_headers = ['*'])
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
#-------------------------------------------------- << ROUTES >> --------------------------------------------------#
|
| 67 |
|
| 68 |
@app.get('/')
|
|
@@ -81,10 +251,29 @@ def get_captcha_route():
|
|
| 81 |
|
| 82 |
try:
|
| 83 |
|
| 84 |
-
captcha_buffer
|
| 85 |
|
| 86 |
return StreamingResponse(status_code = 200, content = captcha_buffer, media_type = 'image/png')
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
except Exception as exception:
|
| 89 |
|
| 90 |
return JSONResponse(status_code = 500, content = {'status' : 'error', 'message' : exception})
|
|
|
|
| 1 |
from fastapi.responses import JSONResponse, StreamingResponse
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from playwright.sync_api import sync_playwright
|
| 4 |
+
from bs4 import BeautifulSoup
|
| 5 |
from fastapi import FastAPI
|
| 6 |
+
from random import choice
|
| 7 |
from io import BytesIO
|
| 8 |
+
from time import sleep
|
| 9 |
+
from PIL import Image
|
| 10 |
+
import requests
|
| 11 |
|
| 12 |
#-------------------------------------------------- << RUN >> --------------------------------------------------#
|
| 13 |
|
| 14 |
# uvicorn app:app
|
| 15 |
|
| 16 |
+
#-------------------------------------------------- << VARIABLES >> --------------------------------------------------#
|
| 17 |
+
|
| 18 |
+
|
| 19 |
#-------------------------------------------------- << FUNCTIONS >> --------------------------------------------------#
|
| 20 |
|
| 21 |
+
def get_email():
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
|
| 25 |
+
url = 'https://temp-mail107.p.rapidapi.com/domains'
|
| 26 |
+
|
| 27 |
+
headers = {
|
| 28 |
+
'x-rapidapi-key': 'd3349ed2b8msh2a16ceeb6b2a192p173237jsn4ff2c7c6467e',
|
| 29 |
+
'x-rapidapi-host': 'temp-mail107.p.rapidapi.com'
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
response = requests.get(url, headers = headers)
|
| 33 |
+
|
| 34 |
+
data = response.json()
|
| 35 |
+
|
| 36 |
+
domains = data['data']
|
| 37 |
+
|
| 38 |
+
domain = choice(domains)
|
| 39 |
+
|
| 40 |
+
url = 'https://temp-mail107.p.rapidapi.com/create-account'
|
| 41 |
+
|
| 42 |
+
payload = { 'domain': domain }
|
| 43 |
+
headers = {
|
| 44 |
+
'x-rapidapi-key': 'd3349ed2b8msh2a16ceeb6b2a192p173237jsn4ff2c7c6467e',
|
| 45 |
+
'x-rapidapi-host': 'temp-mail107.p.rapidapi.com',
|
| 46 |
+
'Content-Type': 'application/json'
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
response = requests.post(url, json = payload, headers = headers)
|
| 50 |
+
|
| 51 |
+
data = response.json()
|
| 52 |
+
|
| 53 |
+
email = data['data']['address']
|
| 54 |
+
|
| 55 |
+
return email
|
| 56 |
+
|
| 57 |
+
except Exception as error:
|
| 58 |
+
|
| 59 |
+
print(f'error : {error}')
|
| 60 |
+
|
| 61 |
+
def get_verification_url(email):
|
| 62 |
+
|
| 63 |
+
try:
|
| 64 |
+
|
| 65 |
+
url = "https://temp-mail107.p.rapidapi.com/check-message"
|
| 66 |
+
|
| 67 |
+
querystring = {"address" : email}
|
| 68 |
+
|
| 69 |
+
headers = {
|
| 70 |
+
"x-rapidapi-key": "d3349ed2b8msh2a16ceeb6b2a192p173237jsn4ff2c7c6467e",
|
| 71 |
+
"x-rapidapi-host": "temp-mail107.p.rapidapi.com"
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
response = requests.get(url, headers = headers, params = querystring)
|
| 75 |
+
|
| 76 |
+
data = response.json()
|
| 77 |
+
|
| 78 |
+
while data['data'] == None:
|
| 79 |
+
|
| 80 |
+
sleep(2)
|
| 81 |
+
|
| 82 |
+
response = requests.get(url, headers = headers, params = querystring)
|
| 83 |
+
|
| 84 |
+
data = response.json()
|
| 85 |
+
|
| 86 |
+
html = data['data']['html']
|
| 87 |
+
|
| 88 |
+
soup = BeautifulSoup(html, 'html.parser')
|
| 89 |
+
|
| 90 |
+
verification_url = soup.find('a').get('href')
|
| 91 |
+
|
| 92 |
+
return verification_url
|
| 93 |
+
|
| 94 |
+
except Exception as error:
|
| 95 |
+
|
| 96 |
+
print(f'error : {error}')
|
| 97 |
|
| 98 |
+
class Bot:
|
| 99 |
+
|
| 100 |
+
def __init__(self):
|
| 101 |
|
| 102 |
+
self.playwright = None
|
| 103 |
+
self.browser = None
|
| 104 |
+
self.page = None
|
| 105 |
|
| 106 |
+
def get_captcha(self):
|
| 107 |
|
| 108 |
+
if self.page:
|
| 109 |
+
|
| 110 |
+
self.page.close()
|
| 111 |
|
| 112 |
+
if self.browser:
|
| 113 |
+
|
| 114 |
+
self.browser.close()
|
| 115 |
+
|
| 116 |
+
if self.playwright:
|
| 117 |
+
|
| 118 |
+
self.playwright.stop()
|
| 119 |
+
|
| 120 |
+
self.playwright = sync_playwright().start()
|
| 121 |
+
self.browser = self.playwright.chromium.launch(headless = True, args = ['--start-maximized'])
|
| 122 |
+
self.page = self.browser.new_page(no_viewport = True)
|
| 123 |
+
|
| 124 |
+
self.page.goto('https://www.thinkdiffusion.com/api/auth/signup')
|
| 125 |
+
|
| 126 |
+
self.page.wait_for_timeout(1000)
|
| 127 |
|
| 128 |
+
captcha_element = self.page.query_selector('body > div.c526f8a4f.c8a792eff > main > section > div > div > div > form > div.c8b219657.c9a020846 > div.c8b219657.c1f2d1695 > div > div.cc9af1055.cddcd8014 > div.c4026b06e.cb1295f34 > img')
|
| 129 |
|
| 130 |
captcha_base64 = captcha_element.screenshot(type = 'png')
|
| 131 |
|
|
|
|
| 137 |
|
| 138 |
captcha_buffer.seek(0)
|
| 139 |
|
| 140 |
+
return captcha_buffer
|
| 141 |
+
|
| 142 |
+
def generate_account(self, captcha_solution):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
+
if self.playwright and self.browser and self.page:
|
| 145 |
+
|
| 146 |
+
if captcha_solution.strip() != '':
|
| 147 |
+
|
| 148 |
+
try:
|
| 149 |
+
|
| 150 |
+
email = get_email()
|
| 151 |
+
password = 'Qwerty12321*'
|
| 152 |
+
|
| 153 |
+
self.page.locator('#email').press_sequentially(email)
|
| 154 |
+
self.page.locator('#password').press_sequentially(password)
|
| 155 |
+
self.page.locator('#captcha').press_sequentially(captcha_solution)
|
| 156 |
|
| 157 |
+
self.page.locator('body > div.c526f8a4f.c8a792eff > main > section > div > div > div > form > div.c2f62a829 > button').click()
|
| 158 |
+
|
| 159 |
+
verification_url = get_verification_url(email)
|
| 160 |
+
|
| 161 |
+
self.page.goto(verification_url)
|
| 162 |
+
|
| 163 |
+
self.page.wait_for_timeout(3000)
|
| 164 |
+
|
| 165 |
+
cookies = self.page.context.cookies()
|
| 166 |
+
|
| 167 |
+
csrf_token = [cookie['value'] for cookie in cookies if cookie['name'] == 'csrf_token'][0]
|
| 168 |
+
app_session = [cookie['value'] for cookie in cookies if cookie['name'] == 'appSession'][0]
|
| 169 |
+
|
| 170 |
+
self.page.close()
|
| 171 |
+
self.browser.close()
|
| 172 |
+
self.playwright.stop()
|
| 173 |
+
|
| 174 |
+
self.page = None
|
| 175 |
+
self.browser = None
|
| 176 |
+
self.playwright = None
|
| 177 |
+
|
| 178 |
+
headers = {
|
| 179 |
+
'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36'
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
data = {
|
| 183 |
+
'civitaiModelVersionId' : None,
|
| 184 |
+
'presetSlug' : 'turbo-comfy-exp',
|
| 185 |
+
'runningTime' : 1200,
|
| 186 |
+
'teamId' : None
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
cookies = {
|
| 190 |
+
'csrf_token' : csrf_token,
|
| 191 |
+
'appSession' : app_session
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
url = 'https://www.thinkdiffusion.com/api/machines/create'
|
| 195 |
+
|
| 196 |
+
response = requests.post(url = url, headers = headers, cookies = cookies, data = data)
|
| 197 |
+
|
| 198 |
+
data = response.json()
|
| 199 |
+
|
| 200 |
+
subdomain = data['subdomain']
|
| 201 |
+
|
| 202 |
+
url = f'https://{subdomain}.thinkdiffusion.xyz'
|
| 203 |
+
|
| 204 |
+
return {'status' : 'success', 'url' : url}
|
| 205 |
+
|
| 206 |
+
except Exception as exception:
|
| 207 |
+
|
| 208 |
+
self.page.close()
|
| 209 |
+
self.browser.close()
|
| 210 |
+
self.playwright.stop()
|
| 211 |
+
|
| 212 |
+
self.page = None
|
| 213 |
+
self.browser = None
|
| 214 |
+
self.playwright = None
|
| 215 |
+
|
| 216 |
+
return {'status' : 'error', 'message' : str(exception)}
|
| 217 |
+
|
| 218 |
+
else:
|
| 219 |
+
|
| 220 |
+
return {'status' : 'error', 'message' : 'captcha solution cannot be empty.'}
|
| 221 |
+
|
| 222 |
+
else:
|
| 223 |
+
|
| 224 |
+
return {'status' : 'error', 'message' : 'no browser available'}
|
| 225 |
+
|
| 226 |
#-------------------------------------------------- << APP >> --------------------------------------------------#
|
| 227 |
|
| 228 |
app = FastAPI()
|
| 229 |
|
| 230 |
app.add_middleware(CORSMiddleware, allow_origins = ['*'], allow_credentials = True, allow_methods = ['*'], allow_headers = ['*'])
|
| 231 |
|
| 232 |
+
#-------------------------------------------------- << BOT >> --------------------------------------------------#
|
| 233 |
+
|
| 234 |
+
bot = Bot()
|
| 235 |
+
|
| 236 |
#-------------------------------------------------- << ROUTES >> --------------------------------------------------#
|
| 237 |
|
| 238 |
@app.get('/')
|
|
|
|
| 251 |
|
| 252 |
try:
|
| 253 |
|
| 254 |
+
captcha_buffer = bot.get_captcha()
|
| 255 |
|
| 256 |
return StreamingResponse(status_code = 200, content = captcha_buffer, media_type = 'image/png')
|
| 257 |
|
| 258 |
+
except Exception as exception:
|
| 259 |
+
|
| 260 |
+
return JSONResponse(status_code = 500, content = {'status' : 'error', 'message' : exception})
|
| 261 |
+
|
| 262 |
+
@app.get('/generate-account/{captcha_solution}')
|
| 263 |
+
def generate_account_route(captcha_solution: str):
|
| 264 |
+
|
| 265 |
+
try:
|
| 266 |
+
|
| 267 |
+
response = bot.generate_account(captcha_solution)
|
| 268 |
+
|
| 269 |
+
if response['status'] == 'success':
|
| 270 |
+
|
| 271 |
+
return JSONResponse(status_code = 200, content = {'status' : response['status'], 'url' : response['url']})
|
| 272 |
+
|
| 273 |
+
if response['status'] == 'error':
|
| 274 |
+
|
| 275 |
+
return JSONResponse(status_code = 500, content = {'status' : response['status'], 'message' : response['message']})
|
| 276 |
+
|
| 277 |
except Exception as exception:
|
| 278 |
|
| 279 |
return JSONResponse(status_code = 500, content = {'status' : 'error', 'message' : exception})
|