• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python timesince.timesince函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中util.timesince.timesince函数的典型用法代码示例。如果您正苦于以下问题:Python timesince函数的具体用法?Python timesince怎么用?Python timesince使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了timesince函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: seen

def seen(inp, nick='', chan='', db=None, input=None):
    ".seen <nick> -- Tell when a nickname was last in active in irc"

    if input.conn.nick.lower() == inp.lower():
        # user is looking for us, being a smartass
        return "You need to get your eyes checked."

    if inp.lower() == nick.lower():
        return "Have you looked in a mirror lately?"

    db_init(db)

    last_seen = db.execute("select name, time, quote from seen where name"
                           " like ? and chan = ?", (inp, chan)).fetchone()

    if last_seen:
        reltime = timesince.timesince(last_seen[1])
        if last_seen[0] != inp.lower():  # for glob matching
            inp = last_seen[0]
        return '%s was last seen %s ago saying: %s' % \
                    (inp, reltime, last_seen[2])
    else:
        from random import random
        seen_time = int(31557600 * random()) # 1 year ago
        reltime = timesince.timesince(int(time.time() - seen_time))
        return '%s was last seen %s ago saying: %s' % \
                    (inp, reltime, 'Volte is always wrong')
开发者ID:Hamled,项目名称:skybot,代码行数:27,代码来源:seen.py


示例2: seen

def seen(inp, nick='', chan='', db=None, input=None):
    "seen <nick> -- Tell when a nickname was last on active in irc"

    if input.conn.nick == inp:
        return "You need to get your eyes checked."
    inp = inp.split(" ")[0]
    db_init(db)
    last_seen = db.execute("select name, time, quote, chan, event from seen where name like (?) order by time desc", (inp.replace("*","%"),)).fetchone()

    if last_seen:
        reltime = timesince.timesince(last_seen[1])
        if last_seen[0] != inp.lower():  # for glob matching
            inp = last_seen[0]
        if last_seen[4] == "privmsg":
            if last_seen[2][0:1]=="\x01":
                return '%s was last seen %s ago in %s: *%s %s*' % (last_seen[0], reltime, last_seen[3], inp, last_seen[2][8:-1])
            else:
                return '%s was last seen %s ago in %s saying: %s' % (last_seen[0], reltime, last_seen[3], last_seen[2])
        if last_seen[4] == "join":
            return '%s was last seen %s ago joining %s' % (last_seen[0], reltime, last_seen[3])
        if last_seen[4] == "part":
            return '%s was last seen %s ago parting %s' % (last_seen[0], reltime, last_seen[3])
        if last_seen[4] == "quit":
            return '%s was last seen %s ago quitting (%s)' % (last_seen[0], reltime, last_seen[2])
        if last_seen[4] == "kick":
            return '%s was last seen %s ago getting kicked from %s' % (last_seen[0], reltime, last_seen[3])
    else:
        return "I've never seen %s" % inp
开发者ID:gbyers,项目名称:skybot,代码行数:28,代码来源:seen.py


示例3: seen

def seen(inp, nick='', chan='', db=None, input=None, bot=None):
    "seen <nick> -- Tell when a nickname was last in active in one of this bot's channels."

    if input.conn.nick.lower() == inp.lower():
        return "You need to get your eyes checked."

    if inp.lower() == nick.lower():
        return "Have you looked in a mirror lately?"

    #if not re.match("^[A-Za-z0-9_|.\-\]\[]*$", inp.lower()):
    #    return "I can't look up that name, its impossible to use!"

    if not db_ready: db_init(db, bot)

    last_seen = db.execute("select name, time, quote from seen where name like ? and chan = ?", (inp, chan)).fetchone()

    if last_seen:
        reltime = timesince.timesince(last_seen[1])
        if last_seen[0] != inp.lower():  # for glob matching
            inp = last_seen[0]
        if last_seen[2][0:1] == "\x01":
            print 'notelse'
            return u'{} was last seen {} ago: * {} {}'.format(inp, reltime, inp,
                                                             last_seen[2][8:-1]).encode('utf-8')
        else:
            return u'{} was last seen {} ago saying: {}'.format(inp, reltime, last_seen[2]).encode('utf-8')
    else:
        return "I've never seen {} talking in this channel.".format(inp)
开发者ID:inexist3nce,项目名称:Taigabot,代码行数:28,代码来源:seen.py


示例4: seen

def seen(inp, say='', nick='', db=None, input=None):
    """.seen <nick> - Tell when a nickname was last in active in IRC."""
    if input.conn.nick.lower() == inp.lower():
        return "You need to get your eyes checked."
    if inp.lower() == nick.lower():
        return "Have you looked in a mirror lately?"

    rows = db.execute("select chan, nick, action, msg, uts from seen where server = lower(?) and chan in (lower(?), 'quit', 'nick') and (nick = lower(?) or (action = 'KICK' and msg = ?)) order by uts desc limit 1",
        (input.server, input.chan, inp, inp.lower() + "%")).fetchone()

    if rows:
        row = dict(zip(['chan', 'nick', 'action', 'msg', 'uts'], rows))
        reltime = timesince.timesince(row['uts'])
        if row['action'] == 'KICK':
            row['who'] = row['msg'].split(' ')[:1][0]
            row['msg'] = ' '.join(row['msg'].split(' ')[1:]).strip('[]')
            if inp.lower() != row['who'].lower():
                row['action'] = 'KICKEE'

        format = formats.get(row['action'])

        out = '{} was last seen {} ago '.format(inp, reltime)
        say(out + format % row)
    else:
        return "I've never seen %s" % inp
开发者ID:Cameri,项目名称:Gary,代码行数:25,代码来源:seen.py


示例5: format_reply

def format_reply(history):
    if not history:
        return

    last_nick, recent_time = history[0]
    last_time = timesince.timesince(recent_time)
    current_time = time.time()

    if (current_time - recent_time < minimum_time_lag):
        return

    if len(history) == 1:
        return "%s linked that %s ago. Pay attention, dumbass." % (last_nick, last_time)

    hour_span = math.ceil((time.time() - history[-1][1]) / 3600)
    hour_span = '%.0f hours' % hour_span if hour_span > 1 else 'hour'

    hlen = len(history)
    ordinal = ["once", "twice", "%d times" % hlen][min(hlen, 3) - 1]

    if len(dict(history)) == 1:
        last = "last linked %s ago" % last_time
    else:
        last = "last linked by %s %s ago" % (last_nick, last_time)

    return "that url has been posted %s in the past %s by %s (%s)." % (ordinal,
            hour_span, nicklist(history), last)
开发者ID:bendavis78,项目名称:ircbot,代码行数:27,代码来源:urlhistory.py


示例6: seen

def seen(inp, nick='', chan='', db=None, input=None, conn=None, notice=None):
    "seen <nick> -- Tell when a nickname was last in active in one of this bot's channels."

    if input.conn.nick.lower() == inp.lower():
        phrase = datafiles.get_phrase(nick,insults,nick,conn,notice,chan)
        return phrase

    if inp.lower() == nick.lower():
        return phrase

    #if not re.match("^[A-Za-z0-9_|.\-\]\[]*$", inp.lower()):
    #    return "I can't look up that name, its impossible to use!"

    if not db_ready: db_init(db)

    last_seen = db.execute("select name, time, quote from seen where name like ? and chan = ?", (inp, chan)).fetchone()

    if last_seen:
        reltime = timesince.timesince(last_seen[1])
        if last_seen[0] != inp.lower():  # for glob matching
            inp = last_seen[0]
        if last_seen[2][0:1] == "\x01":
            return '{} was last seen {} ago: * {} {}'.format(inp, reltime, inp,
                                                             last_seen[2][8:-1])
        else:
            return '{} was last seen {} ago saying: {}'.format(inp, reltime, last_seen[2])
    else:
        return "I've never seen {} talking in this channel.".format(inp)
开发者ID:lity99,项目名称:uguubot,代码行数:28,代码来源:seen.py


示例7: seen

def seen(inp, nick="", chan="", db=None, input=None):
    ".seen <nick> -- Tell when a nickname was last in active in one of this bot's channels."

    if input.conn.nick.lower() == inp.lower():
        # user is looking for us, being a smartass
        return "You need to get your eyes checked."

    if inp.lower() == nick.lower():
        return "Have you looked in a mirror lately?"

    if not re.match("^[A-Za-z0-9_|.-\]\[]*$", inp.lower()):
        return "I cant look up that name, its impossible to use!"

    db_init(db)

    last_seen = db.execute(
        "select name, time, quote from seen where name" " like ? and chan = ?", (inp, chan)
    ).fetchone()

    if last_seen:
        reltime = timesince.timesince(last_seen[1])
        if last_seen[0] != inp.lower():  # for glob matching
            inp = last_seen[0]
        return "%s was last seen %s ago saying: %s" % (inp, reltime, last_seen[2])
    else:
        return "I've never seen %s" % inp
开发者ID:frozenMC,项目名称:CloudBot,代码行数:26,代码来源:seen.py


示例8: pre

def pre(inp):
    """pre <query> -- searches scene releases using orlydb.com"""

    try:
        h = http.get_html("http://orlydb.com/", q=inp)
    except http.HTTPError as e:
        return 'Unable to fetch results: {}'.format(e)

    results = h.xpath("//div[@id='releases']/div/span[@class='release']/..")

    if not results:
        return "No results found."

    result = results[0]

    date = result.xpath("span[@class='timestamp']/text()")[0]
    section = result.xpath("span[@class='section']//text()")[0]
    name = result.xpath("span[@class='release']/text()")[0]

    # parse date/time
    date = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
    date_string = date.strftime("%d %b %Y")
    since = timesince.timesince(date)

    size = result.xpath("span[@class='inforight']//text()")
    if size:
        size = ' - ' + size[0].split()[0]
    else:
        size = ''

    return '{} - {}{} - {} ({} ago)'.format(section, name, size, date_string, since)
开发者ID:FurCode,项目名称:RoboCop2,代码行数:31,代码来源:scene.py


示例9: showuptime

def showuptime(inp):
    "uptime -- shows how long I have been connected for"
    f = open("uptime","r")
    uptime = f.read()
    f.close()
    uptime = timesince.timesince(float(uptime))
    return "I have been online for %s"%uptime
开发者ID:gbyers,项目名称:skybot,代码行数:7,代码来源:misc.py


示例10: seen

def seen(inp, nick='', chan='', db=None, input=None):
    ".seen <nick> -- Tell when a nickname was last in active in irc"

    inp = inp.lower()

    if input.conn.nick.lower() == inp:
        # user is looking for us, being a smartass
        return "You need to get your eyes checked."

    if inp == nick.lower():
        return "Have you looked in a mirror lately?"

    db_init(db)

    last_seen = db.execute("select name, time, quote from seen where"
                           " name = ? and chan = ?", (inp, chan)).fetchone()

    if last_seen:
        reltime = timesince.timesince(last_seen[1])
        if last_seen[0] != inp.lower():  # for glob matching
            inp = last_seen[0]
        if last_seen[2][0:1] == "\x01":
            return '%s was last seen %s ago: *%s %s*' % \
                (inp, reltime, inp, last_seen[2][8:-1])
        else:
            return '%s was last seen %s ago saying: %s' % \
                (inp, reltime, last_seen[2])
    else:
        return "I've never seen %s" % inp
开发者ID:adamcheasley,项目名称:skybot,代码行数:29,代码来源:seen.py


示例11: twitter_url

def twitter_url(match, bot=None):
    # Find the tweet ID from the URL
    tweet_id = match.group(1)

    # Get the tweet using the tweepy API
    api = get_api(bot)
    if not api:
        return
    try:
        tweet = api.get_status(tweet_id)
        user = tweet.user
    except tweepy.error.TweepError:
        return

    # Format the return the text of the tweet
    text = " ".join(tweet.text.split())

    if user.verified:
        prefix = u"\u2713"
    else:
        prefix = ""

    time = timesince.timesince(tweet.created_at, datetime.utcnow())

    return u"{}@\x02{}\x02 ({}): {} ({} ago)".format(prefix, user.screen_name, user.name, text, time)
开发者ID:FrozenPigs,项目名称:uguubot,代码行数:25,代码来源:twitter.py


示例12: seen

def seen(text, nick, chan, db, input, conn):
    """seen <nick> <channel> -- Tell when a nickname was last in active in one of this bot's channels."""

    if input.conn.nick.lower() == text.lower():
        return "You need to get your eyes checked."

    if text.lower() == nick.lower():
        return "Have you looked in a mirror lately?"

    if not re.match("^[A-Za-z0-9_|.\-\]\[]*$", text.lower()):
        return "I can't look up that name, its impossible to use!"

    db_init(db, conn.name)

    last_seen = db.execute("select name, time, quote from seen_user where name"
                           " like :name and chan = :chan", {'name': text, 'chan': chan}).fetchone()

    if last_seen:
        reltime = timesince.timesince(last_seen[1])
        if last_seen[0] != text.lower():  # for glob matching
            text = last_seen[0]
        if last_seen[2][0:1] == "\x01":
            return '{} was last seen {} ago: * {} {}'.format(text, reltime, text,
                                                             last_seen[2][8:-1])
        else:
            return '{} was last seen {} ago saying: {}'.format(text, reltime, last_seen[2])
    else:
        return "I've never seen {} talking in this channel.".format(text)
开发者ID:FurCode,项目名称:RoboCop2,代码行数:28,代码来源:history.py


示例13: last

def last(inp, nick='', chan='', input=None, db=None, say=None):
    """.last <phrase> - Finds the last occurence of a phrase."""
    row = db.execute("select time, nick, msg, uts from log where msg like ? "
        "and uts < ? and chan = ? order by uts desc limit 1",
        (('%' + inp.strip() + '%'), (time.time() - 1), chan)).fetchone()
    if row:
        xtime, xnick, xmsg, xuts = row
        say("%s last said \"%s\" on %s (%s ago)" %
            (xnick, xmsg, xtime[:-7], timesince.timesince(xuts)))
    else:
        say("Never!")
开发者ID:Cameri,项目名称:Gary,代码行数:11,代码来源:chatlog.py


示例14: getdelta

def getdelta(t):
    delta = timesince.timesince(t) + " ago"
    # Check if it's been over a month since we saw them:
    days = datetime.timedelta(seconds=(time.time() - t)).days
    # Consider hiding this is it's been fewer than some number of days?
    if days >= 0:
        t = int(t)
        dt = datetime.datetime.fromtimestamp(t)
        delta = delta + " (" + dt.__str__() + ")"
    
    return delta
开发者ID:TZer0,项目名称:botmily,代码行数:11,代码来源:seen.py


示例15: reddit

def reddit(inp):
    """reddit <subreddit> [n] -- Gets a random post from <subreddit>, or gets the [n]th post in the subreddit."""
    id_num = None

    if inp:
        # clean and split the input
        parts = inp.lower().strip().split()

        # find the requested post number (if any)
        if len(parts) > 1:
            url = base_url.format(parts[0].strip())
            try:
                id_num = int(parts[1]) - 1
            except ValueError:
                return "Invalid post number."
        else:
            url = base_url.format(parts[0].strip())
    else:
        url = "http://reddit.com/.json"

    try:
        data = http.get_json(url, user_agent=http.ua_chrome)
    except Exception as e:
        return "Error: " + str(e)
    data = data["data"]["children"]

    # get the requested/random post
    if id_num is not None:
        try:
            item = data[id_num]["data"]
        except IndexError:
            length = len(data)
            return "Invalid post number. Number must be between 1 and {}.".format(length)
    else:
        item = random.choice(data)["data"]

    item["title"] = formatting.truncate_str(item["title"], 50)
    item["link"] = short_url.format(item["id"])

    raw_time = datetime.fromtimestamp(int(item["created_utc"]))
    item["timesince"] = timesince.timesince(raw_time)

    if item["over_18"]:
        item["warning"] = " \x02NSFW\x02"
    else:
        item["warning"] = ""

    return (
        "\x02{title} : {subreddit}\x02 - posted by \x02{author}\x02"
        " {timesince} ago - {ups} upvotes, {downs} downvotes -"
        " {link}{warning}".format(**item)
    )
开发者ID:Zarthus,项目名称:CloudBotRefresh,代码行数:52,代码来源:reddit.py


示例16: lastfm

def lastfm(script):
    if not api_key:
        script.character.send_chat("[lastfm] error: no api key set")

    user = script.character.name

    response = http.get_json(api_url, method="user.getrecenttracks",
                             api_key=api_key, user=user, limit=1)

    if 'error' in response:
        script.character.send_chat("[lastfm] Error: %s." % response["message"])

    if not "track" in response["recenttracks"] or len(response["recenttracks"]["track"]) == 0:
        script.character.send_chat('[lastfm] No recent tracks for user "%s" found.' % user)

    tracks = response["recenttracks"]["track"]

    if type(tracks) == list:
        # if the user is listening to something, the tracks entry is a list
        # the first item is the current track
        track = tracks[0]
        status = 'is listening to'
        ending = '.'
    elif type(tracks) == dict:
        # otherwise, they aren't listening to anything right now, and
        # the tracks entry is a dict representing the most recent track
        track = tracks
        status = 'last listened to'
        # lets see how long ago they listened to it
        time_listened = datetime.fromtimestamp(int(track["date"]["uts"]))
        time_since = timesince.timesince(time_listened)
        ending = ' (%s ago)' % time_since

    else:
        script.character.send_chat("[lastfm] error: could not parse track listing")

    title = track["name"]
    album = track["album"]["#text"]
    artist = track["artist"]["#text"]

    out = '%s %s "%s"' % (user, status, title)
    if artist:
        out += " by \x02%s\x0f" % artist
    if album:
        out += " from the album \x02%s\x0f" % album

    # append ending based on what type it was
    out += ending

    script.character.send_chat("[lastfm] " + out)
开发者ID:blha303,项目名称:ST-Scripts,代码行数:50,代码来源:lastfm.py


示例17: showtells

def showtells(nick, notice, db, conn):
    """showtells -- View all pending tell messages (sent in a notice)."""

    tells = get_unread(db, conn.server, nick)

    if not tells:
        notice("You have no pending messages.")
        return

    for tell in tells:
        sender, message, time_sent = tell
        past = timesince.timesince(time_sent)
        notice("{} sent you a message {} ago: {}".format(sender, past, message))

    read_all_tells(db, conn.server, nick)
开发者ID:nasonfish,项目名称:CloudBot,代码行数:15,代码来源:tell.py


示例18: seen

def seen(inp, nick='', chan='', db=None, input=None):
    ",seen <nick> -- Tell when a nickname was last in active in irc"
    if input.conn.nick.lower() == inp.lower():
        return("I'm right here, need something?")
    if inp.lower() == nick.lower():
        return("Yes, that's your nick ...")
    db_init(db)
    last_seen = db.execute("select name, said, time, chan from seen where name=lower(?)", (inp,)).fetchone()
    if last_seen:
        reltime = timesince.timesince(last_seen[2])
        if last_seen[0] != inp.lower():  # for glob matching
            inp = last_seen[0]
        return('%s was last seen %s ago in %s saying: %s' % (inp, reltime, last_seen[3], last_seen[1].replace("\x01ACTION",'"'+inp+': ').replace("\x01",'"')))
    else:
        return("User not in database")
开发者ID:Red-M,项目名称:frogbot,代码行数:15,代码来源:seen.py


示例19: onJoinMsg

def onJoinMsg(inp, input=None, db=None, pm=None, conn=None):
    db_init(db)
    m = getMsgs(db,input.nick)
    #if c > 0:
    #    notice("You have %s new messages. Type /msg %s |read to read them"%(str(c),conn.nick))
    if len(m) > 0:
        #if len(m) == 1: notice("You have %s new message."%len(m))
        #elif len(m) > 1: notice("You have %s new messages."%len(m))
        if len(m) > 0:
            for m in m:
                string = "Sent %s ago; From %s;"%(timesince.timesince(m[4]),m[2])
                pm(string+" "+m[3])
                #notice(m[3])
                db.execute("delete from msg where touser like (?)",(input.nick,))
                db.commit()
开发者ID:gbyers,项目名称:skybot,代码行数:15,代码来源:msg.py


示例20: showtells

def showtells(inp, say='', nick='', chan='', db=None):
    db_init(db)
    tells = get_tells(db, nick)

    if not tells:
        return
    for tell in tells:
        user_from, message, time, chan = tell
        past = timesince.timesince(time)
        say("%s: Message from %s, %s ago in %s: %s" %
            (nick, user_from, past, chan, message))  # notice(

    db.execute("delete from tell where user_to=lower(?)",
               (nick,))
    db.commit()
开发者ID:Cameri,项目名称:Gary,代码行数:15,代码来源:message.py



注:本文中的util.timesince.timesince函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tools.getResult函数代码示例发布时间:2022-05-26
下一篇:
Python sliceRun.getExportFilename函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap