-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (51 loc) · 2.34 KB
/
main.py
File metadata and controls
67 lines (51 loc) · 2.34 KB
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
from typing import Optional
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.responses import RedirectResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi import Form
import json
import subprocess
import threading
app = FastAPI()
app.mount("/static",StaticFiles(directory="static"),name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/",response_class=HTMLResponse)
async def read_item(request: Request):
return templates.TemplateResponse("index3.html",{"request": request})
@app.post("/",response_class=HTMLResponse)
async def form_info(name: str = Form(...), password: Optional[str] = Form(None), profile: str = Form(...)):
# Save form data to a JSON file
data = {"name": name, "password": password or "NULL" , "profile" : profile}
with open('data.json', 'w') as json_file:
json.dump(data, json_file)
#Just to check output on terminal
print(f"Form data saved to JSON: {data}")
# Select and run the appropriate Python script based on the selected profile
script_mapping = {
"wtsp": "whatsapp_script.py",
"fb": "facebook_script.py",
"ig": "instagram_script.py",
"google": "google_script.py",
"tg": "telegram_script.py",
"twitter": "twitter_script.py",
}
selected_script = script_mapping.get(profile)
if selected_script:
# Run the selected script in the background using threading
threading.Thread(target=lambda: subprocess.run(["python", selected_script], check=True)).start()
print(f"Started background script: {selected_script}")
else:
print("No matching script for the selected profile.")
# Execute an selenium Python script
# subprocess.run(["python", "sellogin.py"], check=True)
# Redirect to the /success route after form submission
return RedirectResponse(url="/success", status_code=303)
@app.get("/success", response_class=HTMLResponse)
async def success_page(request: Request):
# Render the success.html template to show a success message
return templates.TemplateResponse("success.html", {"request": request})
# *****************************************************
# print(f"Received form data: Name={name}, pass={password}")
# return{"Succesfully submited"}