def main(): since_id = False while_status = True #FILE LINK GOOGLE SPREADSHEET!! #file_link = 'https://docs.google.com/spreadsheets/d/1yGrA816qiglw6PpjdyuWfxIfZORaS-zeQB_plcfQxWk/edit#gid=0' file_link = "https://docs.google.com/spreadsheets/d/12LanzWrCnm48Gq5NRT6RSrJVLVMN2fPz5U9GNSqU-3Y/edit#gid=0" tb = TwitterBot("GoalNHL") uss = SpreadheetUpdater(file_link) uss.gs_cred() end_row = 1 while while_status==True: print(datetime.datetime.now()) try: prnt_tweet_rows = [] prnt_tweet_rows, since_id, twitter_bot_status = tb.fetch_tweet(since_id) if(twitter_bot_status): #print("SINCE ID {}".format(since_id)) if(len(prnt_tweet_rows) > 0): #print(prnt_tweet_rows) end_row = uss.upd_spreadsheet(prnt_tweet_rows, end_row) else: print("No new tweet added to write into sheet!") time.sleep(300) else: print('Twitter BOT Failed!!') break except KeyboardInterrupt: print('Keyboad Interrupt!!') while_status = False break
def main(): conf_file = '../data/bots.conf' conf = load_conf(conf_file) for bot_username in conf['bot_usernames']: try: bot = TwitterBot(bot_username) tweet = bot.tweet_random_quote() if tweet: msg = '%s tweeted: %s' % (bot_username, tweet.text) print msg else: msg = '%s failed to tweet' % bot_username print msg result = bot.retweet_keyword_home_timeline() except Exception as e: error_msg = "%s ERROR: %s" % (bot_username, str(e)) print error_msg
def menu(): """Twitter bot menu""" bot = TwitterBot() user_input = '' menu_string = "\n1) Get Query\n"\ "2) Show Trends\n"\ "3) Show blocked users\n"\ "4) Show followers\n"\ "5) Get user tweets\n"\ "0) Exit\n" while user_input != 0: try: user_input = int(input(f"{menu_string}")) except ValueError: print("!!!Incorrect input, try again.!!!") next if user_input == 1: bot.get_query() elif user_input == 2: bot.show_trends() elif user_input == 3: bot.check_blocked_user() elif user_input == 4: bot.get_followers() elif user_input == 5: bot.get_user_tweets() elif user_input == 0: sys.exit('Bye!')
from twitter_bot import TwitterBot from os import environ import utils API_KEY = utils.getenv('API_KEY', '') API_KEY_SECRET = utils.getenv('API_KEY_SECRET', '') ACCESS_TOKEN = utils.getenv('ACCESS_TOKEN', '') ACCESS_TOKEN_SECRET = utils.getenv('ACCESS_TOKEN_SECRET', '') STALKER_ACCOUNT = utils.getenv('STALKER_ACCOUNT', '') ACCOUNT = utils.getenv('ACCOUNT', '') def check_credentials(credentials): not_empty_items = list(filter(lambda item: item != '', credentials)) return len(not_empty_items) == len(credentials) if __name__ == "__main__": credentials = { 'api_key': API_KEY, 'api_key_secret': API_KEY_SECRET, 'access_token': ACCESS_TOKEN, 'access_token_secret': ACCESS_TOKEN_SECRET } if check_credentials(credentials) & (STALKER_ACCOUNT != ''): bot = TwitterBot(credentials, ACCOUNT, STALKER_ACCOUNT) bot.block_followersOf_replying() else: print('Credenciales no validas')
from twitter_bot import TwitterBot from os import environ import utils API_KEY = utils.getenv('API_KEY', '') API_KEY_SECRET = utils.getenv('API_KEY_SECRET', '') ACCESS_TOKEN = utils.getenv('ACCESS_TOKEN', '') ACCESS_TOKEN_SECRET = utils.getenv('ACCESS_TOKEN_SECRET', '') STALKED_ACCOUNT = utils.getenv('STALKED_ACCOUNT', '') def check_credentials(credentials): not_empty_items = list(filter(lambda item: item != '', credentials)) return len(not_empty_items) == len(credentials) if __name__ == "__main__": credentials = { 'api_key': API_KEY, 'api_key_secret': API_KEY_SECRET, 'access_token': ACCESS_TOKEN, 'access_token_secret': ACCESS_TOKEN_SECRET } if check_credentials(credentials) & (STALKED_ACCOUNT != ''): bot = TwitterBot(credentials, STALKED_ACCOUNT) bot.reply_tweets() else: print('Credenciales no validas')
from check_internet_speed import SpeedCheck from twitter_bot import TwitterBot import time check_internet_speed = SpeedCheck() check_internet_speed.get_speed() # runs the speed test upload_speed = float(check_internet_speed.upload_speed()) # assigns variables for condition and f-strings download_speed = float(check_internet_speed.download_speed()) check_internet_speed.quit() print(">>> checking msg_condition") if download_speed < 100.00: # change to match the guaranteed terms of your isp time.sleep(1) print(">>> main.preparing msg") twitter = TwitterBot() twitter.sign_in() time.sleep(1) message = f"♪┏(・o・)┛♪ UPLOAD SPEED: {upload_speed}\n┗ ( ・o・) ┓♪ DOWNLOAD SPEED: {download_speed}" twitter.tweet(message) print(">>> main.message sent") twitter.quit() # comment out to keep window open at the end
in_reply_to_status_id=tweet.id) except: pass return new_since_id if __name__ == '__main__': if authentication_email_json_path: email_sender = EmailSender(authentication_email_json_path) print('Loading Lyrics Generator Model') lyrics_gen = LyricsGenerator(gpt_2_model_directory) print('Creating Twitter Bot') twitter_bot = TwitterBot(authentication_twitter_json_path) try: since_id = utils.load_since_id(since_id_json_path) print('Last tweet replied loaded correctly') except: print('Error loading last tweet / There was no last tweet') since_id = 1 print('Running...') try: while True: try: print('Replying mentions...') since_id = reply_mentions(twitter_bot, lyrics_gen,
import click import csv import socketserver import sys from dotenv import load_dotenv from feedgen.feed import FeedGenerator from http.server import SimpleHTTPRequestHandler from os import environ from pyngrok import ngrok from twitter_bot import TwitterBot from utils import extract_got_props, got_props load_dotenv() bot = TwitterBot() @click.group() def cli(): """The twitter helper""" pass @cli.command() @click.argument("username") @click.argument("output", type=click.File("w")) def tweets(username, output): """Get top tweets from the accounts given in the input file and saves them in the output""" csvwriter = csv.DictWriter(output, fieldnames=got_props)
def main(): bot = TwitterBot() print("Logging you in!") bot.login() cont = True while (cont): print("What would you like to do?") print("\t1. Write a tweet") print("\t2. Get trending topics") print("\t3. Get number of and read notifications") print("\t4. Logout") print("\t5. Exit") reply = input("Choice: ") if (int(reply) == 1): tweet_text = input("Tweet: ") image_path = input("image path (leave empty if none): ") if (image_path == ""): bot.sendTweet(tweet_text, None) else: bot.sendTweet(tweet_text, image_path) elif (int(reply) == 2): bot.getTrendingTopics() elif (int(reply) == 3): bot.getNumberofNotifications() elif (int(reply) == 4): bot.logout() elif (int(reply) == 5): cont = False exit()
from speed_test import SpeedTest from twitter_bot import TwitterBot PROMISED_DOWN = 150 PROMISED_UP = 10 speeds = SpeedTest() actual_speeds = speeds.get_internet_speed() actual_down = float(actual_speeds["download_speed"]) actual_up = float(actual_speeds["upload_speed"]) if PROMISED_DOWN > actual_down or PROMISED_UP > actual_up: complaint_tweet = f"Hey Internet Provider, why is my connection speed only {actual_down} Down/{actual_up} Up when I am paying for {PROMISED_DOWN} Down/{PROMISED_UP} Up?!" twitter = TwitterBot() twitter.tweet_at_provider(complaint_tweet) else: print("No internet speed issues today.")
logger = logging.getLogger('tweet_bots') logger.setLevel(logging.INFO) handler = logging.handlers.RotatingFileHandler(conf['logging']['logfile'], maxBytes=conf['logging']['max_bytes'], backupCount=conf['logging']['backup_count']) formatter = logging.Formatter('%(asctime)s - %(name)s - %(filename)s:%(funcName)s - %(levelname)s - %(message)s', '%Y-%m-%d %H:%M:%S') handler.setFormatter(formatter) logger.addHandler(handler) bot_usernames = conf['bot_usernames'] for bot_username in bot_usernames: logger.info('activating bot %s' % bot_username) try: bot = TwitterBot(bot_username) # Check API credentials are valid bot.twitter_client.GetUserTimeline() if bot_username == 'portlandiafred': bot.converse_with('portlandiacarie') elif bot_username == 'portlandiacarie': bot.converse_with('portlandiafred') tweet = bot.tweet() if tweet: logger.info('%s tweeted %s' % (bot_username, tweet)) else: logger.error('%s failed to tweet' % bot_username)