Example #1
0
def main(league, time, standings, team, live, output_format, output_file):
    """A CLI for live and past football scores from various football leagues"""
    try:
        if output_format == 'stdout' and output_file:
            raise IncorrectParametersException('Printing output to stdout and '
                                               'saving to a file are mutually exclusive')
        writer = get_writer(output_format, output_file)

        if live:
            get_live_scores(writer)
            return

        if standings:
            if not league:
                raise IncorrectParametersException('Please specify a league. '
                                                   'Example --standings --league=EPL')
            get_standings(league, writer)
            return

        if team:
            get_team_scores(team, time, writer)
            return

        get_league_scores(league, time, writer)
    except IncorrectParametersException as e:
        click.secho(e.message, fg="red", bold=True)
Example #2
0
def main(league, time, standings, team, live, players, output_format, output_file):
    """A CLI for live and past football scores from various football leagues"""
    try:
        if output_format == 'stdout' and output_file:
            raise IncorrectParametersException('Printing output to stdout and '
                                               'saving to a file are mutually exclusive')
        writer = get_writer(output_format, output_file)

        if live:
            get_live_scores(writer)
            return

        if standings:
            if not league:
                raise IncorrectParametersException('Please specify a league. '
                                                   'Example --standings --league=EPL')
            get_standings(league, writer)
            return

        if team:
            if players:
                get_team_players(team, writer)
                return
            else:
                get_team_scores(team, time, writer)
                return

        get_league_scores(league, time, writer)
    except IncorrectParametersException as e:
        click.secho(e.message, fg="red", bold=True)
Example #3
0
def main(league, time, standings, team, live, output):
    """ A CLI for live and past football scores from various football leagues """

    writer = writers.get_writer(output)

    if live:
        get_live_scores(writer)
        return

    if standings:
        get_standings(league, writer)
        return

    if team:
        get_team_scores(team, time, writer)
        return

    get_league_scores(league, time, writer)
Example #4
0
def main(league, time, standings, team, live, output):
    """ A CLI for live and past football scores from various football leagues """

    writer = writers.get_writer(output)

    if live:
        get_live_scores(writer)
        return

    if standings:
        get_standings(league, writer)
        return

    if team:
        get_team_scores(team, time, writer)
        return

    get_league_scores(league, time, writer)
def main(api_token, timezone, live, today, matches, standings, league, sort_by,
         days, history, details, odds, not_started, refresh, bet, profile,
         all_bets, open_bets, closed_bets, watch_bets, possible_leagues):
    params = get_params(api_token, timezone)

    try:
        writer = get_writer()
        rh = RequestHandler(params, LEAGUES_DATA, writer, ch)
        betting = Betting(params, LEAGUES_DATA, writer, rh, ch)
        betting.main()

        Parameters = namedtuple(
            "parameters", "url, msg, league_name, sort_by, days, "
            "show_history, show_details, show_odds, not_started, refresh, place_bet, date_format, type_sort"
        )

        def get_multi_matches(filename, parameters):
            bets = betting.get_bets(ch.get_data('betting_files')[filename])
            match_ids = ','.join([i[0] for i in bets])
            predictions = [i[0] + ';' + i[1] for i in bets]
            return rh.get_multi_matches(match_ids, predictions, parameters)

        def bet_matches(type, sort_by):
            date_format = convert.format_date(ch.get('profile', 'date_format'))
            if sort_by is None:
                sort_by = 'date'
            parameters = Parameters('fixtures/multi', [
                "No open bets at the moment.",
                "There was problem getting live scores, check your parameters"
            ], None, sort_by, None, None, details, True, False, True, None,
                                    date_format, 'watch_bets')
            if type == 'open' and watch_bets:
                filename = 'open_bets'
                while True:
                    betting.check_open_bets()
                    quit = get_multi_matches(filename, parameters)
                    if quit:
                        return
                    else:
                        time.sleep(60)
            elif type == 'open':
                filename = 'open_bets'
            else:
                filename = 'closed_bets'

            get_multi_matches(filename, parameters)
            return

        if live or today or matches:
            check_options(history, bet, live, today, refresh, matches)
            date_format = convert.format_date(ch.get('profile', 'date_format'))
            if sort_by is None:
                sort_by = 'league'
            if bet:
                odds = True
            if live:
                not_started = False
                parameters = Parameters('livescores/now', [
                    "No live action at this moment",
                    "There was problem getting live scores, check your parameters"
                ], league, sort_by, days, history, details, odds, not_started,
                                        refresh, bet, date_format, "live")
            elif today:
                parameters = Parameters('livescores', [
                    "No matches today",
                    "There was problem getting today's scores, check your parameters"
                ], league, sort_by, days, history, details, odds, not_started,
                                        refresh, bet, date_format, "today")
            else:
                parameters = Parameters(
                    'fixtures/between/',
                    [[f"No matches in the past {str(days)} days."],
                     [f"No matches in the coming {str(days)} days."]], league,
                    sort_by, days, history, details, odds, not_started,
                    refresh, bet, date_format, "matches")
            rh.get_matches(parameters)
            return

        if standings:
            check_options_standings(league, history)
            rh.get_standings(league, details)
            return

        if profile:
            rh.show_profile()
            return

        if all_bets:
            betting.view_bets('open')
            betting.view_bets('closed')
            return

        if open_bets:
            if details:
                bet_matches('open', sort_by)
            else:
                betting.view_bets('open')
            return

        if closed_bets:
            if details:
                bet_matches('closed', sort_by)
            else:
                betting.view_bets('closed')
            return

        if watch_bets:
            bet_matches('open', sort_by)

        if possible_leagues:
            rh.show_leagues()
            return

    except IncorrectParametersException as e:
        click.secho(str(e), fg="red", bold=True)
Example #6
0
try:
    api_token = os.environ['SOCCER_CLI_API_TOKEN']
except KeyError:
    from config import config
    api_token = config.get('SOCCER_CLI_API_TOKEN')

if not api_token:
    print('No API Token detected. Please visit {0} and get an API Token, '
          'which will be used by the Soccer CLI to get access to the data'.
          format(BASE_URL))
    sys.exit(1)

headers = {'X-Auth-Token': api_token}

writer = get_writer()


def get_live_scores(writer):
    """Gets the live scores"""
    output = []
    req = requests.get(LIVE_URL)
    if req.status_code == requests.codes.ok:
        scores = req.json()
        if len(scores["games"]) == 0:
            return "No live action currently."
        writer.live_scores(scores)
    else:
        return ":disappointed: There was problem getting live scores"

Example #7
0
File: main.py Project: kuhnza/jenny
def main(argv):   
    # Parse command line arguments.
    try:                                
        opts, args = getopt.getopt(argv, 'dfoSh', ['help', 
                                                 'format=',
                                                 'output=', 
                                                 'hostname=', 
                                                 'username='******'password='******'sender=',
                                                 'recipient=',
                                                 'server',
                                                 'delay='])
    except getopt.GetoptError:          
        usage()                         
        sys.exit(2) 
    
    # Setup defaults
    delay = 0
    server = False
    format = DEFAULT_FORMATTER
    output = DEFAULT_WRITER
    hostname = 'localhost'
    username = None
    password = None
    sender = '*****@*****.**'
    recipients = []
    
    for opt, arg in opts:
        if opt in ('-h', '--help'):
            usage()
            sys.exit()
        elif opt in ('-f', '--format'):
            format = arg
            if format not in SUPPORTED_FORMATS:
                print '%s is not a supported format.\n' % format
                usage()
                sys.exit(2)
        elif opt in ('-o', '--output'):
            output = arg
            if output not in SUPPORTED_OUTPUTS:
                print '%s is not a supported output.\n' % output
                usage()
                sys.exit(2)
        elif opt in ('--hostname'):
            hostname = arg
        elif opt in ('--username'):
            username = arg
        elif opt in ('--password'):
            password = arg
        elif opt in ('--sender'):
            sender = arg
        elif opt in ('--recipient'):
            recipients.append(arg)
        elif opt in ('-d', '--delay'):
            delay = int(arg)
        elif opt in ('-S', '--server'):
            server = True
        
    # Setup our writer object
    writer = get_writer(output)
    writer.formatter = get_formatter(format)
    if output == 'email':
        writer.hostname = hostname
        writer.username = username
        writer.password = password
        writer.sender = sender
        writer.recipients = recipients

    # Are we in server mode?
    if server:
        print 'Starting Jenny server...'
    else: 
        # Then how many messages should Jenny spew forth?
        try:
            how_many = int("".join(args))
        except ValueError:
            how_many = 1
        print 'Generating %s messages.' % how_many

    if delay: random.seed()

    # Produce the required amount of messages
    count = 1 
    while True:
        print 'Generating message %s...' % count
        # Randomly set tone and mood up front. Ideally mood should be fit a normal distribution that's in line with one of
        # our existing corpuses. I'll come back to that later though.
        tone = random.choice(tones)
        mood = random.choice(moods) 
           
        m = construct_message(tone, mood)
        writer.write(m)
        
        if not server and count >= how_many:
            break
        
        count += 1
        if delay:
            n = random.randint(0, delay)
            print 'Going to sleep for %s seconds.' % n
            time.sleep(n)