-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
30 lines (21 loc) · 709 Bytes
/
main.py
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
from fastapi import FastAPI
from dotenv import dotenv_values
from pymongo import MongoClient
from routes import router as data_router
config = dotenv_values(".env")
app = FastAPI()
@app.on_event("startup")
def startup_db_client():
app.mongodb_client = MongoClient(config["ATLAS_URI"])
app.database = app.mongodb_client[config["DB_NAME"]]
print("Connected to the MongoDB database!")
@app.on_event("shutdown")
def shutdown_db_client():
app.mongodb_client.close()
app.include_router(data_router, tags=["data"], prefix="/data")
from run import scrapData
import json
# @app.get("/getNews")
# async def get_News():
# resList = scrapData()
# return {"newsData": json.dumps(resList)}