예제 #1
0
파일: cli.py 프로젝트: buluba89/Yatcobot
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()
예제 #2
0
파일: cli.py 프로젝트: AkilesX/Yatcobot
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()
예제 #3
0
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)
예제 #4
0
 def test_load_without_user_config(self):
     Config._valid = None
     with self.assertRaises(confuse.NotFoundError):
         Config.load()
예제 #5
0
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)