Exemplo 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_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
def test___fetcher__():
    fetcher1 = Fetcher('stocks_now1.db', 90)
    fetcher2 = Fetcher('stocks_now2.db', 60)
    assert fetcher1.db == 'stocks_now1.db'
    assert fetcher2.db == 'stocks_now2.db'
    assert fetcher1.time_limit == 90
    assert fetcher2.time_limit == 60
    assert fetcher1.tickers != []
    assert fetcher2.tickers != []
Exemplo n.º 4
0
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]
Exemplo n.º 5
0
def test_fetcher_fetch_all_data_long():
    testName = "test.db"
    Fetcher(testName).fetch_all_data(60)
    dbConnection = sqlite3.connect(testName)
    dbCursor = dbConnection.cursor()
    dbCursor.execute("SELECT * FROM StockData")
    rows = dbCursor.fetchall()
    dbConnection.close()
    assert len(rows) > 100
Exemplo n.º 6
0
def test_Fetcher_init1():
    f = Fetcher("test.txt", 300, "test.db")
    assert "test.txt" == f.inputFile
    assert 300 == f.timeLimit
    assert "test.db" == f.DBname
Exemplo n.º 7
0
        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()
Exemplo n.º 8
0
        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)

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

        if data != None:
Exemplo n.º 9
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")
Exemplo n.º 10
0
def test_fetcher_makeTimeString_minor():
    time_string = Fetcher().makeTimeString(2,1)
    assert time_string == "02:01"
Exemplo n.º 11
0
def test_fetcher_init():
    testName = "file.db"
    ticker = Fetcher(testName)
    assert ticker.outfile == testName
Exemplo n.º 12
0
def test_fetcher_makeTimeString_major():
    time_string = Fetcher().makeTimeString(22,55)
    assert time_string == "22:55"
def test_create_db():
    fetcher1 = Fetcher('stocks_now3.db', 300)
    assert fetcher1.hasDB == True
def test_read_tickers():
    fetcher1 = Fetcher('stocks_now1.db', 90)
    fetcher1.read_tickers()
    assert fetcher1.tickers != []
Exemplo n.º 15
0
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()