def Stock(ticker=''): if not ticker: print "No Ticker" sys.exit(1) else: """ We create a class from the Yahoo API We set the ticker argv[1] We ask for the value of the market """ finance = YFinance() finance.link = ticker value = finance.value """ We test if value is set first if it is not we exit because the ticker is wrong We, then, test if value is set to -1 if it is we exit because we couldn't connect """ if not value: print """ You submitted a ticker that doesn't exist Please try a different ticker than %s """ % ticker sys.exit(1) if value == -1: print """ We were able to connect to the website The website might be down Please check your connection and try again. """ sys.exit(1) else: return value
if len(sys.argv) != 2: print """ Incorrect argument length Usage: sharevalue.py <ticker> """ sys.exit(1) """ We create a class from the Yahoo API We set the ticker argv[1] We ask for the value of the market """ finance = YFinance() finance.link = sys.argv[1] value = finance.value """ We test if value is set first if it is not we exit because the ticker is wrong We, then, test if value is set to -1 if it is we exit because we couldn't connect """ if not value: print """ You submitted a ticker that doesn't exist Please try a different ticker than %s """ % ( sys.argv[1]