コード例 #1
0
def main():
    args = parse_args()
    dry_run = args.dry_run

    usedpath = 'whitehout_lastused.txt'

    out('Checking For #WPGWhitehout....')

    limit = 1

    try:
        config = read_json_config(args.configPath)
        t = Twitter(config['twitter'])
    except Exception as e:
        err(e)
        exit(1)

    phrases = [
        'I think you mean #WPGWhiteout',
        "Are you sure it's #WPGWhitehout and not #WPGWhiteout?",
        ('Looks like an "h" snuck its way in that hashtag. '
         'I think you mean #WPGWhiteout'),
        'Let me just fix that up for you :) #WPGWhiteout not #WPGWhitehout',
        "What's a Hout? Did you mean #WPGWhiteout?",
        ("There's an H in Nashville but not one in Winnipeg, "
         "so don't use it in the hashtag. #WPGWhiteout"),
        '#WPGWhitehout is wrong. #WPGWhiteout is right',
        ('#WPGWhitehout supports the Houts, #WPGWhiteout supports the '
         'Jets. Notice the logo!')
    ]

    # Create Mutex Lock
    mutex = Lock()

    def check_for_whitehout():
        time = get_fuzzed_time(5, 3)
        minutes, seconds = divmod(time, 60)
        hours, minutes = divmod(minutes, 60)
        out('random time: %sh%sm%ss' %
            (int(hours), int(minutes), int(seconds)))

        # Setup and start the threading
        x = Timer(time, check_for_whitehout)
        x.daemon = True
        x.start()

        mutex.acquire()
        try:
            try:
                wpgwhitehout = t.api.GetSearch(term='#WPGWhitehout',
                                               count=30,
                                               result_type='recent',
                                               lang='en')
            except Exception as e:
                err('[Main] Search Failure: %s' % e)
                wpgwhitehout = []

            matches = []
            for x in wpgwhitehout:
                text = x.AsDict()['text']
                if (text.lower()[0:2] != 'rt'
                        and x.user.screen_name != 'wpgwhitehout'):
                    matches.append(x)

            used_id = -1
            with open(usedpath, 'r') as f:
                # There should only be one line
                used_id = int(f.read().strip())

            count = 0
            for x in matches:
                text = x.AsDict()['text']
                status_id = x.id
                screen_name = x.user.AsDict()['screen_name']

                try:
                    print status_id
                    print used_id
                    if status_id <= used_id:
                        continue
                    out(text)
                    response = '@%s %s' % (screen_name, random.choice(phrases))
                    out('Response: %s' % response)
                    if not dry_run:
                        t.api.PostUpdate(response,
                                         in_reply_to_status_id=status_id)
                        # Write used id to file
                        with open(usedpath, 'w') as f:
                            f.write('%s' % status_id)

                except Exception, e:
                    err('PostUpdate Exception: %s' % e)

                out('')
                count += 1
                if count == limit:
                    break
        finally:
            mutex.release()

    check_for_whitehout()

    try:
        while 1:
            sleep(1)
    except KeyboardInterrupt as e:
        out('Closing...')

    exit(0)
コード例 #2
0
def main():
    args = parse_args()

    out("Checking For Ochos....")

    limit = 1

    try:
        config = read_json_config(args.configPath)
        t = Twitter(config['twitter'])
    except Exception as e:
        err(e)
        exit(1)

    try:
        eight = t.api.GetSearch(term='Eight',
                                count=10,
                                result_type='recent',
                                lang='en')
        ocho = t.api.GetSearch(term='8',
                               count=10,
                               result_type='recent',
                               lang='en')
    except Exception as e:
        err("[Main] Search Failure: %s" % e)
        eight = []
        ocho = []

    matches = []
    for x in eight:
        text = x.AsDict()['text']
        blacklist = [
            'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',
            'nine'
        ]
        if filter_search(text, 'eight', blacklist) is not None:
            matches.append(x)
    for x in ocho:
        text = x.AsDict()['text']
        blacklist = ['0', '1', '2', '3', '4', '5', '6', '7', '9']
        if filter_search(text, '8', blacklist) is not None:
            matches.append(x)

    count = 0
    for x in matches:
        text = x.AsDict()['text']
        status_id = x.id
        user_id = x.user.AsDict()['id']
        screen_name = x.user.AsDict()['screen_name']

        out("That's Ocho!")
        out(text)

        try:
            t.api.PostUpdate("@%s That's Ocho!" % screen_name,
                             in_reply_to_status_id=status_id)
        except Exception, e:
            err("PostUpdate Exception: %s" % e)
        out('')
        count += 1
        if count == limit:
            exit(0)
コード例 #3
0
def main():
    args = parse_args()

    try:
        config = read_json_config(args.configPath)
        t = Twitter(config['twitter'])
        p = PSQL(config['psql'])
        s = config['settings']
    except Exception as e:
        err(e)
        exit(1)

    # Set up debug
    global debug
    debug = args.debug

    # Contests Queue
    contests = []

    # Create Mutex Lock
    mutex = Lock()

    def update_queue():
        time = get_fuzzed_time(s['retweet']['base'], s['retweet']['fuzz'])
        minutes, seconds = divmod(time, 60)
        hours, minutes = divmod(minutes, 60)
        out("update_queue random time: %sh%sm%ss" %
            (int(hours), int(minutes), int(seconds)))

        # Setup and start the threading
        u = Timer(time, update_queue)
        u.daemon = True
        u.start()

        mutex.acquire()
        try:
            if len(contests) > 0:
                contest = contests[0]
                out("Contest: %s" % contest['text'])

                followed = check_for_follow_request(contest, t, p, s)
                favourited = check_for_favourite_request(contest, t, p, s)
                retweet_post(contest, t, p, s, followed, favourited)

                contests.pop(0)
        finally:
            mutex.release()

    def scan_for_contests():
        time = get_fuzzed_time(s['search']['base'], s['search']['fuzz'])
        minutes, seconds = divmod(time, 60)
        hours, minutes = divmod(minutes, 60)
        out("scan_for_contests random time: %sh%sm%ss" %
            (int(hours), int(minutes), int(seconds)))

        # Setup and start the threading
        v = Timer(time, scan_for_contests)
        v.daemon = True
        v.start()

        mutex.acquire()
        try:
            out("Scanning For Contests...")
            last_twitter_id = p.get_last_twitter_id()

            try:
                #"RT to win" music OR sound OR speaker OR dj OR mixer OR gear'
                results = t.api.GetSearch(term='"RT to win"',
                                          since_id=last_twitter_id)

                for status in results:
                    item = status.AsDict()
                    if 'retweet_count' in item and item['retweet_count'] > 0:
                        if item['id'] > last_twitter_id:
                            p.set_last_twitter_id(item['id'])
                            contests.append(item)
            except Exception as e:
                err("[scan_for_contests] Search Error: %s" % e)
        finally:
            mutex.release()

    def make_post():
        time = get_fuzzed_time(s['post']['base'], s['post']['fuzz'])
        minutes, seconds = divmod(time, 60)
        hours, minutes = divmod(minutes, 60)
        out("make_post random time: %sh%sm%ss" %
            (int(hours), int(minutes), int(seconds)))

        # Setup and start the threading
        x = Timer(time, make_post)
        x.daemon = True
        x.start()

        mutex.acquire()
        try:
            out("Making random post...")
            text = None
            try:
                # Choose random user from list
                users = s['post']['users']
                user = users[random.randrange(0, len(users))]
                results = t.api.GetUserTimeline(screen_name=user,
                                                count='200',
                                                exclude_replies=True,
                                                include_rts=True)

                # Pick a random status from this list
                status = results[random.randrange(0, len(results))]
                text = status.AsDict()['text']
                out("Random status from %s: %s" % (user, text))
            except Exception as e:
                err("[make_post] Search Error: %s" % e)

            try:
                if text is not None:
                    if not debug:
                        t.api.PostUpdate(status=text)
            except Exception as e:
                err("[make_post] Post Error: %s" % e)
        finally:
            mutex.release()

    scan_for_contests()
    update_queue()
    make_post()

    try:
        while 1:
            sleep(1)
    except KeyboardInterrupt as e:
        out("Closing...")

    exit(0)
コード例 #4
0
ファイル: ocho.py プロジェクト: DJSymBiotiX/ochobot
def main():
    args = parse_args()

    out("Checking For Ochos....")

    limit = 1

    try:
        config = read_json_config(args.configPath)
        t = Twitter(config['twitter'])
    except Exception as e:
        err(e)
        exit (1)

    try:
        eight = t.api.GetSearch(
            term='Eight',
            count=10,
            result_type='recent',
            lang='en'
        )
        ocho = t.api.GetSearch(
            term='8',
            count=10,
            result_type='recent',
            lang='en'
        )
    except Exception as e:
        err("[Main] Search Failure: %s" % e)
        eight = []
        ocho = []

    matches = []
    for x in eight:
        text = x.AsDict()['text']
        blacklist = [
            'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',
            'nine'
        ]
        if filter_search(text, 'eight', blacklist) is not None:
            matches.append(x)
    for x in ocho:
        text = x.AsDict()['text']
        blacklist = ['0', '1', '2', '3', '4', '5', '6', '7', '9']
        if filter_search(text, '8', blacklist) is not None:
            matches.append(x)

    count = 0
    for x in matches:
        text = x.AsDict()['text']
        status_id = x.id
        user_id = x.user.AsDict()['id']
        screen_name = x.user.AsDict()['screen_name']

        out("That's Ocho!")
        out(text)

        try:
            t.api.PostUpdate(
                "@%s That's Ocho!" % screen_name,
                in_reply_to_status_id=status_id
            )
        except Exception, e:
            err("PostUpdate Exception: %s" % e)
        out('')
        count += 1
        if count == limit:
            exit(0)
コード例 #5
0
ファイル: winner.py プロジェクト: DJSymBiotiX/ochobot
def main():
    args = parse_args()

    try:
        config = read_json_config(args.configPath)
        t = Twitter(config['twitter'])
        p = PSQL(config['psql'])
        s = config['settings']
    except Exception as e:
        err(e)
        exit(1)

    # Set up debug
    global debug
    debug = args.debug

    # Contests Queue
    contests = []

    # Create Mutex Lock
    mutex = Lock()

    def update_queue():
        time = get_fuzzed_time(s['retweet']['base'], s['retweet']['fuzz'])
        minutes, seconds = divmod(time, 60)
        hours, minutes = divmod(minutes, 60)
        out("update_queue random time: %sh%sm%ss" % (
            int(hours), int(minutes), int(seconds)
        ))

        # Setup and start the threading
        u = Timer(time, update_queue)
        u.daemon = True
        u.start()

        mutex.acquire()
        try:
            if len(contests) > 0:
                contest = contests[0]
                out("Contest: %s" % contest['text'])

                followed = check_for_follow_request(contest, t, p, s)
                favourited = check_for_favourite_request(contest, t, p, s)
                retweet_post(contest, t, p, s, followed, favourited)

                contests.pop(0)
        finally:
            mutex.release()

    def scan_for_contests():
        time = get_fuzzed_time(s['search']['base'], s['search']['fuzz'])
        minutes, seconds = divmod(time, 60)
        hours, minutes = divmod(minutes, 60)
        out("scan_for_contests random time: %sh%sm%ss" % (
            int(hours), int(minutes), int(seconds)
        ))

        # Setup and start the threading
        v = Timer(time, scan_for_contests)
        v.daemon = True
        v.start()

        mutex.acquire()
        try:
            out("Scanning For Contests...")
            last_twitter_id = p.get_last_twitter_id()

            try:
                #"RT to win" music OR sound OR speaker OR dj OR mixer OR gear'
                results = t.api.GetSearch(
                    term='"RT to win"',
                    since_id=last_twitter_id
                )

                for status in results:
                    item = status.AsDict()
                    if 'retweet_count' in item and item['retweet_count'] > 0:
                        if item['id'] > last_twitter_id:
                            p.set_last_twitter_id(item['id'])
                            contests.append(item)
            except Exception as e:
                err("[scan_for_contests] Search Error: %s" % e)
        finally:
            mutex.release()


    def make_post():
        time = get_fuzzed_time(s['post']['base'], s['post']['fuzz'])
        minutes, seconds = divmod(time, 60)
        hours, minutes = divmod(minutes, 60)
        out("make_post random time: %sh%sm%ss" % (
            int(hours), int(minutes), int(seconds)
        ))

        # Setup and start the threading
        x = Timer(time, make_post)
        x.daemon = True
        x.start()

        mutex.acquire()
        try:
            out("Making random post...")
            text = None
            try:
                # Choose random user from list
                users= s['post']['users']
                user = users[random.randrange(0, len(users))]
                results = t.api.GetUserTimeline(
                    screen_name=user,
                    count='200',
                    exclude_replies=True,
                    include_rts=True
                )

                # Pick a random status from this list
                status = results[random.randrange(0, len(results))]
                text = status.AsDict()['text']
                out("Random status from %s: %s" % (user, text))
            except Exception as e:
                err("[make_post] Search Error: %s" % e)

            try:
                if text is not None:
                    if not debug:
                        t.api.PostUpdate(
                            status=text
                        )
            except Exception as e:
                err("[make_post] Post Error: %s" % e)
        finally:
            mutex.release()

    scan_for_contests()
    update_queue()
    make_post()

    try:
        while 1:
            sleep(1)
    except KeyboardInterrupt as e:
        out("Closing...")

    exit(0)