tqhoa's picture
Update modules/app.py
4e55ec5 verified
raw
history blame contribute delete
756 Bytes
from fastapi import FastAPI, Query, Request
import os
from typing import Any, Optional, Dict
import requests
app = FastAPI(
title="Test"
)
@app.head("/")
@app.get("/")
async def get_user_info(request: Request) -> Dict[str, str]:
client_host = request.headers.get('x-forwarded-for')
user_agent = request.headers.get('user-agent')
print(request.headers)
push_noti_tele(client_host)
return {
"IP Address": client_host,
"User Agent": user_agent,
}
def push_noti_tele(message):
url = f"https://api.telegram.org/bot7210957168:AAEy0umCg4VTCilHTE3yICnsQT8cPrbeOr4/sendMessage"
payload = {
"chat_id": "-4159820605",
"text": message
}
response = requests.post(url, data=payload)