generated from geoadmin/template-service-flask
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
30 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |