Ejemplo n.º 1
0
 def defined(self):
     s = []
     dumpstr = self.tojson()
     for key, optionvalue in sorted(getjson().loads(dumpstr).items()):
         if key in self.hide: continue
         s.append(key)
     return s
Ejemplo n.º 2
0
 def save(self, attributes=[]):
     target = {}
     if attributes:
         for key in attributes: target[key] = self[key]
     else: target = cpy(self)
     targetfile = getdatadir() + os.sep + "containers" + os.sep + str(self.createtime) + "_" + stripname(self.origin)
     p = Persist(targetfile)
     p.data = getjson().dumps(target)
     p.save()
Ejemplo n.º 3
0
 def show_cfg(self, bot, ievent):
     """ show config options. """
     s = []
     dumpstr = self.tojson()
     logging.warn(dumpstr)
     for key, optionvalue in sorted(getjson().loads(dumpstr).items()):
         if key in self.hide: continue
         v = optionvalue
         if type(v) in [str, str]: v = '"'+v+'"'
         v = str(v)
         s.append("%s=%s" % (key, v))
     ievent.reply("options: " + ' .. '.join(s))
Ejemplo n.º 4
0
def handle_imdb(bot, event):
    """ arguments: <query> - query the imdb databae at http://www.deanclatworthy.com/imdb/ """
    if not event.rest:  event.missing("<query>") ; return
    query = event.rest.strip()
    urlquery = query.replace(" ", "+")
    result = {}
    res = geturl2(URL % urlquery)
    if not res: event.reply("%s didn't return a result" % (URL % urlquery)) ; return
    try: rawresult = getjson().loads(res)
    except ValueError: event.reply("sorry cannot parse data returned from the server: %s" % res) ; return
    # the API are limited to 30 query per hour, so avoid querying it just for testing purposes
    # rawresult = {u'ukscreens': 0, u'rating': u'7.7', u'genres': u'Animation,&nbsp;Drama,Family,Fantasy,Music', u'title': u'Pinocchio', u'series': 0, u'country': u'USA', u'votes': u'23209', u'languages': u'English', u'stv': 0, u'year': None, u'usascreens': 0, u'imdburl': u'http://www.imdb.com/title/tt0032910/'}
    if not rawresult: event.reply("couldn't look up %s" % query) ; return
    if 'error' in rawresult: event.reply("%s" % rawresult['error']) ; return
    for key in list(rawresult.keys()):
        if not rawresult[key]: result[key] = "n/a"
        else: result[key] = rawresult[key]
    for key in list(result.keys()):
        try: result[key] = striphtml(decode_html_entities(str(rawresult[key])))
        except AttributeError: pass
    if "year" in list(rawresult.keys()): event.reply("%(title)s (%(country)s, %(year)s): %(imdburl)s | rating: %(rating)s (out of %(votes)s votes) | Genres %(genres)s | Language: %(languages)s" % result )
    else: event.reply("%(title)s (%(country)s): %(imdburl)s | rating: %(rating)s (out of %(votes)s votes) | Genres %(genres)s | Language: %(languages)s" % result )
Ejemplo n.º 5
0
from tl.utils.generic import splittxt
from tl.utils.timeutils import today
from tl.lib.persistconfig import PersistConfig
from tl.lib.persiststate import PlugState
from tl.lib.tlimport import import_byfile
from tl.lib.datadir import getdatadir
from tl.lib.callbacks import callbacks
from tl.lib.commands import cmnds
from tl.lib.examples import examples
from tl.lib.fleet import getfleet
from tl.utils.help import ibytes, istr
from tl.lib.periodical import minutely, periodical
from tl.lib.errors import URLNotEnabled
from tl.imports import getjson

json = getjson()

## basic imports

import os
import logging
import uuid
import time
import io
import gzip
import urllib.request, urllib.parse, urllib.error

## defines

cfg = PersistConfig()
cfg.define("enable", 0)
Ejemplo n.º 6
0
def querygeoipserver(ip):
    try: ipinfo = getjson().loads(geturl2(URL % ip))
    except ValueError: ipinfo = None
    return ipinfo