niharika17032001 commited on
Commit
c3f1552
·
1 Parent(s): c8e5d7d

Create Dockerfile

Browse files
Files changed (3) hide show
  1. app.py +31 -10
  2. cookies.json +0 -0
  3. songs-1.json +0 -0
app.py CHANGED
@@ -1,16 +1,37 @@
1
- from fastapi import FastAPI
 
 
2
  import json
3
  import os
4
 
5
  app = FastAPI()
6
 
7
- @app.get("/")
8
- def read_root():
9
- return {"message": "Welcome to the Song API!"}
10
 
11
- @app.get("/songs")
12
- def get_songs():
13
- json_path = os.path.join(os.path.dirname(__file__), "songs.json")
14
- with open(json_path, "r", encoding="utf-8") as f:
15
- songs = json.load(f)
16
- return songs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from pydantic import BaseModel
3
+ from typing import Dict, Any
4
  import json
5
  import os
6
 
7
  app = FastAPI()
8
 
9
+ DATA_FILE = "cookies.json"
 
 
10
 
11
+ # Ensure the data file exists
12
+ if not os.path.exists(DATA_FILE):
13
+ with open(DATA_FILE, "w") as f:
14
+ json.dump([], f)
15
+
16
+ def load_data():
17
+ with open(DATA_FILE, "r") as f:
18
+ return json.load(f)
19
+
20
+ def save_data(data):
21
+ with open(DATA_FILE, "w") as f:
22
+ json.dump(data, f, indent=2)
23
+
24
+ # Define the request model
25
+ class CookiePayload(BaseModel):
26
+ data: Dict[str, Any]
27
+
28
+ @app.post("/save-cookies")
29
+ def save_cookies(payload: CookiePayload):
30
+ data = load_data()
31
+ data.append(payload.data)
32
+ save_data(data)
33
+ return {"status": "success", "message": "Cookies saved", "total": len(data)}
34
+
35
+ @app.get("/cookies")
36
+ def get_all_cookies():
37
+ return load_data()
cookies.json ADDED
File without changes
songs-1.json ADDED
The diff for this file is too large to render. See raw diff