Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import praw
  2. import time
  3.  
  4. import spacy
  5. import ipdb
  6. nlp = spacy.load('en')
  7. reddit = praw.Reddit(client_id='',
  8. client_secret='_iQ',
  9. password='',
  10. user_agent='testscript by /u/fakebot3',
  11. username='')
  12.  
  13. lines = [line.rstrip('\n') for line in open('out.txt')]
  14.  
  15. for line in lines:
  16. if line.startswith('TS CHANGE'):
  17. continue
  18. while True:
  19. try:
  20. submission = reddit.submission(line)
  21.  
  22. break
  23. except:
  24. pass
  25.  
  26. submission.comments.replace_more(limit=0)
  27. countries = {}
  28. for comment in submission.comments.list():
  29. doc = nlp(comment.body)
  30. for ent in doc.ents:
  31. if ent.label_ == 'GPE':
  32. if ent.text not in countries:
  33. countries[ent.text] = 1
  34. else:
  35. countries[ent.text] += 1
  36. avg = 0
  37. avg_count = 0
  38. for k,v in countries.items():
  39. if v != 1:
  40. avg += v
  41. avg_count += 1
  42. avg = avg/avg_count/2
  43.  
  44.  
  45. print(submission.title)
  46. print(sorted( ((v,k) for k,v in countries.items() if v > avg), reverse=True))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement