示例#1
0
文件: less.py 项目: Petraea/jsonbot
 def add(self, channel, listoftxt):
     """ add listoftxt to channel's output. """
     channel = unicode(channel).lower()
     data = get("outcache-" + channel)
     if not data: data = []
     data.extend(listoftxt)
     set(u"outcache-" + channel, data, 3600)
示例#2
0
文件: less.py 项目: NURDspace/jsonbot
 def add(self, channel, listoftxt):
     """ add listoftxt to channel's output. """
     channel = unicode(channel).lower()
     data = get("outcache-" + channel)
     if not data: data = []
     data.extend(listoftxt)
     set(u"outcache-" + channel, data, 3600)
示例#3
0
文件: less.py 项目: NURDspace/jsonbot
 def get(self, channel):
     """ return 1 item popped from outcache. """
     channel = unicode(channel).lower()
     global get
     data = get(u"outcache-" + channel)
     if not data: txt = None
     else: 
         try: txt = data.pop(0) ; set(u"outcache-" + channel, data, 3600)
         except (KeyError, IndexError): txt = None
     if data: size = len(data)
     else: size = 0
     return (txt, size)
示例#4
0
文件: less.py 项目: Petraea/jsonbot
 def get(self, channel):
     """ return 1 item popped from outcache. """
     channel = unicode(channel).lower()
     global get
     data = get(u"outcache-" + channel)
     if not data: txt = None
     else:
         try:
             txt = data.pop(0)
             set(u"outcache-" + channel, data, 3600)
         except (KeyError, IndexError):
             txt = None
     if data: size = len(data)
     else: size = 0
     return (txt, size)
示例#5
0
def get_tinyurl(url):
    """ grab a tinyurl. """
    res = get(url, namespace='tinyurl')
    logging.debug('tinyurl - cache - %s' % unicode(res))
    if res and res[0] == '[': return json.loads(res)
    postarray = [
        ('submit', 'submit'),
        ('url', url),
    ]
    postdata = urllib.urlencode(postarray)
    req = urllib2.Request(url=plugcfg.url, data=postdata)
    req.add_header('User-agent', useragent())
    try:
        res = urllib2.urlopen(req).readlines()
    except urllib2.URLError, e:
        logging.warn('tinyurl - %s - URLError: %s' % (url, str(e)))
        return
示例#6
0
def get_tinyurl(url):
    """ grab a tinyurl. """
    res = get(url, namespace='tinyurl') ; logging.debug('tinyurl - cache - %s' % unicode(res))
    if res and res[0] == '[': return json.loads(res)
    postarray = [
        ('submit', 'submit'),
        ('url', url),
        ]
    postdata = urllib.urlencode(postarray)
    req = urllib2.Request(url=plugcfg.url, data=postdata)
    req.add_header('User-agent', useragent())
    try: res = urllib2.urlopen(req).readlines()
    except urllib2.URLError, e: logging.warn('tinyurl - %s - URLError: %s' % (url, str(e))) ; return
    except urllib2.HTTPError, e: logging.warn('tinyurl - %s - HTTP error: %s' % (url, str(e))) ; return
    except Exception, ex:
        if "DownloadError" in str(ex): logging.warn('tinyurl - %s - DownloadError: %s' % (url, str(e)))
        else: handle_exception()
        return
示例#7
0
文件: less.py 项目: Petraea/jsonbot
 def copy(self, channel):
     """ return 1 item popped from outcache. """
     channel = unicode(channel).lower()
     global get
     return get(u"outcache-" + channel)
示例#8
0
文件: less.py 项目: NURDspace/jsonbot
 def copy(self, channel):
     """ return 1 item popped from outcache. """
     channel = unicode(channel).lower()
     global get
     return get(u"outcache-" + channel)