def get_quote(): pd.set_option('display.width', 200) search_quote = input("Enter stock symbol: ") try: url = 'http://dev.markitondemand.com/MODApis/Api/v2/Quote/json?symbol=' + search_quote df = pd.DataFrame([requests.get(url).json()]) print("\n") dropped_columns = ["MSDate", "Status", "Timestamp"] df1 = df.drop(dropped_columns, axis="columns") df1 = df.drop(dropped_columns, axis="columns") df2 = df1 df1 = df1.reindex( ['Symbol', 'Name', 'Open', 'LastPrice', 'Change', 'ChangePercent'], axis=1) df2 = df2.reindex([ 'Symbol', 'Low', 'High', 'MarketCap', 'ChangePercentYTD', 'ChangeYTD' ], axis=1) print("Quote for " + search_quote.upper() + " as of " + datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " UTC:\n\n") print(th.md_table(df1, formats={-1: 'c'})) print("\n" + th.md_table(df2, formats={-1: 'c'})) except: print("Server not responding. Try again later. ") time.sleep(1) pass
def leaderboard(): print("Leaderboard: \n\n") with sqlite3.connect('data.db') as db: df = pd.read_sql_query('SELECT * from stocks', db) df_1 = pd.read_sql_query('SELECT username , bankAccount from users', db) df_1.sort_values(by=['bankAccount'], inplace=True, ascending=False) df_1 = df_1.rename(columns={ 'username': "******", 'bankAccount': "Money:" }) try: df_1 = df_1.head(10) print(th.md_table(df_1, formats={-1: 'c'})) except AttributeError: print(th.md_table(df_1, formats={-1: 'c'}))
def company_search(): search = input("Enter company name or symbol to search: ") url = 'http://dev.markitondemand.com/Api/v2/Lookup/json?input=' + search data = pd.read_json(url) if data.empty: print('No results found') else: print("\nCompany Search Results:\n\n" + th.md_table(data, formats={-1: 'c'}))
def __call__(self, t_shape): import numpy as np n = t_shape[0] num_bytes = np.prod(t_shape) * self.dtype_size_bytes self.observer.stop_block(n=n, num_bytes=num_bytes) self.observer.maybe_log_progress() # Tensorboard is very picky about wanting Markdown :P import tabulatehelper as th stats = self.observer.get_stats() out = th.md_table(stats, headers=[name]) self.observer.start_block() return out
def view_portfolio(): #//TO: Use pandas to easily display portfolio with sqlite3.connect('data.db') as db: # cursor = db.cursor() df = pd.read_sql_query( 'SELECT * from stocks WHERE username="******";', db) df = df.reindex(["stockSymbol", "numShares"], axis=1) df = df.rename(columns={ 'stockSymbol': "Stocks Owned:", 'numShares': "# of Shares:" }) print("\nYour Current Portfolio:\n\n" + th.md_table(df, formats={-1: 'c'}))