Esempio n. 1
0
def test_fetcher():
    current_time = str(datetime.datetime.now())
    current_time = current_time[11::16]
    f = Fetcher(10,"test.db",30)
    f.fetch_all_data()
    q = Query(current_time,"test.db",'YI')
    assert q.get_data() != None
def test_fetcher():
    """
    Test function for Fetcher.fetch_all_data()
    Will check to see that fetch_all_data is logging a ticker value at
    the current time.

    Potential edge case for test failure if fetch.get_time and fetch_all_data
    are executed as the minute value for our current time changes
    """
    fetch = Fetcher(10,"stocks.db")
    time = fetch.get_time()
    fetch.fetch_all_data()
    
    query = Query(time,"stocks.db","YI")
    result = query.find_symbol()
    comp = time = 'Time: '+time
    assert comp == result[0]
def test_fetch_all_data():
    """
    will test fetch all data by ensuring the boolean variable that signals 
    fetch_all_data has run for the correct amount of time is True, signifying 
    the function ran as it should
    """
    fetcher1 = Fetcher('stocks_now3.db', 130)
    assert fetcher1.fetch_all_data() == True
Esempio n. 4
0
    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)

        data = query_call.Get_Datails()
        columns = [
            "Time", "Ticker", "Low", "High", "Open", "Close", "Price", "Volume"
        ]

        if data != None:
            zipped = zip(columns, data)
Esempio n. 5
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")
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()