Exemplo n.º 1
0
    def follower_counter(self, current_follower):
        db = Database()
        db.connect_db(self.db_name)
        db.select_col('follower_counter')

        follower_status = db.find_last_object()
        previous_follower = follower_status['previous_follower']
        diff_follower = current_follower - previous_follower
        db.insert_object({
            'previous_follower': current_follower,
            'current_follower': current_follower + diff_follower,
            'diff_follower': diff_follower
        })
Exemplo n.º 2
0
def main(ck, cs, at, ats):
    bot = Twitter(ck, cs, at, ats)
    db = Database()
    db.connect_db(db_name)
    db.select_col('tweet')

    minute_wait = 5

    while True:
        l = db.find_last_object()
        last_id = l['tweet_last_id']

        since_id = bot.get_mention_tweet(last_id)

        me = bot.api.me()
        my_current_followers = me.followers_count
        bot.follower_counter(my_current_followers)

        t = time.localtime()
        current_time = time.strftime("%H:%M:%S %D", t)

        print(
            "\n" + u"\u250C" +
            "------------------------------------------------",
            "\n| current time: ", current_time, "\n| newest tweet: ", since_id,
            "\n| oldest tweet: ", last_id, "\n| current followers: ",
            me.followers_count, "\n| total tweets: ", me.statuses_count, "\n" +
            u"\u2514" + "------------------------------------------------")

        if (last_id != since_id):
            db.insert_object({'tweet_last_id': since_id})
        else:
            print('no new mention')

        for sec in range(minute_wait * 60, 0, -1):
            sys.stdout.write("\r")
            sys.stdout.write("{:2d} second to check mention.\r".format(sec))
            sys.stdout.flush()
            time.sleep(1)
Exemplo n.º 3
0
    def process_mention(self, list_tweet):
        db = Database()
        db.connect_db(self.db_name)
        db.select_col('tweet')

        for tweet in reversed(list_tweet):
            self.show_status(tweet)
            words = tweet.full_text.lower().split()

            if int(self.important_ids["developer_id"]
                   ) == tweet.in_reply_to_user_id:
                for tw in self.triggering_words:
                    if tw in words:
                        self.tweeted_and_show(self.tweet_text["dont_mock"][0],
                                              tweet)
            elif int(self.important_ids["bot_id"]
                     ) == tweet.in_reply_to_user_id or int(
                         self.important_ids["bot_test_id"]
                     ) == tweet.in_reply_to_user_id:
                print("skipped: mocked itself")
                continue
            else:
                for tw in self.triggering_words:
                    try:
                        if tw is "pliisi" in words:
                            self.mock_in_pliisi(tweet, db)

                        elif tw is "please" in words:
                            self.mock_in_please(tweet, db)

                        elif tw is "pleasek" in words:
                            self.mock_in_emoji_pattern(tweet, 'k', db)

                        elif tw is "pleaseb" in words:
                            self.mock_in_emoji_pattern(tweet, 'b', db)

                        elif tw is "pleasej" in words:
                            self.mock_in_emoji_pattern(tweet, 'j', db)

                        elif tw == "please😂" in words:
                            self.mock_in_emoji(tweet, "laugh", db)

                        elif tw == "please👏" in words:
                            self.mock_in_emoji(tweet, "clap", db)

                        elif tw == "please🤮" in words:
                            self.mock_in_emoji(tweet, "vomit", db)

                        elif tw == "please🤢" in words:
                            self.mock_in_emoji(tweet, "sick", db)

                        elif tw == "please💩" in words:
                            self.mock_in_emoji(tweet, "poop", db)

                        elif tw == "pleasealay" in words:
                            self.mock_in_alay(tweet, db)

                        elif tw == "pleaseud" in words:
                            self.mock_in_upsidedown(tweet, db)

                    except tweepy.TweepError as e:
                        error = e.api_code
                        error = str(error)
                        error_text = e.response

                        db.insert_object({'tweet_last_id': tweet.id})

                        if error == self.error_code['private_account'][0]:
                            tweet_err = self.error_code['private_account'][1]
                            self.api.update_status(
                                status=tweet_err,
                                in_reply_to_status_id=tweet.id,
                                auto_populate_reply_metadata=True)
                            self.show_what_tweeted(tweet_err)

                        elif error == self.error_code['blocked_account'][0]:
                            tweet_err = self.error_code['blocked_account'][1]
                            target = self.api.get_user(
                                id=tweet.in_reply_to_user_id)
                            tweet_err = tweet_err.format(target.screen_name)
                            self.api.update_status(
                                status=tweet_err,
                                in_reply_to_status_id=tweet.id,
                                auto_populate_reply_metadata=True)
                            self.show_what_tweeted(tweet_err)

                        elif error == self.error_code['tweet_target_deleted'][
                                0]:
                            tweet_err = self.error_code[
                                'tweet_target_deleted'][1]
                            self.api.update_status(
                                status=tweet_err,
                                in_reply_to_status_id=tweet.id,
                                auto_populate_reply_metadata=True)
                            self.show_what_tweeted(tweet_err)

                        elif error == self.error_code['tweet_target_to_long'][
                                0]:
                            tweet_err = self.error_code[
                                'tweet_target_to_long'][1]
                            self.api.update_status(
                                status=tweet_err,
                                in_reply_to_status_id=tweet.id,
                                auto_populate_reply_metadata=True)
                            self.show_what_tweeted(tweet_err)

                        elif error == self.error_code['twitter_over_capacity'][
                                0]:
                            tweet_err = self.error_code[
                                'twitter_over_capacity'][1]
                            self.api.update_status(
                                status=tweet_err,
                                in_reply_to_status_id=tweet.id,
                                auto_populate_reply_metadata=True)
                            self.show_what_tweeted(tweet_err)

                        elif error == self.error_code['suspended_account'][0]:
                            tweet_err = self.error_code['suspended_account'][1]
                            self.api.update_status(
                                status=tweet_err,
                                in_reply_to_status_id=tweet.id,
                                auto_populate_reply_metadata=True)
                            self.show_what_tweeted(tweet_err)

                        elif error == self.error_code['duplicate_tweet'][0]:
                            tweet_err = self.error_code['duplicate_tweet'][1]
                            self.show_what_tweeted(tweet_err)
                            continue

                        elif error == self.error_code[
                                'tweet_deleted_or_not_visible'][0]:
                            tweet_err = self.error_code[
                                'tweet_deleted_or_not_visible'][1]
                            self.show_what_tweeted(tweet_err)

                        elif error == self.error_code['page_does_not_exist'][
                                0]:
                            tweet_err = self.error_code['page_does_not_exist'][
                                1]
                            self.show_what_tweeted(tweet_err)

                        else:
                            t = time.localtime()
                            current_time = time.strftime("%H:%M:%S %D", t)
                            db.select_col('tweet_error')
                            db.insert_object({
                                'error_code': str(error),
                                'timestamp': current_time,
                                'tweet_id': tweet.id,
                                'username': tweet.user.screen_name,
                                'tweet_text': tweet.full_text,
                                'error_text': error_text
                            })

                time.sleep(self.time_interval)

            continue