Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -9,10 +9,15 @@ firebase_config = {
|
|
9 |
}
|
10 |
from fastapi import FastAPI,BackgroundTasks , Request
|
11 |
import requests
|
|
|
|
|
12 |
from pyrebase import initialize_app
|
13 |
import httpx
|
14 |
app = FastAPI()
|
15 |
-
|
|
|
|
|
|
|
16 |
# Firebase configuration
|
17 |
async def keep_alive_request(receiver_url: str):
|
18 |
async with httpx.AsyncClient() as client:
|
@@ -36,11 +41,11 @@ def fetch_and_store_data(request: Request,url: str = "https://dailymo-api.onrend
|
|
36 |
background_tasks.add_task(keep_alive_request, receiver_url)
|
37 |
print(response.status_code)
|
38 |
print(response.json())
|
39 |
-
data_to_store = {"a":"a"} # Assuming the response is in JSON format, adjust accordingly
|
40 |
-
|
41 |
# Write data to Firebase Realtime Database
|
42 |
db = firebase.database()
|
43 |
-
db.child('finally').set(response.json())
|
44 |
|
45 |
return {"status": "success", "message": "Data fetched and stored successfully." , "data_stored":response.json()}
|
46 |
|
@@ -50,9 +55,10 @@ def fetch_and_store_data(request: Request,url: str = "https://dailymo-api.onrend
|
|
50 |
def fetch_and_store_data():
|
51 |
try:
|
52 |
# Fetch data from the provided URL
|
|
|
53 |
db = firebase.database()
|
54 |
response=db.child("finally").child("url").get()
|
55 |
return {"status": response.val()}
|
56 |
|
57 |
except Exception as e:
|
58 |
-
return {"status": "error", "message": f"An error occurred: {str(e)}"}
|
|
|
9 |
}
|
10 |
from fastapi import FastAPI,BackgroundTasks , Request
|
11 |
import requests
|
12 |
+
import random
|
13 |
+
import string
|
14 |
from pyrebase import initialize_app
|
15 |
import httpx
|
16 |
app = FastAPI()
|
17 |
+
def gen_ran():
|
18 |
+
length_of_string = 6
|
19 |
+
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=length_of_string))
|
20 |
+
return random_string
|
21 |
# Firebase configuration
|
22 |
async def keep_alive_request(receiver_url: str):
|
23 |
async with httpx.AsyncClient() as client:
|
|
|
41 |
background_tasks.add_task(keep_alive_request, receiver_url)
|
42 |
print(response.status_code)
|
43 |
print(response.json())
|
44 |
+
# data_to_store = {"a":"a"} # Assuming the response is in JSON format, adjust accordingly
|
45 |
+
add=gen_ran()
|
46 |
# Write data to Firebase Realtime Database
|
47 |
db = firebase.database()
|
48 |
+
db.child('finally'+add).set(response.json())
|
49 |
|
50 |
return {"status": "success", "message": "Data fetched and stored successfully." , "data_stored":response.json()}
|
51 |
|
|
|
55 |
def fetch_and_store_data():
|
56 |
try:
|
57 |
# Fetch data from the provided URL
|
58 |
+
|
59 |
db = firebase.database()
|
60 |
response=db.child("finally").child("url").get()
|
61 |
return {"status": response.val()}
|
62 |
|
63 |
except Exception as e:
|
64 |
+
return {"status": "error", "message": f"An error occurred: {str(e)}"}
|