Beispiel #1
0
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
Beispiel #2
0
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()
Beispiel #3
0
    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")
Beispiel #4
0
    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)
        query_call = Query(ticker, time_count, database)
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()