示例#1
0
 def fetch(self, obj):
     nr = 0
     for o in get_feed(obj.rss):
         if o.link in objs.seen.list: continue
         objs.seen.list.append(o.link)
         o.prefix = "feeds"
         o.services = "rss"
         if "published" in o:
             try: date = file_time(to_time(o.published)) ; o.save(date)
             except ENODATE as ex: logging.warn("EDATE %s" % str(ex))
         else: o.save()
         for bot in fleet: bot.announce(self.display(o))
         nr += 1
     return nr 
示例#2
0
def begin(event):
    """ begin stopwatch. """
    global start
    start = to_time(now())
    if start: event.reply("time is %s" % time.ctime(start))
示例#3
0
#
#
""" show statistics on suicide. """

from meds.utils.tijd import elapsed, to_time, today
from meds.object import Object
from meds.event import Event

from meds.core import storage, cfgs

import random
import time

#startdate = "2013-01-01 00:00:00"
startdate = "2016-01-01 00:00:00"
starttime = to_time(startdate)
source = "http://pypi.python.org/pypi/meds"


def seconds(nr, period="jaar"):
    if not nr: return nr
    return nrsec.get(period) / float(nr)


def nr(name):
    delta = time.time() - starttime
    awake = time.time() - today()
    for key, obj in wanted.items():
        for n, val in obj.items():
            if n == name: return val
    return 0
示例#4
0
def timed(obj):
    t = to_date(dated(obj))
    if t: t = to_time(t)
    if not t and "_path" in obj: t = fn_time(obj._path)
    if not t: t = fn_time(rtime())
    return t
示例#5
0
 def parse(self, txt=""):
     """ parse provided text or available self.txt and determine cmnd, args, rest and other values. Adds a _parsed object to the event. """
     from meds.core import aliases, cmnds, cfg, names
     if txt: self.txt = txt.rstrip()
     if self.txt.endswith("&"): self.threaded = True ; self.txt = self.txt[:-1]
     splitted = self.txt.split()
     quoted = False
     key2 = ""
     counter = -1
     parsed = Parsed()
     for word in splitted:
         counter += 1
         if counter == 0:
             if "cc" in self and self.cc:
                 if self.cc != word[0]: continue
                 else: word = word[1:]
             alias = aliases.get(word, None)
             if alias: word = alias
             cmnd = word.lower().strip()
             if cmnd:
                 parsed.cmnd = cmnd
                 funcs = cmnds.get(cmnd, None)
                 if not funcs:
                     modnames = names.get(cmnd, [])
                     for modname in modnames:
                         self.load(modname)
             if funcs:
                 self._funcs.extend(funcs)
                 self._funcs = list(set(self._funcs))
             continue
         try: key, value = word.split("=", 1) 
         except (IndexError,ValueError):
             key = ""
             value = word 
         if value.startswith('"'):
             if value.endswith('"'):
                 value = value[1:-1]
                 parsed.words.append(value)
             else:
                 key2 = key
                 value = value[1:]
                 parsed.words.append(value)
                 quoted = True
                 continue
         if quoted:
             if value.endswith('"'):
                 key = key2
                 parsed.words.append(value[:-1])
                 value = sj(*parsed.words)
                 self._parsed.words = []
                 quoted = False
             else:
                 parsed.words.append(value)
                 continue
         if quoted:
             parsed.words.append(value)
             continue
         if counter == 1:
             if word.count("[") == 1:
                 value, index = word.split("[")
                 try: parsed.index = int(index[:-1])
                 except ValueError: pass
             if not self.prefix:
                 if key and os.path.isdir(j(cfg.workdir, key)):
                     self.prefix = key
                 elif os.path.isdir(j(cfg.workdir, value)):
                     self.prefix = value
         if "http" in value:
             parsed.args.append(value)
             parsed.rest += " " + value
             continue
         if key=="index":
             parsed.index = int(value)
             continue
         if key == "start":
             parsed.start = to_time(value)
             continue 
         if key == "end":
             parsed.end = to_time(value)
             continue 
         if value.startswith("+") or value.startswith("-"):
             try: parsed.time_diff = int(value[1:])
             except ValueError: parsed.time_diff = 0
         if value.endswith("++") or value.endswith("--"):
             try: parsed.karma = value[:-2]
             except ValueError: pass
         if key and value:
             pre = key[0]
             op = key[-1]
             post = value[0]
             last = value[-1]
             if key.startswith("!"):
                  key = key[1:]
                  parsed.switch[key] = value
                  continue
             if post == "-":
                  value = value[1:]
                  parsed.ignore.register(key, value)
                  continue
             if op == "-":
                  key = key[:-1]
                  parsed.notwant[key] = value
                  continue
             if last == "-":
                 value = value[:-1]
             parsed.want[key] = value 
             if last == "-" :
                  continue
             if counter > 1: parsed.fields.append(key)
             parsed.args.append(key)
             parsed.rest += " " + key
         else:
             if counter > 1: parsed.fields.append(value)
             parsed.args.append(value)
             parsed.rest += " " + str(value)
     self._parsed.update(parsed)
     self._parsed.rest = self._parsed.rest.strip()
     return parsed