Skip to content

Commit

Permalink
PB-227: Update formating
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJoss committed Jan 22, 2024
1 parent 8fc110f commit 1304b40
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
14 changes: 8 additions & 6 deletions app/helpers/translation.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import json
import os

from app.settings import JSON_FOLDER


def get_icon_set_translation(icon_set=''):
path = os.path.abspath(os.path.join(JSON_FOLDER, icon_set + '_dictionary.json'))
if(not(os.path.isfile(path))):
if not os.path.isfile(path):
return False
else: return True
return True


def get_icon_translation(icon_name='', icon_set=''):
path = os.path.abspath(os.path.join(JSON_FOLDER, icon_set + '_dictionary.json'))
if(not(os.path.isfile(path))):
if not os.path.isfile(path):
return False

with open(path) as f:
with open(path, encoding='utf-8') as f:
df = json.load(f)

id = icon_name[0:3]
icon_translation = df['ICON_'+id]
icon_translation = df['ICON_' + icon_name[0:3]]
return icon_translation
2 changes: 1 addition & 1 deletion app/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from flask import url_for

from app.helpers.icons import get_icon_template_url
from app.helpers.url import get_base_url
from app.helpers.translation import get_icon_translation
from app.helpers.url import get_base_url
from app.settings import DEFAULT_COLOR
from app.settings import IMAGE_FOLDER

Expand Down
2 changes: 1 addition & 1 deletion app/icon_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from flask import url_for

from app.helpers.icons import get_icon_set_template_url
from app.helpers.url import get_base_url
from app.helpers.translation import get_icon_set_translation
from app.helpers.url import get_base_url
from app.icon import Icon
from app.settings import COLORABLE_ICON_SETS
from app.settings import IMAGE_FOLDER
Expand Down
25 changes: 12 additions & 13 deletions scripts/generate_babs_dic.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@

import json
import os

import pandas as pd

id_range = slice(0,3)
name_range = slice(6,None)
id_range = slice(0, 3)
name_range = slice(6, None)

# read by default 1st sheet of an excel file
df = pd.read_excel('../../tmp/Namenliste.xlsx',sheet_name=1)
df = pd.read_excel('../../tmp/Namenliste.xlsx', sheet_name=1)
print(df)

json_dic = {}
for index, row in df.iterrows():
string_id=row['D'][id_range]
icon_dic={
"de": row['D'][name_range].split('.svg')[0],
"fr": row['F'][name_range].split('.svg')[0],
"it": row['I'][name_range].split('.svg')[0]
}
json_dic["ICON_"+string_id]=icon_dic
string_id = row['D'][id_range]
icon_dic = {
"de": row['D'][name_range].split('.svg')[0],
"fr": row['F'][name_range].split('.svg')[0],
"it": row['I'][name_range].split('.svg')[0]
}
json_dic["ICON_" + string_id] = icon_dic

with open("../json/babs2_dictionary.json", "w") as outfile:
with open("../json/babs2_dictionary.json", "w", encoding='utf-8') as outfile:
json.dump(json_dic, outfile, indent=4)
2 changes: 1 addition & 1 deletion tests/unit_tests/test_all_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_all_icon_metadata_endpoint(self):
self.assertIn('icon_set', json_response)
self.assertEqual(icon_set_name, json_response['icon_set'])
self.assertIn('title', json_response)
if(json_response['title']):
if json_response['title']:
self.assertIn('de', json_response['title'])
self.assertIn('fr', json_response['title'])
self.assertIn('it', json_response['title'])
Expand Down
14 changes: 7 additions & 7 deletions tests/unit_tests/test_json.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import json
import os

from app.settings import JSON_FOLDER
from tests.unit_tests.base_test import ServiceIconsUnitTests

from app.settings import JSON_FOLDER

def validateJSON(jsonData):
def validate_json(json_file):
try:
json.loads(jsonData)
json.loads(json_file)
except ValueError as err:
return False
return True


class IconsTests(ServiceIconsUnitTests):

def test_json(self):
path = os.path.abspath(os.path.join(JSON_FOLDER, 'babs2_dictionary.json'))
self.assertTrue(os.path.exists(path),"babs2 json file doesn't exist")
self.assertTrue(os.path.exists(path), "babs2 json file doesn't exist")

for root, dirs, files in os.walk(os.path.join(JSON_FOLDER)):
for name in files:
p = os.path.join(root, name)
with open(p) as f:
with open(p, encoding='utf-8') as f:
json_file = f.read()
self.assertTrue(validateJSON(json_file),"json file validation failed")

self.assertTrue(validate_json(json_file), "json file validation failed")

0 comments on commit 1304b40

Please sign in to comment.