32 lines
940 B
Python
32 lines
940 B
Python
import os
|
|
import json
|
|
def handle_arguments(arguments, config):
|
|
for index, arg in enumerate(arguments[1:]):
|
|
match arg:
|
|
case '--wpm'|'-w':
|
|
config['wpm'] = int(arguments[index+2])
|
|
case '--language'|'-l':
|
|
config['language'] = arguments[index+2]
|
|
case '--mode'|'-m':
|
|
config['mode'] = arguments[index+2]
|
|
try:
|
|
config['mode_modifier'] = int(arguments[index+3])
|
|
except ValueError:
|
|
config['mode_modifier'] = arguments[index+3]
|
|
except IndexError:
|
|
config.pop('mode_modifier',None)
|
|
case '--list-languages'|'-i':
|
|
languages = os.listdir('languages')
|
|
for lang in languages:
|
|
print(lang.replace('.json',''))
|
|
exit()
|
|
case '--list-quotes'|'-q':
|
|
with open(f'quotes/{config['language']}.json') as file:
|
|
quotes = json.load(file)
|
|
for index,quote in enumerate(quotes):
|
|
print(f'{index}: {quote['quote']} - {quote['author']}')
|
|
exit()
|
|
case _:
|
|
continue
|
|
return config
|