Last active
December 13, 2021 18:24
-
-
Save CrimsonScythe/d680b359d1308d41ec01d47ff37ffce8 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 celery import Celery | |
import requests | |
import pandas as pd | |
celery = Celery( | |
'celerynews', | |
backend='redis://localhost', | |
broker='pyamqp://guest@localhost//' | |
) | |
@celery.task() | |
def getNewsData(country): | |
res = requests.request("GET", "https://newsapi.org/v2/top-headlines", | |
params={"country":country, "apiKey":"<API_KEY>"}) | |
return res.json() | |
@celery.task() | |
def genReport(results): | |
dfs=[] | |
for result in results: | |
df=pd.DataFrame(result) | |
dfs.append(df) | |
df = pd.concat(dfs, axis=0) | |
df.index=list(range(df.shape[0])) | |
return df.to_json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment