Skip to content

Commit

Permalink
PB-227: Adapt script to updated excel file
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJoss committed Aug 23, 2024
1 parent 2915b93 commit 80b262c
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions scripts/generate_babs_dic.py
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()

0 comments on commit 80b262c

Please sign in to comment.