11use calamine:: { open_workbook, Xlsx } ;
22use clap:: Parser ;
3- use polars:: prelude:: * ;
43use indicatif:: ProgressBar ;
4+ use polars:: prelude:: * ;
55
66// TODO: Make progressbar
77// TODO: convert dividends derived elements into TTM data
@@ -235,8 +235,6 @@ fn get_companies_data(
235235 database : Option < String > ,
236236 target_yield : f64 ,
237237) -> Result < ( ) , & ' static str > {
238-
239-
240238 // If we have explicitly given companies then make progress bar with specific length
241239 // otherwise just make the one without length
242240 let pb = if companies. is_empty ( ) {
@@ -321,6 +319,10 @@ fn get_companies_data(
321319 df
322320 } ;
323321
322+ let use_polygon = std:: env:: var ( "POLYGON_AUTH_KEY" ) . is_ok ( ) ;
323+ let mut provider = investments_forecasting:: get_yahoo_connector ( )
324+ . map_err ( |_| "Error: Unable to create yahoo connector" ) ?;
325+
324326 let maybe_success = companies. iter ( ) . try_for_each ( |symbol| {
325327 let (
326328 share_price,
@@ -335,11 +337,12 @@ fn get_companies_data(
335337 years_of_growth,
336338 payout_ratio,
337339 sector_desc,
338- ) = if std :: env :: var ( "POLYGON_AUTH_KEY" ) . is_ok ( ) {
340+ ) = if use_polygon {
339341 investments_forecasting:: get_polygon_data ( symbol)
340342 . expect ( "Error: unable to get Data from polygon IO for forecasting" )
341343 } else {
342- investments_forecasting:: get_yahoo_data ( symbol)
344+ let myref = provider. as_mut ( ) . unwrap ( ) ;
345+ investments_forecasting:: get_yahoo_data ( symbol, myref)
343346 . expect ( "Error: unable to get Data from yahoo finance for forecasting" )
344347 } ;
345348
@@ -515,18 +518,13 @@ fn main() -> Result<(), &'static str> {
515518 None
516519 } ;
517520
518-
519-
520521 //let company = <std::string::String as AsRef<str>>::as_ref(&args.company).to_uppercase();
521522 let companies = args
522523 . company
523524 . iter ( )
524525 . map ( |x| x. to_uppercase ( ) )
525526 . collect :: < Vec < String > > ( ) ;
526527
527-
528-
529-
530528 // For no handpicked companies just make overall analysis
531529 if companies. len ( ) == 0 {
532530 if args. list_all {
0 commit comments