File size: 629 Bytes
e857da4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fbf4577
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
from news_extractor import get_news
from db_operations import DBOperations
import json
from flask import Flask
from flask_cors import cross_origin, CORS

app = Flask(__name__)
CORS(app)


@app.route("/")
@cross_origin()
def update_news():
    status = "success"
    try:
        news_df = get_news()
        news_json = [*json.loads(news_df.reset_index(drop=True).to_json(orient="index")).values()]
        db = DBOperations()
        db.insert_news_into_db(news_json)
    except:
        status = "failure"
    return status


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860, timeout=120, workers=3, threads=3)