def task2(self, s_url, begin, end): logger = Logger() path = '//div[@class="bd"]/ul/li[@class="position_shares"]/div/' driver = webdriver.Chrome() for url in s_url[begin:end]: logger.info(url) driver.get(url) temp = random.randint(9, 20) time.sleep(temp) list_fund_code = [url[26:32] for i in xrange(10)] try: list_stock_name = self.get_text( driver.find_elements_by_xpath( path + 'table/tbody/tr/td[1]')[0:10]) list_stock_per = self.get_text( driver.find_elements_by_xpath( path + 'table/tbody/tr/td[2]')[0:10]) sum = self.get_text( driver.find_elements_by_xpath(path + 'p/span[2]')) list_per_sum = [sum[0] for i in xrange(10)] except Exception as e: logger.error(e) continue dict_df = { u'基金代码': pd.Series(list_fund_code), u'股票名称': pd.Series(list_stock_name), u'股票占比': pd.Series(list_stock_per), u'前十持仓占比合计': pd.Series(list_per_sum) } df = pd.DataFrame(dict_df, columns=[u'基金代码', u'股票名称', u'股票占比', u'前十持仓占比合计']) print(df) # df.to_excel('./Data3/fund_position_' + str(url[26:32]) + '.xlsx', index=False) driver.close() pass
class Base: def __init__(self, master): self.name = None # "name" self.commands = [] # ["\command", ...] self.master = master self.LOG = Logger('./log', 'plugins') return def initialize(self): return def __call__(self, cmd: str, arg: Optional[str] = None) -> bool: return False def on_stop(self): return def log_info(self, msg): self.LOG.info("[%s]: %s" % (self.name, msg)) return def log_warn(self, msg): self.LOG.warn("[%s]: %s" % (self.name, msg)) return def log_error(self, msg): self.LOG.error("[%s]: %s" % (self.name, msg)) return
class Report: def __init__(self): # get the logger self.logger = Logger(log_path=Config.logdir+'/Report.log', log_level='debug', log_name='Report') self.logger.debug("logger test ok") # init sqlite self.sqlite = Sqlite() self.cap = Capture() self.logger.debug("init over") def get_available_name(self): try: result = self.sqlite.get_available_yuming_infos() return result except Exception,ex: self.logger.error("get_available_name error:%s" %(ex)) return []
class Report: def __init__(self): # get the logger self.logger = Logger(log_path=Config.logdir + '/Report.log', log_level='debug', log_name='Report') self.logger.debug("logger test ok") # init sqlite self.sqlite = Sqlite() self.cap = Capture() self.logger.debug("init over") def get_available_name(self): try: result = self.sqlite.get_available_yuming_infos() return result except Exception, ex: self.logger.error("get_available_name error:%s" % (ex)) return []
class DatabaseSync(): def __init__(self): # Config self.config = ConfigParser.RawConfigParser() self.config.read(config_filename) self.db_reload_seconds = 0 tidy_client_id = self.config.get('TidyHQ', 'client_id') tidy_client_secret = self.config.get('TidyHQ', 'client_secret') tidy_member_group = self.config.get('TidyHQ', 'group_id') tidy_domain_prefix = self.config.get('TidyHQ', 'domain_prefix') self.tidy_username = self.config.get('TidyHQ', 'username') self.tidy_password = self.config.get('TidyHQ', 'password') self.db_reload_seconds = self.config.getint('TidyHQ', 'update_interval_sec') self.push_apikey = self.config.get('Pushover', 'access_token') self.push_userkey = self.config.get('Pushover', 'user_key') log_filename = self.config.get('Logging', 'sync_filename') log_filesize = self.config.get('Logging', 'size_bytes') log_backup_count = self.config.get('Logging', 'backup_count') #print "Pushover token: " + self.push_apikey self.log = Logger(log_filename, log_filesize, log_backup_count, self.push_apikey, self.push_userkey, "HHSAccess") self.tidyhq = TidyHQController(tidy_client_id, tidy_client_secret, tidy_member_group, tidy_domain_prefix) def reload_db(self): self.tidyhq.connect_to_api(self.tidy_username, self.tidy_password) if self.tidyhq.reload_db() is False: self.log.error("DB update failed!") else: self.log.log("DB update success") def run(self): self.reload_db()