258
258
"southeast_asia" : ["KH" , "ID" , "LA" , "MY" , "PH" , "SG" , "TH" , "VN" ],
259
259
}
260
260
261
- INDICATORS_DESCRIPTIONS = json .load (
262
- (files ("openbb_econdb.utils" ) / "indicators_descriptions.json" ).open ()
263
- )
264
- MULTIPLIERS = json .load ((files ("openbb_econdb.utils" ) / "multipliers.json" ).open ())
265
- SCALES = json .load ((files ("openbb_econdb.utils" ) / "scales.json" ).open ())
266
- UNITS = json .load ((files ("openbb_econdb.utils" ) / "units.json" ).open ())
267
- INDICATOR_COUNTRIES = json .load (
268
- (files ("openbb_econdb.utils" ) / "indicator_countries.json" ).open ()
269
- )
270
- SYMBOL_TO_INDICATOR = json .load (
271
- (files ("openbb_econdb.utils" ) / "symbol_to_indicator.json" ).open ()
272
- )
261
+ with (files ("openbb_econdb.utils" ) / "indicators_descriptions.json" ).open () as f :
262
+ INDICATORS_DESCRIPTIONS = json .load (f )
263
+
264
+ with (files ("openbb_econdb.utils" ) / "multipliers.json" ).open () as f :
265
+ MULTIPLIERS = json .load (f )
266
+
267
+ with (files ("openbb_econdb.utils" ) / "scales.json" ).open () as f :
268
+ SCALES = json .load (f )
269
+
270
+ with (files ("openbb_econdb.utils" ) / "units.json" ).open () as f :
271
+ UNITS = json .load (f )
272
+
273
+ with (files ("openbb_econdb.utils" ) / "symbol_to_indicator.json" ).open () as f :
274
+ SYMBOL_TO_INDICATOR = json .load (f )
275
+
276
+ with (files ("openbb_econdb.utils" ) / "indicator_countries.json" ).open () as f :
277
+ INDICATOR_COUNTRIES = json .load (f )
278
+
273
279
HAS_COUNTRIES = {
274
280
d : INDICATOR_COUNTRIES .get (d ) != ["W00" ] for d in INDICATORS_DESCRIPTIONS
275
281
}
@@ -622,28 +628,44 @@ def update_symbol_to_indicator() -> None:
622
628
"w" , # type: ignore
623
629
encoding = "utf-8" ,
624
630
) as f :
625
- indicators .set_index ("short_ticker" ).sort_index ()["symbol_root" ].to_json (f )
631
+ json_data = json .dumps (
632
+ indicators .set_index ("short_ticker" )
633
+ .sort_index ()["symbol_root" ]
634
+ .to_dict ()
635
+ )
636
+ f .write (json_data )
626
637
627
638
def update_multipliers () -> None :
628
639
"""Update the unit multipliers."""
629
640
with open ( # type: ignore
630
641
files ("openbb_econdb.utils" ) / "multipliers.json" , "w" , encoding = "utf-8"
631
642
) as f :
632
- indicators .set_index ("short_ticker" ).sort_index ()["multiplier" ].to_json (f )
643
+ json_data = json .dumps (
644
+ indicators .set_index ("short_ticker" )
645
+ .sort_index ()["multiplier" ]
646
+ .to_dict ()
647
+ )
648
+ f .write (json_data )
633
649
634
650
def update_scales () -> None :
635
651
"""Update the scales."""
636
652
with open ( # type: ignore
637
653
files ("openbb_econdb.utils" ) / "scales.json" , "w" , encoding = "utf-8"
638
654
) as f :
639
- indicators .set_index ("short_ticker" ).sort_index ()["scale" ].to_json (f )
655
+ json_data = json .dumps (
656
+ indicators .set_index ("short_ticker" ).sort_index ()["scale" ].to_dict ()
657
+ )
658
+ f .write (json_data )
640
659
641
660
def update_units () -> None :
642
661
"""Update the units."""
643
662
with open ( # type: ignore
644
663
files ("openbb_econdb.utils" ) / "units.json" , "w" , encoding = "utf-8"
645
664
) as f :
646
- indicators .set_index ("short_ticker" ).sort_index ()["currency" ].to_json (f )
665
+ json_data = json .dumps (
666
+ indicators .set_index ("short_ticker" ).sort_index ()["currency" ].to_dict ()
667
+ )
668
+ f .write (json_data )
647
669
648
670
def update_descriptions () -> None :
649
671
"""Update the indicator descriptions."""
@@ -656,7 +678,8 @@ def update_descriptions() -> None:
656
678
"w" ,
657
679
encoding = "utf-8" ,
658
680
) as f :
659
- json .dump (descriptions_dict , f )
681
+ json_data = json .dumps (descriptions_dict )
682
+ f .write (json_data )
660
683
661
684
def update_indicator_countries () -> None :
662
685
"""Update the indicator countries."""
@@ -665,9 +688,13 @@ def update_indicator_countries() -> None:
665
688
"w" ,
666
689
encoding = "utf-8" ,
667
690
) as f :
668
- indicators [indicators ["symbol_root" ] != "[W00]" ].groupby ("symbol_root" )[
669
- "iso"
670
- ].apply (lambda x : x .sort_values ().unique ().tolist ()).to_json (f )
691
+ json_data = json .dumps (
692
+ indicators [indicators ["symbol_root" ] != "[W00]" ]
693
+ .groupby ("symbol_root" )["iso" ]
694
+ .apply (lambda x : x .sort_values ().unique ().tolist ())
695
+ .to_dict ()
696
+ )
697
+ f .write (json_data )
671
698
672
699
update_symbol_to_indicator ()
673
700
update_multipliers ()
0 commit comments