Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import praw
  2. import json
  3. import time
  4. from datetime import datetime
  5.  
  6. users = set()
  7.  
  8. bot = praw.Reddit(user_agent='',
  9. client_id='Iq6Y7YogHPtmbA',
  10. client_secret='',
  11. username='',
  12. password='')
  13. cnt = 0
  14. for submission in bot.subreddit('portugal').new(limit=None):
  15. if submission.author and not submission.author.name in users:
  16. users.add(submission.author.name)
  17. subs = set()
  18. for post in submission.author.submissions.new(limit=3):
  19. name = post.subreddit.display_name
  20. if name not in subs:
  21. print(submission.author.name + ">> " + str(post.created_utc) +
  22. " | " + name + " > " + post.title)
  23. subs.add(name)
  24. tosave = {
  25. "id": post.id,
  26. "author": submission.author.name,
  27. "score": post.score,
  28. "title": post.title,
  29. "name": name,
  30. "utc": str(datetime.utcfromtimestamp(post.created_utc)),
  31. "time": time.strftime("%Y%m%d-%H%M%S-%Z", time.localtime(post.created_utc))
  32. }
  33. with open(
  34. time.strftime("%Y%m%d-%H%M%S-%Z", time.localtime(post.created_utc)) + "-" +
  35. submission.author.name + ".crawl", 'w') as outfile:
  36. json.dump(tosave, outfile)
  37. outfile.write("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement