Пример #1
0
def zebra_img():
    if request.method == 'GET':
        return helper.render_doc_template(request.url_rule.rule)
    check_request()
    json_in = request.json
    REQUEST_URL = os.path.join(BASE_API_URL, 'match',
                               str(json_in['event_key']) + '_' + str(json_in['match_key']), 'zebra_motionworks')
    CACHE_CONST = 'event/' + json_in['event_key'] + '/'

    json_in['red_relative_keys'].sort()

    filename = json_in['match_key'] + \
        str(json_in['red_relative_keys']) + '.png'

    full_path = os.path.join(cache_folder, CACHE_CONST, filename)

    try:
        if not os.path.exists(full_path):
            storage.child(full_path).download(full_path)
    except:
        None

    if os.path.exists(full_path):
        return flask.send_file(filename_or_fp=full_path, mimetype='image/png')

    helper.plot_data(
        json_in['event_key'], json_in['match_key'], os.path.join(cache_folder, CACHE_CONST), json_in['red_relative_keys'], fout=filename)

    # Put File on Firebase
    storage.child('/')
    storage.child(full_path).put(full_path)

    return flask.send_file(filename_or_fp=full_path, mimetype='image/png')
Пример #2
0
def events():
    if request.method == 'GET':
        return helper.render_doc_template(request.url_rule.rule)
    check_request()
    CACHE_CONST = 'event'
    json_in = request.json
    REQUEST_URL = os.path.join(BASE_API_URL, 'events',
                               str(json_in['year']), 'simple')

    if not check_key():
        return abort(403)

    filename = str(json_in['year']) + '.events.all.txt'
    txt, update = update_cache(
        (os.path.join(cache_folder, CACHE_CONST, filename)), REQUEST_URL)

    if not update:
        return jsonify(txt), 200

    r = requests.get(
        url=REQUEST_URL,
        headers=auth_headers())
    if r.status_code == 404:
        abort(404)

    all_data = []
    r = r.json()
    print(r)
    for item in r:
        all_data.append({'name': item['name'], 'key': item['key']})
    write_to_file(all_data, os.path.join(
        cache_folder, CACHE_CONST), filename)
    return jsonify(all_data), 200
Пример #3
0
def event_teams():
    if request.method == 'GET':
        return helper.render_doc_template(request.url_rule.rule)
    check_request()
    CACHE_CONST = 'event'
    json_in = request.json
    REQUEST_URL = os.path.join(BASE_API_URL, 'event',
                               json_in['event_key'], 'teams')
    if not check_key():
        return jsonify(["Not Allowed, please use a valid API Key"]), 403

    filename = json_in['event_key'] + '.txt'
    txt,  update = update_cache(os.path.join(
        cache_folder, CACHE_CONST, filename), REQUEST_URL)
    if not update:
        return jsonify(txt), 200

    r = requests.get(url=REQUEST_URL, headers=auth_headers())
    if r.status_code == 404:
        abort(404)

    all_data = []
    r = r.json()
    for item in r:
        all_data.append(simplify_data(item))
    write_to_file(all_data, os.path.join(cache_folder, CACHE_CONST), filename)

    return jsonify(all_data), 200
Пример #4
0
def teams():
    if request.method == 'GET':
        return helper.render_doc_template(request.url_rule.rule)
    check_request()
    CACHE_CONST = 'teams'
    json_in = request.json
    if not check_key():
        return jsonify(["Not Allowed, please use a valid API Key"]), 403
    return jsonify(get_teams(str(json_in['year']), CACHE_CONST)), 200
Пример #5
0
def get_matches():
    if request.method == 'GET':
        return helper.render_doc_template(request.url_rule.rule)
    check_request()
    CACHE_CONST = 'event'
    json_in = request.json
    REQUEST_URL = os.path.join(BASE_API_URL, 'event', json_in['event_key'],
                               'matches', 'simple')

    if not check_key():
        return abort(403)

    filename = json_in['event_key'] + '.matches.' + json_in[
        'comp_level'] + '.' + str(json_in['uses_sets']) + '.txt'

    # REGEX_PATTERN = re.compile("(^\w+_" + json_in['comp_level'] + "\d+)$")

    txt, update = update_cache(
        os.path.join(cache_folder, CACHE_CONST, filename), REQUEST_URL)

    if not update:
        return jsonify(txt), 200

    r = requests.get(
        url=REQUEST_URL,
        headers=auth_headers())
    if r.status_code == 404:
        abort(404)

    all_data = {}
    r = r.json()
    for item in r:
        if item['comp_level'] == json_in['comp_level']:
            match_data = {}
            insert_val = ''
            if json_in['uses_sets']:
                insert_val = str(item['set_number']) + \
                    ',' + str(item['match_number'])
            else:
                if(json_in['comp_level'] == 'qf' or json_in['comp_level'] == 'sf'):
                    return jsonify(["cannot use numbers for qf or sf due to ties and rematches"]), 404
                insert_val = str(item['set_number']*item['match_number'])
            all_data[insert_val] = match_data
            alliances = item['alliances']
            match_data['blue'] = process_team_keys(
                alliances['blue']['team_keys'])
            match_data['red'] = process_team_keys(
                alliances['red']['team_keys'])
    write_to_file(all_data, os.path.join(cache_folder, CACHE_CONST), filename)
    return jsonify(all_data), 200