Skip to content

Instantly share code, notes, and snippets.

@CrimsonScythe
Last active December 13, 2021 18:24
Show Gist options
  • Save CrimsonScythe/d680b359d1308d41ec01d47ff37ffce8 to your computer and use it in GitHub Desktop.
Save CrimsonScythe/d680b359d1308d41ec01d47ff37ffce8 to your computer and use it in GitHub Desktop.
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