Skip to content

Instantly share code, notes, and snippets.

@CrimsonScythe
Created December 9, 2021 20:58
Show Gist options
  • Save CrimsonScythe/274d3a0e31d650cb53e15a08670edc15 to your computer and use it in GitHub Desktop.
Save CrimsonScythe/274d3a0e31d650cb53e15a08670edc15 to your computer and use it in GitHub Desktop.
from celery import Celery
import requests
import pandas as pd
celery = Celery(
'calc',
backend='redis://localhost',
broker='pyamqp://guest@localhost//'
)
@celery.task()
def getTwitterUser(topic, headers):
res = requests.get(f"https://oauth.reddit.com/r/{topic}/hot", headers=headers)
return res.json()
@celery.task()
def genReport(results):
dfs=[]
for result in results:
for post in result['data']['children']:
df=pd.DataFrame([{"title":post['data']['title'], "author":post['data']['author_fullname']}])
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