Пример #1
0
 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
 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
 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
 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 set(self, channel, listoftxt):
     """ set listoftxt to channel's output. """
     channel = unicode(channel).lower()
     set(u"outcache-" + channel, listoftxt, 3600)
Пример #6
0
 def set(self, channel, listoftxt):
     """ set listoftxt to channel's output. """
     channel = unicode(channel).lower()
     set(u"outcache-" + channel, listoftxt, 3600)
Пример #7
0
        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
    urls = []
    for line in res:
        if line.startswith('<blockquote><b>'):
            urls.append(striphtml(line.strip()).split('[Open')[0])
    if len(urls) == 3: urls.pop(0)
    set(url, json.dumps(urls), namespace='tinyurl')
    return urls


## tinyurl command


def handle_tinyurl(bot, ievent):
    """ arguments: <url> - get tinyurl from provided url. """
    if not ievent.rest and (not urlcache.has_key(bot.cfg.name) or
                            not urlcache[bot.cfg.name].has_key(ievent.target)):
        ievent.missing('<url>')
        return
    elif not ievent.rest:
        url = urlcache[bot.cfg.name][ievent.target]
    else:
Пример #8
0
        ]
    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
    urls = []
    for line in res:
        if line.startswith('<blockquote><b>'): urls.append(striphtml(line.strip()).split('[Open')[0])
    if len(urls) == 3: urls.pop(0)
    set(url, json.dumps(urls), namespace='tinyurl')
    return urls

## tinyurl command

def handle_tinyurl(bot, ievent):
    """ arguments: <url> - get tinyurl from provided url. """
    if not ievent.rest and (not urlcache.has_key(bot.cfg.name) or not urlcache[bot.cfg.name].has_key(ievent.target)):
        ievent.missing('<url>')
        return
    elif not ievent.rest: url = urlcache[bot.cfg.name][ievent.target]
    else: url = ievent.rest
    url = valid_url(url)
    if not url: ievent.reply('invalid or bad URL') ; return
    tinyurl = get_tinyurl(url)
    if tinyurl: ievent.reply(' .. '.join(tinyurl))