コード例 #1
0
def throws_dice(min=1, max=7):

    global list_unit_dice_throws

    for throws in range(number_of_tries):
        result_throw = utils.secret(min, max)

        if result_throw == 1:
            global dice_one
            dice_one += 1
            list_unit_dice_throws.append(1)
        elif result_throw == 2:
            global dice_two
            dice_two += 1
            list_unit_dice_throws.append(2)
        elif result_throw == 3:
            global dice_three
            dice_three += 1
            list_unit_dice_throws.append(3)
        elif result_throw == 4:
            global dice_four
            dice_four += 1
            list_unit_dice_throws.append(4)
        elif result_throw == 5:
            global dice_five
            dice_five += 1
            list_unit_dice_throws.append(5)
        elif result_throw == 6:
            global dice_six
            dice_six += 1
            list_unit_dice_throws.append(6)
コード例 #2
0
ファイル: downloadfonts.py プロジェクト: m4rc1e/gfregression
def _gf_has_family(family):
    """Check if Google Fonts has the specified font family"""
    api_url = 'https://www.googleapis.com/webfonts/v1/webfonts?key={}'.format(
        secret('GF_API_KEY'))
    r = requests.get(api_url)
    families_on_gf = [f['family'] for f in r.json()['items']]
    if family in families_on_gf:
        return True
    return False
コード例 #3
0
 def test_api_upload_media(self):
     """Test we can upload media to the media endpoint"""
     url = self.local_base_url + '/api/upload-media'
     img_path = os.path.join(os.path.dirname(__file__), 'data', 'test_img.gif')
     payload = [('files', open(img_path, 'rb'))]
     request = requests.post(url,
                             files=payload,
                             data={"uuid": "12345"},
                             headers={"Access-Token": secret("ACCESS_TOKEN")})
     self.assertEqual(request.status_code, 200)
コード例 #4
0
def googlefonts_has_families(families):
    """Check if Google Fonts has the specified font family"""
    api_url = 'https://www.googleapis.com/webfonts/v1/webfonts?key={}'.format(
        secret('GF_API_KEY'))
    r = requests.get(api_url)
    families_on_gf = [f['family'] for f in r.json()['items']]

    for family in families:
        if family not in families_on_gf:
            raise Exception(
                'Family {} does not exist on Google Fonts!'.format(family))
コード例 #5
0
def gf_families_ignore_camelcase():
    """Find family names in the GF collection which cannot be derived by
    splitting the filename using a camelcase function e.g

    VT323, PTSans.
    
    If these filenames are split, they will be V T 323 and P T Sans."""
    families = {}
    api_url = 'https://www.googleapis.com/webfonts/v1/webfonts?key={}'.format(
        secret('GF_API_KEY'))
    r = requests.get(api_url)
    for item in r.json()["items"]:
        if re.search(r"[A-Z]{2}", item['family']):
            families[item["family"].replace(" ", "")] = item["family"]
    return families
コード例 #6
0
def upload_media():
    """Media upload end point. This endpoint can be used to store data
    regarding a session. This is useful for constructing good github
    pull requests or messages.

    The gf bot will use this endpoint to upload diff images and zips
    for the CI"""
    if request.headers['Access-Token'] != secret("ACCESS_TOKEN"):
        return json.dumps({"error": "Access-Token is incorrect"})

    if 'uuid' not in request.form:
        raise Exception('No uuid specified')
    uuid = request.form['uuid']
    uploaded_files = request.files.getlist('files')
    media_dir = os.path.join(MEDIA_DIR, uuid)
    if not os.path.isdir(media_dir):
        os.mkdir(media_dir)
    paths = []
    for f in uploaded_files:
        destination = os.path.join(media_dir, f.filename)
        f.save(destination)
        paths.append(destination)
    dl_urls = [p.replace('static/', '') for p in paths]
    return json.dumps({'items': dl_urls})
コード例 #7
0
ファイル: main.py プロジェクト: felipesanches/gfregression
def upload_fonts(upload_type=None):
    """Upload fonts to diff."""
    from_api = False
    if 'api' in request.path:
        upload_type = upload_type
        from_api = True
    else:
        upload_type = request.form.get('fonts')

    if upload_type == 'googlefonts':
        family_after = family_from_user_upload(request.files.getlist('fonts_after'),
                                              FONTS_DIR)
        family_before = family_from_googlefonts(family_after.name,
                                                FONTS_DIR,
                                                api_key=secret("GF_API_KEY"),
                                                include_width_families=True)
    elif upload_type == 'user':
        family_after = family_from_user_upload(request.files.getlist('fonts_after'),
                                               FONTS_DIR)
        family_before = family_from_user_upload(request.files.getlist('fonts_before'),
                                                FONTS_DIR)

    uuid = str(uuid4())
    if DIFF_FAMILIES:
        diff = diff_families(family_before, family_after, uuid)
        diff += families_glyphs_all(family_before, family_after, uuid)
        diff += families_text(family_before, family_after, uuid)
    else:
        diff = families_glyphs_all(family_before, family_after, uuid)
        diff += families_text(family_before, family_after, uuid)
    r.table('families_diffs').insert(diff).run(g.rdb_conn)
    families = get_families(family_before, family_after, uuid)
    r.table('families').insert(families).run(g.rdb_conn)
    if from_api:
        return redirect(url_for("api_uuid_info", uuid=uuid))
    return redirect(url_for("compare", view='waterfall', uuid=uuid))