Spaces:
Running
on
Zero
Running
on
Zero
File size: 2,947 Bytes
164aab4 70e3d06 164aab4 54216e7 e485f1f 062317a a40dd85 33ae057 4ee8e2e 3a42cf7 7d25f85 164aab4 8f10d41 33413a1 164aab4 c85c203 3f66c9b 6e9fd94 aba7131 164aab4 aba7131 0872300 |
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 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import os
import sys
import subprocess
import logging
from fastapi import FastAPI, Request, HTTPException
import requests
import json
from datetime import datetime
import importlib
import pkgutil
from mysite.libs.utilities import validate_signature, no_process_file
#from mysite.database.database import ride,create_ride
from controllers.gra_04_database.rides import test_set_lide
from mysite.interpreter.prompt import prompt_genalate,test_prompt
from mysite.interpreter.google_chat import send_google_chat_card,send_google_chat_card_thread
#from mysite.interpreter.interpreter import chat_with_interpreter
from routers.gra_02_openInterpreter.OpenInterpreter import chat_with_interpreter_no_stream
from mysite.appsheet.appsheet import get_senario
import asyncio
logger = logging.getLogger(__name__)
"""
router
"""
def include_routers(app):
package_dir = "/home/user/app/routers"
if not os.path.exists(package_dir):
logger.error(f"Package directory {package_dir} does not exist.")
return
for module_info in pkgutil.iter_modules([package_dir]):
try:
if module_info.ispkg:
sub_package_dir = os.path.join(package_dir, module_info.name)
for sub_module_info in pkgutil.iter_modules([sub_package_dir]):
module_name = (
f"routers.{module_info.name}.{sub_module_info.name}"
if sub_module_info.ispkg
else f"routers.{module_info.name}.{sub_module_info.name}"
)
module = importlib.import_module(module_name)
if hasattr(module, "router"):
app.include_router(module.router)
else:
module_name = f"routers.{module_info.name}"
module = importlib.import_module(module_name)
if hasattr(module, "router"):
app.include_router(module.router)
except ModuleNotFoundError as e:
logger.error(f"Module not found: {e}")
except Exception as e:
logger.error(f"An error occurred: {e}")
from datetime import datetime
def get_user_profile(user_id, access_token):
url = f'https://api.line.me/v2/bot/profile/{user_id}'
headers = {
'Authorization': f'Bearer {access_token}'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
profile = response.json()
user_name = profile.get('displayName')
user_thumbnail = profile.get('pictureUrl')
return user_name, user_thumbnail
else:
print(f"Failed to get user profile: {response.status_code}, {response.text}")
return None, None
#from routers.webhooks import router
def setup_webhook_routes(app: FastAPI):
from polls.routers import register_routers
register_routers(app)
from routers.webhook import router
app.include_router(router) |