def main(): parser = argparse.ArgumentParser(description="Yatcobot: a bot for entering twitter contests") parser.add_argument("--login", dest="login", action="store_true", help="Login to twitter to get tokens") parser.add_argument("--config", "-c", dest="config", default="config.json", help="Path of the config file") parser.add_argument("--ignore_list", "-i", dest="ignore_list", default="ignorelist", help="Path of the ignore file") parser.add_argument("--log", dest="logfile", default=None, help="Path of log file") parser.add_argument("--debug", dest="debug", action="store_true", help="Enable debug") args = parser.parse_args() # Gets user tokens from twitter and saves them if args.login: tokens = get_access_token(Config.consumer_key, Config.consumer_secret) while True: user_input = input("Save tokens to {}? y/n ".format(args.config)) user_input = user_input.lower() if user_input in ["y", "n"]: break else: print("That is not a valid option!") if user_input == "y": Config.save_user_tokens(args.config, tokens["token"], tokens["secret"]) # Create logger if args.debug: create_logger(logging.DEBUG, args.logfile) else: create_logger(logging.INFO, args.logfile) Config.load(args.config) bot = Yatcobot(args.ignore_list) bot.run()
def test_config(self): template = Config.get_template() self.assertIn(RatingByRetweetsCount.name, template['twitter']['search']['sort']) self.assertIn( 'enabled', template['twitter']['search']['sort'][RatingByRetweetsCount.name])
def test_config(self): template = Config.get_template() self.assertIn(Follow.name, template['twitter']['actions']) self.assertIn('enabled', template['twitter']['actions'][Follow.name]) self.assertIn('keywords', template['twitter']['actions'][Follow.name]) self.assertIn('max_following', template['twitter']['actions'][Follow.name]) self.assertIn('multiple', template['twitter']['actions'][Follow.name])
def test_config(self): template = Config.get_template() self.assertIn(TagFriend.name, template['twitter']['actions']) self.assertIn('enabled', template['twitter']['actions'][TagFriend.name]) self.assertIn('friends', template['twitter']['actions'][TagFriend.name]) self.assertIn('tag_keywords', template['twitter']['actions'][TagFriend.name]) self.assertIn('friend_keywords', template['twitter']['actions'][TagFriend.name]) self.assertIn('number_keywords', template['twitter']['actions'][TagFriend.name])
def test_config(self): template = Config.get_template() self.assertIn(RatingByKeywords.name, template['twitter']['search']['sort']) self.assertIn( 'enabled', template['twitter']['search']['sort'][RatingByKeywords.name]) self.assertIn( 'keywords', template['twitter']['search']['sort'][RatingByKeywords.name])
def test_config(self): template = Config.get_template() self.assertIn(MailNotifier.name, template['notifiers']) self.assertIn('enabled', template['notifiers'][MailNotifier.name]) self.assertIn('host', template['notifiers'][MailNotifier.name]) self.assertIn('port', template['notifiers'][MailNotifier.name]) self.assertIn('tls', template['notifiers'][MailNotifier.name]) self.assertIn('username', template['notifiers'][MailNotifier.name]) self.assertIn('password', template['notifiers'][MailNotifier.name]) self.assertIn('recipient', template['notifiers'][MailNotifier.name])
def test_config(self): template = Config.get_template() self.assertIn(FilterMinRetweets.name, template['twitter']['search']['filter']) self.assertIn( 'enabled', template['twitter']['search']['filter'][FilterMinRetweets.name]) self.assertIn( 'number', template['twitter']['search']['filter'][FilterMinRetweets.name])
def test_config(self): template = Config.get_template() self.assertIn(FilterBlacklist.name, template['twitter']['search']['filter']) self.assertIn( 'enabled', template['twitter']['search']['filter'][FilterBlacklist.name]) self.assertIn( 'keywords', template['twitter']['search']['filter'][FilterBlacklist.name])
def main(): parser = argparse.ArgumentParser(description='Yatcobot: a bot for entering twitter contests') parser.add_argument('--login', dest='login', action='store_true', help='Login to twitter to get tokens') parser.add_argument('--config', '-c', dest='config', default='config.json', help='Path of the config file') parser.add_argument('--ignore_list', '-i', dest='ignore_list', default='ignorelist', help='Path of the ignore file') parser.add_argument('--log', dest='logfile', default=None, help='Path of log file') parser.add_argument('--debug', dest='debug', action='store_true', help='Enable debug') args = parser.parse_args() #Gets user tokens from twitter and saves them if args.login: tokens = get_access_token(Config.consumer_key, Config.consumer_secret) while True: user_input = input('Save tokens to {}? y/n '.format(args.config)) user_input = user_input.lower() if user_input in ['y', 'n']: break else: print('That is not a valid option!') if user_input == 'y': Config.save_user_tokens(args.config, tokens['token'], tokens['secret']) #Create logger if args.debug: create_logger(logging.DEBUG, args.logfile) else: create_logger(logging.INFO, args.logfile) Config.load(args.config) bot = Yatcobot(args.ignore_list) bot.run()
def load_fixture_config(): tests_path = os.path.dirname(os.path.abspath(__file__)) config_path = os.path.join(tests_path, 'fixtures', 'config.test.yaml') Config.load(config_path)
def test_access_before_load(self): Config._valid = None with self.assertRaises(ValueError): Config.get()
def test_load_without_user_config(self): Config._valid = None with self.assertRaises(confuse.NotFoundError): Config.load()
import argparse import json from yatcobot.client import TwitterClient from yatcobot.config import TwitterConfig, Config parser = argparse.ArgumentParser(description='Download a tweet to json') parser.add_argument('tweet_id', metavar='id', type=int) parser.add_argument('--config', '-c', dest='config', default='../config.yaml', help='Path of the config file') args = parser.parse_args() Config.load(args.config) client = TwitterClient(TwitterConfig.get().consumer_key, TwitterConfig.get().consumer_secret, TwitterConfig.get().access_token_key, TwitterConfig.get().access_token_secret) tweet = client.get_tweet(args.tweet_id) with open(f'{args.tweet_id}.json', 'w') as f: json.dump(tweet, f, indent=2)
def test_config(self): template = Config.get_template() self.assertIn(Favorite.name, template['twitter']['actions']) self.assertIn('enabled', template['twitter']['actions'][Favorite.name]) self.assertIn('keywords', template['twitter']['actions'][Favorite.name])
def test_config(self): template = Config.get_template() self.assertIn(PushbulletNotifier.name, template['notifiers']) self.assertIn('enabled', template['notifiers'][PushbulletNotifier.name]) self.assertIn('token', template['notifiers'][PushbulletNotifier.name])