Spaces:
Sleeping
Sleeping
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from fastapi.responses import RedirectResponse, HTMLResponse
|
| 4 |
+
import urllib.parse
|
| 5 |
+
import requests, json, time
|
| 6 |
+
from password_generator import generate_password
|
| 7 |
+
import threading
|
| 8 |
+
import os
|
| 9 |
+
from dotenv import load_dotenv
|
| 10 |
+
|
| 11 |
+
user_credentials_google_apps_script_url = os.getenv("USER_CREDENTIALS_GOOGLE_APPS_SCRIPT_URL")
|
| 12 |
+
app_link = "https://mr-help-binrushd-salla-app.hf.space"
|
| 13 |
+
view_app_link = "https://mr-help-binrushd-salla-app.hf.space"
|
| 14 |
+
webhook_url = "https://mr-help-binrushd-salla-app.hf.space/notifyme"
|
| 15 |
+
|
| 16 |
+
app = FastAPI()
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class Message(BaseModel):
|
| 20 |
+
message: str
|
| 21 |
+
|
| 22 |
+
@app.get("/", response_class=HTMLResponse)
|
| 23 |
+
async def read_root():
|
| 24 |
+
return """Hello World"""
|
| 25 |
+
|
| 26 |
+
@app.get("/redirect")
|
| 27 |
+
def redirect_to_oauth():
|
| 28 |
+
queries = {
|
| 29 |
+
'client_id': '170fa108-4723-4816-9791-f227baa704b6',
|
| 30 |
+
'client_secret': 'b0ac2ce8a9e217c5e76b9b83539e9823',
|
| 31 |
+
'redirect_uri': 'https://mr-help-binrushd-salla-app.hf.space/redirect',
|
| 32 |
+
'response_type': 'code'
|
| 33 |
+
}
|
| 34 |
+
query_string = urllib.parse.urlencode(queries)
|
| 35 |
+
oauth_url = f' https://accounts.salla.sa/oauth2/auth?{query_string}'
|
| 36 |
+
return RedirectResponse(url=oauth_url)
|