Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # jsb/plugs/common/uidchecker.py
- #
- #
- """
- the rss mantra is of the following:
- 1) add a url with !rss-add <feedname> <url>
- 2) use !rss-start <feed> in the channel you want the feed to appear
- 3) run !rss-scan <feed> to see what tokens you can use .. add them with !rss-additem <feed> <token>
- 4) change markup with !rss-addmarkup <feed> <markupitem> <value> .. see !rss-markuplist for possible markups
- 5) check with !rss-feeds in a channel to see what feeds are running in a channel
- 6) in case of trouble check !rss-running to see what feeds are monitored
- 7) enjoy
- """
- ## jsb imports
- from jsb.lib.persist import Persist, PlugPersist
- from jsb.utils.exception import handle_exception
- from jsb.utils.lazydict import LazyDict
- from jsb.lib.commands import cmnds
- from jsb.lib.examples import examples
- from jsb.lib.tasks import taskmanager
- from jsb.lib.callbacks import callbacks
- from jsb.lib.threads import start_new_thread
- from jsb.lib.cache import get, set, delete
- import logging
- ## basic imports
- import re
- import requests
- lastpoll = PlugPersist('lastuid')
- if not lastpoll.data:
- lastpoll.data = LazyDict()
- lastpoll.data[0] = "stopped"
- lastpoll.save()
- name_re = re.compile(r"<title>Your Relationship with (.+) \(\d+\) </title>")
- LOGIN_URL = "http://soylentnews.org/my/login"
- ZOO_URL = "http://soylentnews.org/zoo.pl?op=check&uid="
- payload = {'returnto': '',
- 'op': 'userlogin',
- 'unickname': 'BenderBot',
- 'upasswd': '6NakHFKXBKgLBkWJ7',
- 'userlogin': 'Log+in',
- 'login_temp': 'yes'
- }
- def is_uid(uid, session):
- r = session.get(ZOO_URL+str(uid))
- if "<title>Sorry, you did not specify a valid user.</title>" in r.content:
- return False
- else:
- matches = name_re.search(r.content)
- if not matches:
- return False
- name = matches.group(1)
- return name
- def check_uid(dunno):
- session = requests.session()
- session.post(LOGIN_URL, data=payload)
- if "last" not in lastpoll.data:
- user = "error!!"
- uid = 2000
- else:
- (user, uid) = lastpoll.data["last"]
- tmp_user = "error!!"
- search_size = 1024
- while True:
- uid += search_size
- tmp_user = is_uid(uid, session)
- if not tmp_user:
- uid -= search_size
- if search_size == 1:
- break
- search_size = search_size/2
- else:
- user = tmp_user
- lastpoll.data["last"] = (user, uid)
- lastpoll.save()
- def doperiodical(*args, **kwargs):
- if 0 not in lastpoll.data:
- lastpoll.data[0] = "stopped"
- if not lastpoll.data[0] == "running":
- lastpoll.data[0] = "running"
- lastpoll.save()
- try: start_new_thread(check_uid, (None,))
- except Exception, ex: handle_exception()
- lastpoll.data[0] = "stopped"
- lastpoll.save()
- callbacks.add('TICK60', doperiodical)
- def current_uid(bot, ievent):
- (user, uid) = lastpoll.data["last"]
- ievent.reply("The current maximum UID is %d, owned by %s" % (uid, user))
- cmnds.add('current-uid', current_uid, ['GUEST', 'ANON', 'USER' ])
- examples.add('current-uid', 'Gets the current max UID on Soylent News', 'current-uid')
Advertisement
Add Comment
Please, Sign In to add comment