def test_save_tickers_long(): test_max = 100 test_outfile = "test_tickers_2.txt" ticker = Tickers(test_max) ticker.outfile = test_outfile ticker.save_tickers() assert len(open(test_outfile).readlines()) <= test_max
def test_confirm_ticker(): """ Test function for Tickers.confirm_tickers() confirms if requested tickers are valid NASDAQ ticker symbols """ tick = Tickers(100) assert tick.confirm_ticker("YI") == True assert tick.confirm_ticker("Gucci") == False
def test_get_tickers(): """ Test function for Tickers.get_tickers() checks if the file has the requested number of tickers within it """ tick = Tickers(100) headers = {'Accept-Encoding': 'identity'} r = requests.get( "http://www.nasdaq.com/screening/companies" "-by-industry.aspx?exchange=NASDAQrender=download", headers=headers) ticker_list = tick.get_tickers(r) assert len(ticker_list) == 100
def test_save_tickers(): """ Test function for Tickers.save_tickers() checks if file exists after file save """ tick = Tickers(100) tick_test = Tickers(130) tick_test.save_tickers() tick.save_tickers() symbols = [] test_symbols = [] my_file = Path('./tickers.txt') assert my_file.exists()
def test_Ticker_OpenFile(): t = Tickers(100, "test.txt") file = open(t.fileName,"w") assert file != None
def test_Ticker_init1(): t = Tickers(100, "test.txt") assert 100 == t.numTickers assert "test.txt" == t.fileName
required=(parser.parse_known_args()[0].operation in ("Ticker", "Fetcher"))) parser.add_argument( "--time", type=__valid_time, help="Specify Time to Query", required=(parser.parse_known_args()[0].operation == "Query")) parser.add_argument( "--time_limit", type=int, help="...", required=(parser.parse_known_args()[0].operation == "Fetcher")) parser.add_argument("--db", type=str, help="...", required=(parser.parse_known_args()[0].operation in ("Query", "Fetcher"))) return parser.parse_args() if __name__ == '__main__': # Parse Input args = parseInput() # Execute Cooresponding Operation if args.operation == "Ticker": Tickers(args.ticker_count).save_tickers() elif args.operation == "Fetcher": Fetcher(args.db).fetch_all_data(args.time_limit) elif args.operation == "Query": Query(args.time, args.db, args.ticker).fetch_and_print()
def test_ticker(): t = Tickers(10) assert t.ticker == 'x' assert t.ticker_count == 10 assert t.check_if_valid() == True
def test_ticker_init(): for val in {0, 1, 50, 110}: ticker = Tickers(val) assert ticker.maximum == val
#These set the default if tickernum == None: tickernum = 110 if ticker == None: ticker = 'YI' if dbname == None: dbname = "stocks_new.db" if curr_time == None: curr_time = "16:32" if time_lim == None: time_lim = 120 if operation == "Ticker": ticker_count = tickernum #print(ticker_count) ticker_call = Tickers(ticker_count, "tickers.txt") ticker_call.save_tickers() elif operation == "Fetcher": fetcher_count = int(tickernum) time_count = int(time_lim) database = dbname # print(f"\nfetcher_count = {fetcher_count}\ntime_count = {time_count}\ndatabase = {database}\n") fetcher_call = Fetcher("tickers.txt", time_count, database) fetcher_call.fetch_all_data() elif operation == "Query": time_count = curr_time database = dbname # print(f"time_count = {time_count}\ndatabase = {database}\nticker_name = {ticker_name}") #print(ticker_name)
parser.add_argument("--time_limit", nargs='?', default=None, type=str, help="parameter for update time limit for Fetcher class") parser.add_argument("--time", nargs='?', default=None, type=str, help="parameter to identify the specific minute for which to print data.") parser.add_argument("--ticker", nargs='?', default=None, type=str, help="ticker: Used by the Query class to identify the specific ticker" "for which to print data") parser.add_argument("--db", nargs='?', default=None, type=str, help="parameter to specify the database file to be used.") args = parser.parse_args(args) return args if __name__ == "__main__": args = parse_args(sys.argv[1:]) d = vars(args) if d["operation"]=="Ticker" and d["ticker_count"]!=None: tickers = Tickers(int(d["ticker_count"])) tickers.save_tickers() elif d["operation"]=="Fetcher" and d["time_limit"]!=None and d["db"]!=None: fetcher = Fetcher(int(d["time_limit"]),d["db"]) fetcher.fetch_all_data() elif d["operation"]=="Query" and d["time"]!=None and d["db"]!=None and d["ticker"]!=None: query = Query(d["time"],d["db"],d["ticker"]) query.find_symbol() else: print("What you entered was not valid")
def driver(): """ a main module that takes the following flags: ∗ operation: Values are: ’Fetcher’, ’Ticker’, or ’Query’ Based on the value of this variable, you will decide which class you will instantiate and the optional arguments whose values you will need. 1. For ’Ticker’: Use the optional flag ’ticker count’ to instantiate Tickers class and then call the save tickers() function. 2. For ’Fetcher’: Use the optional flags ’db’ and ’time limit to instantiate Fetcher class and then call the fetch all data() function. 3. For ’Query’: Use the optional flags ’db’ and ’time’ and ’ticker’ to instantiate Query class and then call the function to fetch and print data from the database. The data must be printed out to the terminal when this operation is used. ∗ time: Used by the Query class to identify the specific minute for which to print data. Optional argument used only for the Query class. ∗ ticker: Used by the Query class to identify the specific ticker for which to print data. Optional argument used only for the Query class. ∗ time limit: Used by the Fetcher class to identify the length of time in seconds for which to fetch data. Optional argument used only for the Fetcher class. ∗ db: Used by the Fetcher and Query classes to specify the database file to be used. Optional argument used only for the Fetcher and Query classes. ∗ ticker count: Used only by the Tickers class to specify the number of valid tickers to be fetched. Optional argument only used by Tickers class. """ parser = argparse.ArgumentParser() parser.add_argument("--operation", help="values are: 'Fetcher', 'Ticker', 'Query'") parser.add_argument( "--time", help="used by Query to identify specific minute for which to print data" ) parser.add_argument( "--ticker", help="used by Query to identify specific ticker for which to print data" ) parser.add_argument( "--time_limit", help= "used by Fetcher class to identify the length of time in seconds for which to fetch data" ) parser.add_argument( "--db", help= "used by Fetcher and Query classes to specify database file to be used" ) parser.add_argument( "--ticker_count", help= "used by Tickers class to specify number of valid tickers to be fetched" ) args = parser.parse_args() if args.operation == "Ticker": tickers = Tickers(args.ticker_count) tickers.save_tickers() elif args.operation == "Fetcher": fetcher = Fetcher(args.db, args.time_limit) fetcher.fetch_all_data() elif args.operation == "Query": query = Query(args.db, args.time, args.ticker) query.query_ticker()