예제 #1
0
    def update_stock_info(self,ticker):
        """
        updates stock information in database for argument ticker
        """

        want = ['low', 'high', 'open', 'close', 'latestPrice', 'latestVolume']

        sys.stdout = open(os.devnull, 'w')
        updatedInfo = Stock(ticker).quote()
        sys.stdout = sys.__stdout__

        thevalues = {key:value for key, value in updatedInfo.items() if key in want}

        detime = time.strftime("%H:%M")

        conn = sqlite3.connect(self.db)
        c = conn.cursor()

        print("Opened database successfully")
        print(f"the values to insert...\n{thevalues}")
        print(type(thevalues['latestVolume']))
        c.execute("INSERT INTO STOCKDATA VALUES (?, ?, ?, ?, ?, ?, ?, ?)", (detime, ticker, thevalues['low'], thevalues['high'], thevalues['open'], thevalues['close'], thevalues['latestPrice'], thevalues['latestVolume']))


        conn.commit()
        conn.close()
예제 #2
0
    def update_stock_info(self,ticker):
        """
        updates stock information in database for argument ticker

        :type ticker : string

        :param ticker : ticker name
        """

        want = ['low', 'high', 'open', 'close', 'latestPrice', 'latestVolume']

        sys.stdout = open(os.devnull, 'w')
        updatedInfo = Stock(ticker).quote()
        sys.stdout = sys.__stdout__

        thevalues = {key:value for key, value in updatedInfo.items() if key in want}

        detime = time.strftime("%H:%M")

        conn = sqlite3.connect(self.db)
        c = conn.cursor()

        c.execute("INSERT INTO StockData VALUES (?, ?, ?, ?, ?, ?, ?, ?)", (detime, ticker, thevalues['low'], thevalues['high'], thevalues['open'], thevalues['close'], thevalues['latestPrice'], thevalues['latestVolume']))


        conn.commit()
        conn.close()