def insert_new_ticker(ticker, fd_class): if fd_class is not Ticker.STOCK and fd_class is not Ticker.FUND: raise TypeError('fd_class must be one of STOCK or FUND') executor = SqlExecutor() executor.exec_insert( 'INSERT INTO COMPANY (TICKER, CLASS) VALUES (?, ?)', (ticker, fd_class)) executor.close()
def delete_ticker(ticker): """ Deletes teh provided ticker if it exists in the database. This action cannot be undone. :param ticker: :return: """ found_t = Ticker.get_ticker(ticker) if found_t is None: return executor = SqlExecutor() executor.exec_insert('DELETE FROM Company WHERE TICKER=?', (ticker, )) executor.close()
def __init__(self, pickle_file): self.pickler = Pickler() self.congress_cache = CongressCache() self.president_cache = PresidentCache() self.house_member_cache = HouseMemberCache() self.senate_member_cache = SenateMemberCache() self.bill_cache = BillCache() self.sqlEx = SqlExecutor() self.pickle_file = pickle_file self.local_dir = path.dirname(path.abspath(__file__)) if self.pickle_file == 'House Members.pkl': self.congressional_body = 'House' else: self.congressional_body = 'Senate'
def do_ticker_update(ticker_name, ticker_json): update_sql_template = "UPDATE `COMPANY` " \ "SET NAME=?, DESCRIPTION=?, SECTOR=?, INDUSTRY=?, EMPLOYEES=?, REVENUE=?, NET_INCOME=?," \ "FORWARD_PE=?, TRAILING_PE=?, PRICE_TO_BOOK=?, COUNTRY=?, LAST_TARGET_PRICE=?," \ "RESOURCE_URL=?," \ "LAST_RETRIEVED=CURRENT_DATE " \ "WHERE TICKER=?;" """`PRICE_TO_BOOK` VARCHAR(50) DEFAULT NULL, `COUNTRY` VARCHAR(50) DEFAULT NULL, `LAST_TARGET_PRICE` VARCHAR(50) DEFAULT NULL""" executor = SqlExecutor() executor.exec_insert( update_sql_template, (ticker_json.get('Name'), ticker_json.get('Description'), ticker_json.get('Sector'), ticker_json.get('Industry'), ticker_json.get('FullTimeEmployees'), ticker_json.get('RevenueTTM'), ticker_json.get('GrossProfitTTM'), ticker_json.get('ForwardPE'), ticker_json.get('TrailingPE'), ticker_json.get('PriceToBookRatio'), ticker_json.get('Country'), ticker_json.get('AnalystTargetPrice'), ticker_json.get('resource_url'), ticker_name)) executor.close()
def __init__(self): self.db = SqlExecutor(db_name='gpp-long-term.db')
def _setup(self, member_table, session_table): self._member_table = member_table self._session_table = session_table self._db = SqlExecutor()
from db.SqlExecutor import SqlExecutor # TRANSCRIBE_FILE = '../../data/tickers/compiled/all_tickers.txt' TRANSCRIBE_FILE = '../../data/tickers/raw/etfs/etfs.txt' INSERT_SQL = "INSERT INTO `COMPANY` (TICKER) VALUES (?);" executor = SqlExecutor(debug=True) with open(TRANSCRIBE_FILE) as all_tickers: for ticker_text in all_tickers: ticker = ticker_text.strip() result = executor.exec_select( "SELECT COUNT(*) AS ROW_COUNT FROM `COMPANY` WHERE `TICKER`=?", (ticker, )) if result.fetchone()[0] == 1: print("Already found record for ticker %s, continuing..." % (ticker, )) continue print(ticker) executor.exec_insert(INSERT_SQL, (ticker, )) rows = executor.exec_select('SELECT COUNT(*) AS rowcount FROM COMPANY;') for row in rows: print(row[0])
def __init__(self): self.db = SqlExecutor()
def __init__(self): self.db = SqlExecutor() self.congress_cache = CongressCache()
def __init__(self): self._executor = SqlExecutor()
def get_ticker(ticker): executor = SqlExecutor() result = executor.exec_select('SELECT * FROM COMPANY WHERE TICKER=?', (ticker, )) return result.fetchone()
def get_n_stocks(n=5): executor = SqlExecutor() result = executor.exec_select( 'SELECT * FROM COMPANY WHERE CLASS=? AND NAME IS NOT NULL LIMIT ?', (Ticker.STOCK, n)) return result.fetchall()
def get_ticker_with_class(ticker, fd_class): executor = SqlExecutor() result = executor.exec_select( 'SELECT * FROM COMPANY WHERE TICKER=? AND CLASS=?', (ticker, fd_class)) return result.fetchone()