Skip to content

Instantly share code, notes, and snippets.

@jftuga
Created June 25, 2021 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jftuga/262782df2ce3ed062a7f0724e1f7d0aa to your computer and use it in GitHub Desktop.
Save jftuga/262782df2ce3ed062a7f0724e1f7d0aa to your computer and use it in GitHub Desktop.
reddit asyncpraw example
import asyncio
import asyncpraw
import sys
class AsPr:
def __init__(self, sr: str):
self.sr = sr # subreddit
self.reddit = asyncpraw.Reddit(client_id=reddit_client_id, client_secret=reddit_client_secret,
user_agent=user_agent)
async def close(self):
await self.reddit.close()
async def stream(self):
self.subreddit = await self.reddit.subreddit(self.sr)
async for submission in self.subreddit.hot(limit=5):
print(submission.title)
###
async def main():
aspr = AsPr("nfl")
await aspr.stream()
await aspr.close()
if "__main__" == __name__:
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(main())
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment