Guest User

uidchecker.py

a guest
Aug 18th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.29 KB | None | 0 0
  1. # jsb/plugs/common/uidchecker.py
  2. #
  3. #
  4.  
  5. """
  6.    the rss mantra is of the following:
  7.  
  8.    1) add a url with !rss-add <feedname> <url>
  9.    2) use !rss-start <feed> in the channel you want the feed to appear
  10.    3) run !rss-scan <feed> to see what tokens you can use .. add them with !rss-additem <feed> <token>
  11.    4) change markup with !rss-addmarkup <feed> <markupitem> <value> .. see !rss-markuplist for possible markups
  12.    5) check with !rss-feeds in a channel to see what feeds are running in a channel
  13.    6) in case of trouble check !rss-running to see what feeds are monitored
  14.    7) enjoy
  15.  
  16. """
  17.  
  18. ## jsb imports
  19.  
  20. from jsb.lib.persist import Persist, PlugPersist
  21. from jsb.utils.exception import handle_exception
  22. from jsb.utils.lazydict import LazyDict
  23. from jsb.lib.commands import cmnds
  24. from jsb.lib.examples import examples
  25. from jsb.lib.tasks import taskmanager
  26. from jsb.lib.callbacks import callbacks
  27. from jsb.lib.threads import start_new_thread
  28.  
  29.  
  30. from jsb.lib.cache import get, set, delete
  31.  
  32. import logging
  33.  
  34. ## basic imports
  35.  
  36. import re
  37. import requests
  38.  
  39.  
  40.  
  41. lastpoll = PlugPersist('lastuid')
  42. if not lastpoll.data:
  43.     lastpoll.data = LazyDict()
  44.     lastpoll.data[0] = "stopped"
  45.     lastpoll.save()
  46.  
  47. name_re = re.compile(r"<title>Your Relationship with (.+) \(\d+\) </title>")
  48.  
  49. LOGIN_URL = "http://soylentnews.org/my/login"
  50. ZOO_URL = "http://soylentnews.org/zoo.pl?op=check&uid="
  51.  
  52. payload = {'returnto': '',
  53.             'op': 'userlogin',
  54.             'unickname': 'BenderBot',
  55.             'upasswd': '6NakHFKXBKgLBkWJ7',
  56.             'userlogin': 'Log+in',
  57.             'login_temp': 'yes'
  58.             }
  59.  
  60.  
  61. def is_uid(uid, session):
  62.     r = session.get(ZOO_URL+str(uid))
  63.     if "<title>Sorry, you did not specify a valid user.</title>" in r.content:
  64.         return False
  65.     else:
  66.         matches = name_re.search(r.content)
  67.         if not matches:
  68.             return False
  69.         name = matches.group(1)
  70.         return name
  71.  
  72.  
  73. def check_uid(dunno):
  74.     session = requests.session()
  75.     session.post(LOGIN_URL, data=payload)
  76.  
  77.     if "last" not in lastpoll.data:
  78.         user = "error!!"
  79.         uid = 2000
  80.     else:
  81.         (user, uid) = lastpoll.data["last"]
  82.  
  83.     tmp_user = "error!!"
  84.  
  85.     search_size = 1024
  86.     while True:
  87.         uid += search_size
  88.         tmp_user = is_uid(uid, session)
  89.         if not tmp_user:
  90.             uid -= search_size
  91.             if search_size == 1:
  92.                 break
  93.             search_size = search_size/2
  94.         else:
  95.             user = tmp_user
  96.  
  97.     lastpoll.data["last"] = (user, uid)
  98.     lastpoll.save()
  99.  
  100. def doperiodical(*args, **kwargs):
  101.     if 0 not in lastpoll.data:
  102.         lastpoll.data[0] = "stopped"
  103.     if not lastpoll.data[0] == "running":
  104.         lastpoll.data[0] = "running"
  105.         lastpoll.save()
  106.         try: start_new_thread(check_uid, (None,))
  107.         except Exception, ex: handle_exception()
  108.         lastpoll.data[0] = "stopped"
  109.         lastpoll.save()
  110.  
  111. callbacks.add('TICK60', doperiodical)
  112.  
  113. def current_uid(bot, ievent):
  114.     (user, uid) = lastpoll.data["last"]
  115.     ievent.reply("The current maximum UID is %d, owned by %s" % (uid, user))
  116.  
  117. cmnds.add('current-uid', current_uid, ['GUEST', 'ANON', 'USER' ])
  118. examples.add('current-uid', 'Gets the current max UID on Soylent News', 'current-uid')
Advertisement
Add Comment
Please, Sign In to add comment