ka1kuk commited on
Commit
de1c1b5
1 Parent(s): 98adbab

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +34 -1
main.py CHANGED
@@ -5,6 +5,10 @@ from fastapi import FastAPI, Request, Path
5
  from pydantic import BaseModel
6
  from fastapi.middleware.cors import CORSMiddleware
7
  from ImageCreator import generate_image_prodia
 
 
 
 
8
 
9
  app = FastAPI()
10
 
@@ -29,7 +33,36 @@ def search_google(query):
29
  ).execute()
30
  return result['items']
31
 
32
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  @app.get("/")
34
  def hello():
35
  return "Hello! My name is Linlada."
 
5
  from pydantic import BaseModel
6
  from fastapi.middleware.cors import CORSMiddleware
7
  from ImageCreator import generate_image_prodia
8
+ import asyncio
9
+ import uuid
10
+ import json
11
+ from aiohttp import ClientSession
12
 
13
  app = FastAPI()
14
 
 
33
  ).execute()
34
  return result['items']
35
 
36
+ async def create_async_generator(
37
+ proxy: str = None,
38
+ **kwargs
39
+ ):
40
+ if proxy and "://" not in proxy:
41
+ proxy = f"http://{proxy}"
42
+ headers = {
43
+ "authority": "liaobots.com",
44
+ "content-type": "application/json",
45
+ "origin": "https://liaobots.com",
46
+ "referer": "https://liaobots.com/",
47
+ "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
48
+ }
49
+ async with ClientSession(
50
+ headers=headers
51
+ ) as session:
52
+ async with session.post("https://liaobots.com/api/user", proxy=proxy, json={"authcode": ""}) as response:
53
+ response.raise_for_status()
54
+ auth_code = json.loads((await response.text()))["authCode"]
55
+
56
+ return auth_code
57
+
58
+ @app.get('/authCode')
59
+ def AuthCode():
60
+ loop = asyncio.new_event_loop()
61
+ asyncio.set_event_loop(loop)
62
+ result = loop.run_until_complete(create_async_generator())
63
+ loop.close()
64
+ return result
65
+
66
  @app.get("/")
67
  def hello():
68
  return "Hello! My name is Linlada."