コード例 #1
0
ファイル: twitter.py プロジェクト: HeyMan7/Code
def daemon(code, tc):
    while True:
        time.sleep(auto_check)

        if code.debug:
            output.info('Running check for new tweets', 'TWITTER')
        # Here we do the work...
        for channel in tc:
            for tweet_item in tc[channel]:
                if tweet_item.startswith('#'):  # ID
                    data = get_tweets(uri_hash % web.quote(tweet_item))
                else:
                    data = get_tweets(uri_user % web.quote(tweet_item), tweet_item)
                if not data:
                    continue
                data = data[0]
                hash_str = hash(data['text'])
                db = database.get(code.default, 'twitter')
                if not db:  # New data on new database, don't output anywhere..
                    database.set(code.default, [hash_str], 'twitter')
                    continue
                if hash_str in db:
                    continue  # Same

                db.append(hash_str)
                database.set(code.default, db, 'twitter')
                msg = format(data)
                code.msg(channel, msg.decode('ascii', 'ignore'), shorten_urls=False)
            db = database.get(code.default, 'twitter')
            if db:
                if len(db) > 200:
                    db = db[-200:]
                    database.set(code.default, db, 'twitter')
コード例 #2
0
def daemon(code, tc):
    while True:
        time.sleep(auto_check)

        # Here we do the work...
        for channel in tc:
            for tweet_item in tc[channel]:
                if tweet_item.startswith('#'):  # ID
                    data = get_tweets(uri_hash % urllib.quote(tweet_item))
                else:
                    data = get_tweets(uri_user % urllib.quote(tweet_item),
                                      tweet_item)
                if not data:
                    continue
                data = data[0]
                hash_str = hash(data['text'])
                db = database.get(code.nick, 'twitter')
                if not db:  # New data on new database, don't output anywhere..
                    database.set(code.nick, [hash_str], 'twitter')
                    continue
                if hash_str in db:
                    continue  # Same

                db.append(hash_str)
                database.set(code.nick, db, 'twitter')
                msg = format(data)
                if hasattr(code.config, 'shortenurls'):
                    if code.config.shortenurls:
                        urls = r_basicurl.findall(msg)
                        for url in urls:
                            msg = msg.replace(url, web.shorten(url))
                code.msg(channel, msg.decode('ascii', 'ignore'))
            db = database.get(code.nick, 'twitter')
            if db:
                if len(db) > 200:
                    db = db[-200:]
                    database.set(code.nick, db, 'twitter')
コード例 #3
0
ファイル: twitter.py プロジェクト: kamaal44/Code
def daemon(code, tc):
    while True:
        time.sleep(auto_check)

        if code.debug:
            output.info('Running check for new tweets', 'TWITTER')
        # Here we do the work...
        for channel in tc:
            for tweet_item in tc[channel]:
                if tweet_item.startswith('#'):  # ID
                    data = get_tweets(uri_hash % web.quote(tweet_item))
                else:
                    data = get_tweets(uri_user % web.quote(tweet_item),
                                      tweet_item)
                if not data:
                    continue
                data = data[0]
                hash_str = hash(data['text'])
                db = database.get(code.default, 'twitter')
                if not db:  # New data on new database, don't output anywhere..
                    database.set(code.default, [hash_str], 'twitter')
                    continue
                if hash_str in db:
                    continue  # Same

                db.append(hash_str)
                database.set(code.default, db, 'twitter')
                msg = format(data)
                code.msg(channel,
                         msg.decode('ascii', 'ignore'),
                         shorten_urls=False)
            db = database.get(code.default, 'twitter')
            if db:
                if len(db) > 200:
                    db = db[-200:]
                    database.set(code.default, db, 'twitter')
コード例 #4
0
ファイル: twitter.py プロジェクト: wolfy852/Code
def daemon(code, tc):
    while True:
        time.sleep(auto_check)

        # Here we do the work...
        for channel in tc:
            for tweet_item in tc[channel]:
                if tweet_item.startswith('#'):  # ID
                    data = get_tweets(uri_hash % urllib.quote(tweet_item))
                else:
                    data = get_tweets(uri_user % urllib.quote(tweet_item), tweet_item)
                if not data:
                    continue
                data = data[0]
                hash_str = hash(data['text'])
                db = database.get(code.nick, 'twitter')
                if not db:  # New data on new database, don't output anywhere..
                    database.set(code.nick, [hash_str], 'twitter')
                    continue
                if hash_str in db:
                    continue  # Same

                db.append(hash_str)
                database.set(code.nick, db, 'twitter')
                msg = format(data)
                if hasattr(code.config, 'shortenurls'):
                    if code.config.shortenurls:
                        urls = r_basicurl.findall(msg)
                        for url in urls:
                            msg = msg.replace(url, web.shorten(url))
                code.msg(channel, msg.decode('ascii', 'ignore'))
            db = database.get(code.nick, 'twitter')
            if db:
                if len(db) > 200:
                    db = db[-200:]
                    database.set(code.nick, db, 'twitter')