Advertisement
talichan

Untitled

Jan 7th, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1.  
  2.  
  3. # -*- coding: utf-8 -*-
  4.  
  5. import requests
  6. from willie.module import commands, interval
  7.  
  8. archives = requests.get('https://raw.githubusercontent.com/MayhemYDG/archives.json/master/archives.json').json()
  9. last_post = {}
  10. search_query = '?text=removethis|removethis|removethis'
  11. # change text to whatever you are searching for, filename is filename, image hash is simply image - change 'removethis' for desires search queries
  12. channel = '#removethis'
  13. # remove for desired channel input
  14. for archive in archives:
  15. if archive['software'] != 'foolfuuka':
  16. continue
  17. for board in archive['boards']:
  18. last_post[board] = 0
  19.  
  20. start = False
  21.  
  22.  
  23. @interval(60)
  24. def check(bot):
  25. global last_post, start
  26.  
  27. for archive in archives:
  28. if archive['software'] != 'foolfuuka':
  29. continue
  30. proto = 'https' if archive['https'] else 'http'
  31. print 'checking %s' % archive['domain']
  32. try:
  33. resp = requests.get('%s://%s/_/api/chan/search/%s' % (proto, archive['domain'], search_query))
  34. except:
  35. resp = requests.get('http://%s/_/api/chan/search/%s' % (archive['domain'], search_query))
  36.  
  37. for board in archive['boards']:
  38. for post in reversed(resp.json()[0]['posts']):
  39. if 'board' not in post: # stupid archives
  40. continue
  41. if post['board']['shortname'] != board:
  42. continue
  43.  
  44. if int(post['num']) > last_post[board]:
  45. last_post[board] = int(post['num'])
  46. if start:
  47. bot.msg(channel, '%s: %s %s://%s/%s/thread/%s#%s' %
  48. (post['name'], post['comment'][:200], proto, archive['domain'], board, post['thread_num'], post['num']))
  49.  
  50. start = True
  51. print last_post
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement