77from pathlib import Path
88from typing import Any
99
10+ import humanize
11+
1012from models .cron import Cron
1113from models .errors import ConfigurationError
1214
1820 'sleep_time' : 60 ,
1921 'schedule_cron' : Cron ('* * * * *' ),
2022 'debug' : False ,
23+ 'locale' : "en_US" ,
2124 'metrics' : False ,
2225 'metrics_port' : 8000 ,
2326 'disable_tests' : False ,
7578 'url' : '' ,
7679 'method' : 'POST' ,
7780 'body' : '' ,
78- 'type' : '' ,
81+ 'type' : 'text/plain ' ,
7982 'headers' : {},
8083 'timeout' : 60 ,
8184 'cron' : Cron ('* * * * *' )
@@ -105,6 +108,7 @@ class Config():
105108 sleep_time : int
106109 schedule_cron : str
107110 debug : bool
111+ locale : str
108112 metrics : bool
109113 metrics_port : int
110114 disable_tests : bool
@@ -135,6 +139,8 @@ def __init__(self, file: str = None):
135139
136140 self .token_path = environ .get ("TGTG_TOKEN_PATH" , None )
137141 self ._load_tokens ()
142+ if (self .locale and not self .locale .startswith ('en' )):
143+ humanize .i18n .activate (self .locale )
138144
139145 def _open (self , file : str , mode : str ) -> TextIOWrapper :
140146 return open (Path (self .token_path , file ), mode , encoding = 'utf-8' )
@@ -238,6 +244,7 @@ def _read_ini(self) -> None:
238244 self ._ini_get_boolean (config , "MAIN" , "DisableTests" ,
239245 "disable_tests" )
240246 self ._ini_get_boolean (config , "MAIN" , "quiet" , "quiet" )
247+ self ._ini_get (config , "MAIN" , "locale" , "locale" )
241248
242249 self ._ini_get (config , "TGTG" , "Username" , "tgtg.username" )
243250 self ._ini_get (config , "TGTG" , "AccessToken" , "tgtg.access_token" )
@@ -350,6 +357,7 @@ def _read_env(self) -> None:
350357 self ._env_get_int ("METRICS_PORT" , "metrics_port" )
351358 self ._env_get_boolean ("DISABLE_TESTS" , "disable_tests" )
352359 self ._env_get_boolean ("QUIET" , "quiet" )
360+ self ._env_get ("LOCALE" , "locale" )
353361
354362 self ._env_get ("TGTG_USERNAME" , "tgtg.username" )
355363 self ._env_get ("TGTG_ACCESS_TOKEN" , "tgtg.access_token" )
@@ -419,7 +427,7 @@ def set(self, section: str, option: str, value: Any) -> bool:
419427 try :
420428 config = configparser .ConfigParser ()
421429 config .optionxform = str
422- config .read (self .file )
430+ config .read (self .file , encoding = 'utf-8' )
423431 if section not in config .sections ():
424432 config .add_section (section )
425433 config .set (section , option , str (value ))
@@ -440,7 +448,7 @@ def save_tokens(self, access_token: str, refresh_token: str,
440448 try :
441449 config = configparser .ConfigParser ()
442450 config .optionxform = str
443- config .read (self .file )
451+ config .read (self .file , encoding = 'utf-8' )
444452 if "TGTG" not in config .sections ():
445453 config .add_section ("TGTG" )
446454 config .set ("TGTG" , "AccessToken" , access_token )
0 commit comments