File size: 831 Bytes
e857da4
 
 
99ce67b
e857da4
5116708
e857da4
 
 
e85a070
e857da4
 
 
 
 
eec495e
 
e857da4
79227de
e857da4
 
 
 
eec495e
 
 
e857da4
 
 
b9ffefc
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
31
from news_extractor import get_news
from db_operations import DBOperations
import json
from flask import Flask, Response
from flask_cors import cross_origin, CORS
import logging

app = Flask(__name__)
CORS(app)
logging.warning('Initiated')


@app.route("/")
@cross_origin()
def update_news():
    status_json = "{'status':'success'}"
    status_code = 200
    try:
        db = DBOperations()
        news_df = get_news()
        news_json = [*json.loads(news_df.reset_index(drop=True).to_json(orient="index")).values()]
        db.insert_news_into_db(news_json)
    except:
        status_json = "{'status':'failure'}"
        status_code = 500
    return Response(status_json, status=status_code, mimetype='application/json')


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