Created
December 9, 2021 20:58
-
-
Save CrimsonScythe/274d3a0e31d650cb53e15a08670edc15 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( | |
'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