Beispiel #1
0
    def scan_for_contests():
        # Setup and start the threading
        v = Timer(60.0 * 10.0, 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()
Beispiel #2
0
    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()
Beispiel #3
0
    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()
Beispiel #4
0
    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()
Beispiel #5
0
    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()
Beispiel #6
0
def check_for_follow_request(item, twitter, psql, settings):
    """
    Check if a post requires you to follow the user.
    Be careful with this function! Twitter may write ban your application for
    following too aggressively
    """
    followed = False
    text = item['text']
    if 'follow' in text.lower():
        out("Asking to follow...")
        followed = True

        # Unfollow oldest follower if our follower count is >= 1900
        follower_count = psql.get_follower_count()
        if follower_count >= settings['max_followers']:
            oldest_follower = psql.get_oldest_follower()
            out("Too many followers: Unfollowing %s" % oldest_follower)

            # Unfollow that nerd
            if not debug:
                twitter.api.DestroyFriendship(screen_name=oldest_follower)
                psql.unfollow_user(oldest_follower)

        if not debug:
            # Follow the new guy
            try:
                new_follower = item['retweeted_status']['user']['screen_name']
                twitter.api.CreateFriendship(screen_name=new_follower)
            except Exception as e:
                new_follower = item['user']['screen_name']
                twitter.api.CreateFriendship(screen_name=new_follower)

            # Add follower to db
            psql.follow_user(new_follower)
    return followed
Beispiel #7
0
def check_for_favourite_request(item, twitter, psql, settings):
    """
    Check if a post requires you to favourite the tweet.
    Be careful with this function! Twitter may write ban your application for
    favouriting too aggressively
    """
    favourited = False
    text = item['text']
    # Check both canadian and american spelling
    if 'favourite' in text.lower() or 'favorite' in text.lower():
        out("Asking to favourite...")

        # Check if we have already favourited
        if not psql.check_favourite(item['id']):
            favourited = True
            if not debug:
                try:
                    twitter.api.CreateFavorite(
                        id=item['retweeted_status']['user']['id']
                    )
                except Exception as e:
                    twitter.api.CreateFavorite(
                        id=item['id']
                    )

    return favourited
Beispiel #8
0
def retweet_post(item, twitter, psql, settings, followed, favourited):
    out("Retweeting...")

    # Check if we have already retweeted this post
    retweeted = False
    try:
        tweet_id = item['retweeted_status']['id']
        if not psql.check_contest(tweet_id):
            retweeted = True
            if not debug:
                twitter.api.PostRetweet(tweet_id)
    except Exception as e:
        retweeted = False
        try:
            tweet_id = item['id']
            if not psql.check_contest(tweet_id):
                retweeted = True
                if not debug:
                    twitter.api.PostRetweet(tweet_id)
        except Exception as e:
            retweeted = False

    if retweeted:
        if not debug:
            psql.add_contest(tweet_id, item['text'],
                             item['user']['screen_name'], followed, favourited)
Beispiel #9
0
def retweet_post(item, twitter, psql, settings, followed, favourited):
    out("Retweeting...")

    # Check if we have already retweeted this post
    retweeted = False
    try:
        tweet_id = item['retweeted_status']['id']
        if not psql.check_contest(tweet_id):
            retweeted = True
            if not debug:
                twitter.api.PostRetweet(tweet_id)
    except Exception as e:
        retweeted = False
        try:
            tweet_id = item['id']
            if not psql.check_contest(tweet_id):
                retweeted = True
                if not debug:
                    twitter.api.PostRetweet(tweet_id)
        except Exception as e:
            retweeted = False

    if retweeted:
        if not debug:
            psql.add_contest(
                tweet_id,
                item['text'],
                item['user']['screen_name'],
                followed,
                favourited
            )
Beispiel #10
0
    def update_queue():
        # Setup and start the threading
        u = Timer(60.0 * 5.0, 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)
                favourited = check_for_favourite_request(contest, t, p)
                retweet_post(contest, t, p, followed, favourited)

                contests.pop(0)
        finally:
            mutex.release()
Beispiel #11
0
def check_for_follow_request(item, twitter, psql, settings):
    """
    Check if a post requires you to follow the user.
    Be careful with this function! Twitter may write ban your application for
    following too aggressively
    """
    followed = False
    text = item['text']
    if 'follow' in text.lower():
        out("Asking to follow...")
        followed = True

        # Unfollow oldest follower if our follower count is >= 1900
        follower_count = psql.get_follower_count()
        if follower_count >= settings['max_followers']:
            oldest_follower = psql.get_oldest_follower()
            out("Too many followers: Unfollowing %s" % oldest_follower)

            # Unfollow that nerd
            if not debug:
                twitter.api.DestroyFriendship(
                    screen_name=oldest_follower
                )
                psql.unfollow_user(oldest_follower)

        if not debug:
            # Follow the new guy
            try:
                new_follower = item['retweeted_status']['user']['screen_name']
                twitter.api.CreateFriendship(
                    screen_name=new_follower
                )
            except Exception as e:
                new_follower = item['user']['screen_name']
                twitter.api.CreateFriendship(
                    screen_name=new_follower
                )

            # Add follower to db
            psql.follow_user(new_follower)
    return followed
Beispiel #12
0
def check_for_favourite_request(item, twitter, psql, settings):
    """
    Check if a post requires you to favourite the tweet.
    Be careful with this function! Twitter may write ban your application for
    favouriting too aggressively
    """
    favourited = False
    text = item['text']
    # Check both canadian and american spelling
    if 'favourite' in text.lower() or 'favorite' in text.lower():
        out("Asking to favourite...")

        # Check if we have already favourited
        if not psql.check_favourite(item['id']):
            favourited = True
            if not debug:
                try:
                    twitter.api.CreateFavorite(
                        id=item['retweeted_status']['user']['id'])
                except Exception as e:
                    twitter.api.CreateFavorite(id=item['id'])

    return favourited
Beispiel #13
0
    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()
Beispiel #14
0
    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()
Beispiel #15
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)
Beispiel #16
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)
Beispiel #17
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)
Beispiel #18
0
def main():
    args = parse_args()

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

    limit = 1

    t = Twitter(args.configPath)

    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 = []

    out(eight[0].AsDict())

    exit(0)

    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)
Beispiel #19
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)
Beispiel #20
0
    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()
Beispiel #21
0
def main():
    args = parse_args()

    # t = Twitter API, p = PSQL Helper Functions
    t = Twitter(args.configPath)
    p = PSQL(args.configPath)

    # Contests Queue
    contests = []

    # Create Mutex Lock
    mutex = Lock()

    def update_queue():
        # Setup and start the threading
        u = Timer(60.0 * 5.0, 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)
                favourited = check_for_favourite_request(contest, t, p)
                retweet_post(contest, t, p, followed, favourited)

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

    def scan_for_contests():
        # Setup and start the threading
        v = Timer(60.0 * 10.0, 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()

    scan_for_contests()
    update_queue()

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

    exit(0)