Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import logging
|
|
|
2 |
from contextlib import asynccontextmanager
|
3 |
from akenoai import AkenoXToJs as js
|
4 |
from akenoai.runner import run_fast
|
@@ -47,12 +48,10 @@ async def hello():
|
|
47 |
return {"success": "hello world!"}
|
48 |
|
49 |
@fast_app.get("/user/get_story")
|
50 |
-
async def get_user_story(link=None):
|
51 |
username, random_id = get_random_from_channel(link)
|
52 |
try:
|
53 |
stories = await user_client.get_stories(username, story_ids=[random_id])
|
54 |
-
# LOGS.info(f"Updates: {stories}")
|
55 |
-
# return {"done": "nothing"}
|
56 |
except Exception as e:
|
57 |
return {"error": str(e)}
|
58 |
if stories:
|
@@ -63,15 +62,20 @@ async def get_user_story(link=None):
|
|
63 |
)
|
64 |
caption = story.caption or f"By {user_client.me.mention}"
|
65 |
if file_id:
|
|
|
|
|
|
|
|
|
66 |
return {
|
|
|
67 |
"random_file_id": file_id,
|
68 |
"caption": caption
|
69 |
}
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
|
76 |
@fast_app.get("/user/get_user")
|
77 |
async def get_user(user_id=None):
|
|
|
1 |
import logging
|
2 |
+
import base64
|
3 |
from contextlib import asynccontextmanager
|
4 |
from akenoai import AkenoXToJs as js
|
5 |
from akenoai.runner import run_fast
|
|
|
48 |
return {"success": "hello world!"}
|
49 |
|
50 |
@fast_app.get("/user/get_story")
|
51 |
+
async def get_user_story(link: str = None):
|
52 |
username, random_id = get_random_from_channel(link)
|
53 |
try:
|
54 |
stories = await user_client.get_stories(username, story_ids=[random_id])
|
|
|
|
|
55 |
except Exception as e:
|
56 |
return {"error": str(e)}
|
57 |
if stories:
|
|
|
62 |
)
|
63 |
caption = story.caption or f"By {user_client.me.mention}"
|
64 |
if file_id:
|
65 |
+
image_path = await user_client.download_media(file_id)
|
66 |
+
|
67 |
+
with open(image_path, "rb") as f:
|
68 |
+
base64_image = base64.b64encode(f.read()).decode("utf-8")
|
69 |
return {
|
70 |
+
"download": base64_image,
|
71 |
"random_file_id": file_id,
|
72 |
"caption": caption
|
73 |
}
|
74 |
+
return {
|
75 |
+
"random_file_id": None,
|
76 |
+
"caption": None
|
77 |
+
}
|
78 |
+
|
79 |
|
80 |
@fast_app.get("/user/get_user")
|
81 |
async def get_user(user_id=None):
|