def tweet_sender(self):
        print("starting tweet_sender()")

        gls.log_file_writer()

        try:
            for i in range(len(self.tweets_list)):
                # the following line sends out the tweets from the list
                gls.api.update_status(
                    f'{self.tweets_list[i]} {gls.random_hashtag()}')

                time_slept = gls.sleep_time()
                #
                # del (self.tweets_list[i])
                #
                # print(f'index - {i} len - {len(self.tweets_list)}')
                #
                # if i == gls.random_num or len(self.tweets_list) < gls.random_num:
                #     break

        except tweepy.TweepError as e:
            logging.error('Error occurred ' + str(e))

        finally:
            pass

        print(
            "follower_looper() has terminated after 5 iterations and deletions "
        )
        return len(self.tweets_list)
Exemple #2
0
    def follower_looper(self):
        print("starting follower_looper()")

        gls.log_file_writer()
        try:
            # this loop sends dms to everyone I follow
            for i in range(len(self.follower_id_list)):
                gls.api.send_direct_message(
                    self.follower_id_list[i],
                    f'{self.custom_msg_list[randint(0, len(self.custom_msg_list) - 1)]} {self.screen_name_list[i]} :)!'
                )

                gls.sleep_time()

                # del (self.screen_name_list[i])
                # del (self.follower_id_list[i])
                #
                # print(f'index - {i} len - {len(self.screen_name_list)}')
                #
                # if i == gls.random_num or len(self.screen_name_list) < gls.random_num:
                #     break

        except tweepy.TweepError as e:
            logging.error('Error occurred ' + str(e))

        except Exception as e:
            logging.error('Error occurred ' + str(e))

        finally:
            pass

        print(
            "follower_looper() has terminated after 5 iterations and deletions "
        )
        return len(self.screen_name_list)
Exemple #3
0
def custom_replier():
    gls.log_file_writer()

    try:
        print("replying to custom mentions...")
        last_seen_id = get_last_seen_id(gls.value_holder_file)

        mentions = api.mentions_timeline(last_seen_id, tweet_mode='extended')
        # print(mentions[0].__dict__.keys())  # converts list into dict and extracts all the keys
        #
        # print(mentions[0].text)
        # 1163451084704079873 for testing

        for single_mention in reversed(mentions):
            print(f"mention id {single_mention.id} - mention full text {single_mention.full_text}")
            last_seen_id = single_mention.id
            save_last_seen_id(last_seen_id, gls.value_holder_file)

            api.update_status(
                "merry christmas and happy new year",
                single_mention.id)

            gls.sleep_time()

    except tweepy.TweepError as ess:
        logging.error('Error occurred ' + str(ess))

    except Exception as eww:
        logging.error('Error occurred ' + str(eww))

    finally:
        pass

    print("custom_replier() has terminated ")
Exemple #4
0
def tweet_list_downloader(downloaded_tweets_csv, hashtag):
    gls.log_file_writer()

    try:
        tweets_csv = open(downloaded_tweets_csv, gls.write)
        csv_writer = csv.writer(tweets_csv)
        print("hashtag downloading on: ", hashtag)
        for single_tweet in tweepy.Cursor(api.search, q=hashtag, rpp=1200, lang="en", since="2018-08-17").items(100000):
            print(single_tweet.id_str)
            single_tweet.favorite()
            gls.sleep_time()
            single_tweet.retweet()

            print(single_tweet.author, single_tweet.created_at, single_tweet.text)

            csv_writer.writerow([str(single_tweet.id_str)+'x', single_tweet.text])

            print("row (hopefully) written into csv")

    except IOError as e2:
        logging.error('Error occurred ' + str(e2))

    except tweepy.TweepError as e3:
        logging.error('Error occurred ' + str(e3))

    except Exception as x4:
        logging.error('Error occurred ' + str(x4))

    finally:
        print("end of like and retweet cycle")
    def single_tweet_replier(self):
        print("starting screen_name_follower()")

        gls.log_file_writer()

        try:
            for i in range(len(self.screen_name_list)):
                gls.api.update_status(
                    status=
                    f"@{self.screen_name_list[i]}  {self.custom_tweet_list[randint(0, len(self.custom_tweet_list) - 1)]}",
                    in_reply_to_status_id=self.tweet_id_list[i][:-1])
                time_slept = gls.sleep_time()
                #
                # del (self.screen_name_list[i])
                # del (self.custom_tweet_list[i])
                #
                # print(f'index - {i} len - {len(self.screen_name_list)}')
                #
                # if i == gls.random_num or len(self.screen_name_list) < gls.random_num:
                #     break

        except tweepy.TweepError as e:
            logging.error('Error occurred ' + str(e))

        except Exception as e:
            logging.error('Error occurred ' + str(e))

        finally:
            pass

        print(
            "screen_name_follower() has terminated after 5 iterations and deletions "
        )
        return len(self.screen_name_list)
Exemple #6
0
def image_tweeter(single_image, single_tweet, single_hashtag):
    print("starting image_tweeter()")

    gls.log_file_writer()

    try:
        api.update_with_media(single_image, f"{single_tweet} {single_hashtag}")

        gls.sleep_time()

    except tweepy.TweepError as eu:
        logging.error('Error occurred ' + str(eu))

    finally:
        pass

    print("image_tweeter() has terminated")
Exemple #7
0
def dm_sender(minion_id, text):
    print("starting dm_sender()")

    gls.log_file_writer()
    try:
        api.send_direct_message(minion_id, text)

    except tweepy.TweepError as ue:
        logging.error('Error occurred ' + str(ue))
        print('Error occurred ' + str(ue))

    except Exception as ep:
        logging.error('Error occurred ' + str(ep))
        print('Error occurred ' + str(ep))

    finally:
        pass
    def custom_replier(self):
        gls.log_file_writer()

        try:
            print("replying to custom mentions...")
            last_seen_id = get_last_seen_id(self.value_holder_file)

            mentions = gls.api.mentions_timeline(last_seen_id, tweet_mode='extended')
            # print(mentions[0].__dict__.keys())  # converts list into dict and extracts all the keys
            #
            # print(mentions[0].text)
            # 1163451084704079873 for testing

            i = 0
            for single_mention in reversed(mentions):
                print(f"mention id {single_mention.id} - mention full text {single_mention.full_text}")
                last_seen_id = single_mention.id
                save_last_seen_id(last_seen_id, self.value_holder_file)

                gls.api.update_status(
                    f'{gls.random_hashtag()} {self.custom_message_list[randint(0, len(self.custom_message_list) - 1)]}, @{single_mention.user.screen_name}',
                    single_mention.id)
                i += 1

                time_slept = gls.sleep_time()

                del (self.custom_message_list[i])

                print(f'index - {i} len - {len(self.custom_message_list)}')

                if i == gls.random_num or len(self.custom_message_list) < gls.random_num:
                    break

            print("end of reply cycle")

        except tweepy.TweepError as e:
            logging.error('Error occurred ' + str(e))

        except Exception as e:
            logging.error('Error occurred ' + str(e))

        finally:
            pass

        print("custom_replier() has terminated after 5 iterations and deletions ")
Exemple #9
0
def tweet_sender(single_handle, single_tweet, single_hashtag):
    print("starting tweet_sender()")

    gls.log_file_writer()

    try:
        api.update_status(f'hey @{single_handle}, {single_tweet} {single_hashtag}')

        gls.sleep_time()

    except tweepy.TweepError as ed:
        logging.error('Error occurred ' + str(ed))
        print('Error occurred ' + str(ed))

    finally:
        pass

    print("tweet_sender() has terminated")
Exemple #10
0
def follower_extractor(follower_and_id_csv, single_handle):
    print(" follower_extractor() starting...")
    gls.log_file_writer()
    try:
        fol_id_csv = open(follower_and_id_csv, gls.write)
        csv_writer = csv.writer(fol_id_csv)
        for a_follower in tweepy.Cursor(api.followers, screen_name=single_handle).items():
            print(f"{a_follower.id} - {a_follower.screen_name}")
            csv_writer.writerow([str(a_follower.id)+'x', a_follower.screen_name])
            print("row (hopefully )written into csv")

    except tweepy.TweepError as em:
        logging.error('Error occurred ' + str(em))
        print('Error occurred ' + str(em))

    finally:
        print(" follower_extractor() done")

        pass
    def tweet_reader(self):
        gls.log_file_writer()

        first_line = True
        try:
            with open(self.tweets_list_csv, self.action) as rdr:
                reader = csv.reader(rdr, delimiter=",")
                for single_row in reader:
                    if first_line:  # this skips th first line
                        first_line = False
                        continue  # used this way, the rest of the code from here is skipped in this loop
                    self.tweets_list.append(single_row[0])
        except IOError as e:
            logging.error('Error occurred ' + str(e))

        finally:
            pass

        print("len of tweet list ", len(self.tweets_list))
    def tweet_list_downloader(self):
        gls.log_file_writer()

        try:
            tweets_csv = open(self.hashtag_tweet_csv, self.action)
            csv_writer = csv.writer(tweets_csv)

            print("hashtag downloading on: ", self.hash_tag)
            for single_tweet in tweepy.Cursor(
                    gls.api.search,
                    q=self.hash_tag,
                    rpp=self.count_num,
                    lang=self.language,
                    since=self.from_date).items(1000):
                print(single_tweet.id_str)
                single_tweet.favorite()
                single_tweet.retweet(
                )  # retweets and favs then waits for a few seconds before going on with iteration

                #time_slept = gls.sleep_time()

                print(single_tweet.author, single_tweet.created_at,
                      single_tweet.text)

                csv_writer.writerow([
                    single_tweet.author.screen_name, single_tweet.created_at,
                    str(single_tweet.id_str) + "x",
                    single_tweet.text.encode('utf-8')
                ])
                print("row (hopefully )written")

        except IOError as e:
            logging.error('Error occurred ' + str(e))

        except tweepy.TweepError as e:
            logging.error('Error occurred ' + str(e))

        except Exception as x:
            logging.error('Error occurred ' + str(x))

        finally:
            print("end of tweet extraction")
Exemple #13
0
    def follower_extractor(self):
        print(" follower_extractor() starting...")
        gls.log_file_writer()
        try:
            for single_follower in tweepy.Cursor(
                    gls.api.followers, screen_name=self.screen_name).items():
                print(f"{single_follower.id} - {single_follower.screen_name}")
                self.screen_name_list.append(single_follower.screen_name)
                self.follower_id_list.append(single_follower.id)

            # gls.sleep_time()

        except tweepy.TweepError as e:
            logging.error('Error occurred ' + str(e))

        finally:
            pass

        print("len of follower id list ", len(self.follower_id_list))
        print("len of handle list ", len(self.screen_name_list))
Exemple #14
0
def my_minion_extractor(my_minion_csv, my_twitter_ac):
    print(" minion_extractor() starting...")

    gls.log_file_writer()
    try:
        minion_csv = open(my_minion_csv, gls.write)
        csv_writer = csv.writer(minion_csv)
        for single_minion in tweepy.Cursor(api.followers, screen_name=my_twitter_ac).items():
            print(f"minion id: {single_minion.id} -  minion name: {single_minion.screen_name}")
            csv_writer.writerow([str(single_minion.id)+'x', single_minion.screen_name])
            print("row (hopefully )written into csv")

    except tweepy.TweepError as ev:
        logging.error('Error occurred ' + str(ev))
        print('Error occurred ' + str(ev))

    finally:
        print("minion extraction done")

        pass
Exemple #15
0
def single_tweet_replier(single_tweet_text, tweet_id):
    print("starting single_tweet_replier()")

    gls.log_file_writer()

    refreshed_tweet = f"{single_tweet_text} #LessonsNotLearned"

    try:
        api.update_status(status=refreshed_tweet, in_reply_to_status_id=tweet_id[:-1])
        gls.sleep_time()

    except tweepy.TweepError as re:
        logging.error('Error occurred ' + str(re))

    except Exception as et:
        logging.error('Error occurred ' + str(et))

    finally:
        pass

    print("single_tweet_replier() has terminated ")
Exemple #16
0
def twitter_user_follower(single_handle):
    print("starting twitter_user_follower()")

    gls.log_file_writer()
    try:

        print(f"creating friendship with: {single_handle}")

        api.create_friendship(screen_name=single_handle)

        gls.sleep_time()

    except tweepy.TweepError as ef:
        logging.error('Error occurred ' + str(ef))
        print('Error occurred ' + str(ef))

    except Exception as eg:
        logging.error('Error occurred ' + str(eg))

    finally:
        pass

    print("twitter_user_follower() has terminated")