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.
PB-227: Adapt script to updated excel file
- Loading branch information
Showing
1 changed file
with
27 additions
and
16 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,23 +1,34 @@ | ||
import json | ||
import argparse | ||
|
||
import pandas as pd | ||
|
||
id_range = slice(0, 3) | ||
name_range = slice(6, None) | ||
def generate_translation_file(args): | ||
id_range = slice(0, 3) | ||
source = args.input | ||
destination = args.output | ||
# read by default 1st sheet of an excel file | ||
df = pd.read_excel(source, sheet_name=0) | ||
|
||
# read by default 1st sheet of an excel file | ||
df = pd.read_excel('../../tmp/Namenliste.xlsx', sheet_name=1) | ||
print(df) | ||
json_dic = {} | ||
for index, row in df.iterrows(): | ||
string_id = row['Dateiname - D'][id_range] | ||
icon_dic = { | ||
"de": row['Text Mouseover - D'], | ||
"fr": row['Text Mouseover - F'], | ||
"it": row['Text Mouseover - I'] | ||
} | ||
json_dic["ICON_" + string_id] = icon_dic | ||
|
||
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 | ||
with open(destination, "w", encoding='utf-8') as outfile: | ||
json.dump(json_dic, outfile, indent=4) | ||
|
||
with open("../json/babs2_dictionary.json", "w", encoding='utf-8') as outfile: | ||
json.dump(json_dic, outfile, indent=4) | ||
def main(): | ||
parser = argparse.ArgumentParser(description='Create json translation file from excel file ') | ||
parser.add_argument('--input', action="store", dest='input', default=None) | ||
parser.add_argument('--output', action="store", dest='output', default=None) | ||
args = parser.parse_args() | ||
generate_translation_file(args) | ||
|
||
if __name__ == '__main__': | ||
main() |