def run(self): """ 2009-9-22 add the debug section """ if self.debug: import pdb pdb.set_trace() db = StockDB(drivername=self.drivername, username=self.db_user, password=self.db_passwd, hostname=self.hostname, database=self.dbname, schema=self.schema) db.setup() session = db.session session.begin() strain_unique_key2strain = self.get_strain_unique_key2strain(session) self.splitCalls_BySeq(session, strain_unique_key2strain) if self.commit: session.commit() session.clear() else: #default is also rollback(). to demonstrate good programming session.rollback()
def run(self): """ 2008-05-15 """ if self.debug: import pdb pdb.set_trace() """ import MySQLdb conn = MySQLdb.connect(db=self.dbname, host=self.hostname, user = self.user, passwd = self.passwd) curs = conn.cursor() """ db = StockDB(drivername=self.drivername, username=self.db_user, password=self.db_passwd, hostname=self.hostname, database=self.dbname, schema=self.schema) db.setup(create_tables=False) session = db.session session.begin() #self.createEcotypeid2duplicate_view(db, self.ecotypeid2duplicate_view_name) self.createNoGenotypingEcotypeView( db, self.no_genotyping_ecotype_view_name) self.createNoGPSEcotypeView(db, self.no_gps_ecotype_view_name) genotyping_all_na_ecotypeid_duplicate_ls, genotype_run2call_ls = self.createGenotypingAllNAEcotypeTable(db, \ table_name=self.genotyping_all_na_ecotype_table, commit=self.commit) no_genotyping_ecotypeid_set = self.get_no_genotyping_ecotypeid_set( db, no_genotyping_ecotype_view_name=self. no_genotyping_ecotype_view_name) no_gps_ecotypeid_set = self.get_no_gps_ecotypeid_set( db, no_gps_ecotype_view_name=self.no_gps_ecotype_view_name) nativename_stkparent2ecotypeid_duplicate_ls, nativename_stkparent2tg_ecotypeid, ecotype_duplicate2tg_ecotypeid = \ self.createTableStructureToGroupEcotypeid(db, no_genotyping_ecotypeid_set, no_gps_ecotypeid_set, \ genotyping_all_na_ecotypeid_duplicate_ls, \ nativename_stkparent2tg_ecotypeid_table=self.nativename_stkparent2tg_ecotypeid_table, \ ecotype_duplicate2tg_ecotypeid_table=self.ecotype_duplicate2tg_ecotypeid_table, \ commit=self.commit) if self.commit: session.flush() session.commit() session.clear() else: #default is also rollback(). to demonstrate good programming session.rollback()
def main(): gc.enable() logPath = initializeLogDirectory() logging.basicConfig(filename = logPath, level = logging.DEBUG, format="%(levelname)s::%(asctime)s: %(message)s") sd = StockDB("ben", "pass", "127.0.0.1", "stockbot") sb = StockBot(sd) parser = argparse.ArgumentParser() parser.add_argument("-a", "--add", type = str, help = "Add a stock to the database.") parser.add_argument("-r", "--remove", type = str, help = "Remove a stock from the database.") parser.add_argument("--allTables", action = "store_true") #goes with remove parser.add_argument("-d", "--display", action = "store_true", help = "Display the stocks in the database.") #parser.add_argument("--run", action = "store_true", # help = "Run the stock tracker as a background process.") #parser.add_argument("--stop", action = "store_true", # help = "Stop the stock tracker background process if it is running.") args = parser.parse_args() # Handle --display command if args.display: # Will be updated to show a GUI instead of printing stock signs for stock in sd.getKeyValues('stock'): print(stock) # Handle --add command elif not args.add == None: stock = args.add.upper() yahoo = Share(stock) if not yahoo.get_price() == None: sb.postStock(stock) print("Stock '{}' posted to database.".format(stock)) logging.info("Stock '{}' posted to database.".format(stock)) else: print("Invalid stock argument passed with --add.") logging.warning("Invalid stock argument passed with --add.") # Handle --remove command elif not args.remove == None: stock = args.remove.upper() if stock in sb.stocksToMonitor: sb.removeStock(stock, args.allTables) print("Stock '{}' removed from database. allTables = {}".format(stock, args.allTables)) logging.info("Stock '{}' removed from database. allTables = {}".format(stock, args.allTables)) else: print("Invalid stock argument passed with --remove.") logging.warning("Invalid stock argument passed with --remove.") #elif args.run: # StockMonitor.main() # hopefully runs the process #elif args.stop: # x = 0 # kill the stock monitor process sd.close()
def run(self): """ 2008-05-15 """ if self.debug: import pdb pdb.set_trace() """ import MySQLdb conn = MySQLdb.connect(db=self.dbname, host=self.hostname, user = self.user, passwd = self.passwd) curs = conn.cursor() """ db = StockDB(drivername=self.drivername, username=self.db_user, password=self.db_passwd, hostname=self.hostname, database=self.dbname, schema=self.schema) db.setup(create_tables=False) session = db.session session.begin() #self.createEcotypeid2duplicate_view(db, self.ecotypeid2duplicate_view_name) self.createNoGenotypingEcotypeView(db, self.no_genotyping_ecotype_view_name) self.createNoGPSEcotypeView(db, self.no_gps_ecotype_view_name) genotyping_all_na_ecotypeid_duplicate_ls, genotype_run2call_ls = self.createGenotypingAllNAEcotypeTable(db, \ table_name=self.genotyping_all_na_ecotype_table, commit=self.commit) no_genotyping_ecotypeid_set = self.get_no_genotyping_ecotypeid_set(db, no_genotyping_ecotype_view_name=self.no_genotyping_ecotype_view_name) no_gps_ecotypeid_set = self.get_no_gps_ecotypeid_set(db, no_gps_ecotype_view_name=self.no_gps_ecotype_view_name) nativename_stkparent2ecotypeid_duplicate_ls, nativename_stkparent2tg_ecotypeid, ecotype_duplicate2tg_ecotypeid = \ self.createTableStructureToGroupEcotypeid(db, no_genotyping_ecotypeid_set, no_gps_ecotypeid_set, \ genotyping_all_na_ecotypeid_duplicate_ls, \ nativename_stkparent2tg_ecotypeid_table=self.nativename_stkparent2tg_ecotypeid_table, \ ecotype_duplicate2tg_ecotypeid_table=self.ecotype_duplicate2tg_ecotypeid_table, \ commit=self.commit) if self.commit: session.flush() session.commit() session.clear() else: #default is also rollback(). to demonstrate good programming session.rollback()