Update app.py
Browse files
app.py
CHANGED
@@ -35,11 +35,11 @@ async def save_sms(request: SmsRequest):
|
|
35 |
# Create filename with timestamp
|
36 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
37 |
filename = f"{DATA_DIR}/backup_{timestamp}.json"
|
38 |
-
|
39 |
# Save to file
|
40 |
with open(filename, "w") as f:
|
41 |
json.dump([sms.dict() for sms in request.sms_list], f, indent=2)
|
42 |
-
|
43 |
return {
|
44 |
"status": "success",
|
45 |
"message": f"{len(request.sms_list)} SMS saved",
|
@@ -48,10 +48,29 @@ async def save_sms(request: SmsRequest):
|
|
48 |
except Exception as e:
|
49 |
raise HTTPException(status_code=500, detail=str(e))
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
@app.get("/")
|
52 |
async def health_check():
|
53 |
return {
|
54 |
"status": "healthy",
|
55 |
"timestamp": datetime.datetime.now().isoformat(),
|
56 |
"sms_storage": DATA_DIR
|
57 |
-
}
|
|
|
35 |
# Create filename with timestamp
|
36 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
37 |
filename = f"{DATA_DIR}/backup_{timestamp}.json"
|
38 |
+
|
39 |
# Save to file
|
40 |
with open(filename, "w") as f:
|
41 |
json.dump([sms.dict() for sms in request.sms_list], f, indent=2)
|
42 |
+
|
43 |
return {
|
44 |
"status": "success",
|
45 |
"message": f"{len(request.sms_list)} SMS saved",
|
|
|
48 |
except Exception as e:
|
49 |
raise HTTPException(status_code=500, detail=str(e))
|
50 |
|
51 |
+
@app.get("/get-sms")
|
52 |
+
async def get_sms():
|
53 |
+
try:
|
54 |
+
sms_list = []
|
55 |
+
files = sorted(os.listdir(DATA_DIR))
|
56 |
+
for file in files:
|
57 |
+
if file.endswith(".json"):
|
58 |
+
file_path = os.path.join(DATA_DIR, file)
|
59 |
+
with open(file_path, "r") as f:
|
60 |
+
data = json.load(f)
|
61 |
+
sms_list.extend(data)
|
62 |
+
return {
|
63 |
+
"status": "success",
|
64 |
+
"total_sms": len(sms_list),
|
65 |
+
"sms_list": sms_list
|
66 |
+
}
|
67 |
+
except Exception as e:
|
68 |
+
raise HTTPException(status_code=500, detail=str(e))
|
69 |
+
|
70 |
@app.get("/")
|
71 |
async def health_check():
|
72 |
return {
|
73 |
"status": "healthy",
|
74 |
"timestamp": datetime.datetime.now().isoformat(),
|
75 |
"sms_storage": DATA_DIR
|
76 |
+
}
|