Last active
December 13, 2021 18:54
-
-
Save CrimsonScythe/4c1f2817d77de5222335b4aa99daa21a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request | |
from celerynews import getNewsData, genReport | |
from celery import chord | |
from default_settings import * | |
import requests | |
app = Flask(__name__) | |
@app.route('/api/send', methods=['GET', 'POST']) | |
def send(): | |
countries = request.get_json()["countries"] | |
''' Fast version ''' | |
tasks = [getNewsData.s(country) for country in countries] | |
res = chord(tasks)(genReport.s()) | |
df = res.get() | |
'''Slow version''' | |
# reslst=[] | |
# for ye in countries: | |
# res = requests.request("GET", "https://newsapi.org/v2/top-headlines", | |
# params={"country":ye, "apiKey":"<API_KEY>"}) | |
# reslst.append(res.json()) | |
# df = genReport.delay(reslst).get() | |
return df | |
if __name__ == '__main__': | |
app.run(debug=True, host='0.0.0.0', port=5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment