提交 4cb4929e 作者: 刘伟刚

财务数据的自动化任务修改

上级 70f8ebff
...@@ -297,6 +297,38 @@ def FBS(): ...@@ -297,6 +297,38 @@ def FBS():
r.rpush('NewsEnterpriseFbs:gnqy_socialCode', item) r.rpush('NewsEnterpriseFbs:gnqy_socialCode', item)
closeSql(cnx,cursor) closeSql(cnx,cursor)
#将IPO的国外股票代码放到redis中
def yahooCodeFromSql():
cnx_,cursor_=cnn11()
try:
gn_query = "select securities_code from sys_base_enterprise_ipo where category in ('4','5','6') "
cursor_.execute(gn_query)
gn_result = cursor_.fetchall()
gn_social_list = [item[0] for item in gn_result]
print('=======')
for item in gn_social_list:
r.rpush('NoticeEnterprise:securities_code', item)
except Exception as e:
log.info("数据查询异常")
finally:
close11(cnx_,cursor_)
#雅虎财务数据3天一次
def yahooCode_task():
# 实例化一个调度器
scheduler = BlockingScheduler()
# 每天执行一次
# scheduler.add_job(yahooCodeFromSql, 'cron', hour=0,minute=0)
#3天执行一次
scheduler.add_job(yahooCodeFromSql, 'interval', days=3)
try:
yahooCodeFromSql() # 定时开始前执行一次
scheduler.start()
except Exception as e:
print('定时采集异常', e)
pass
if __name__ == "__main__": if __name__ == "__main__":
start = time.time() start = time.time()
# NoticeEnterprise() # NoticeEnterprise()
......
...@@ -35,7 +35,9 @@ def yahooCode_task(): ...@@ -35,7 +35,9 @@ def yahooCode_task():
# 实例化一个调度器 # 实例化一个调度器
scheduler = BlockingScheduler() scheduler = BlockingScheduler()
# 每天执行一次 # 每天执行一次
scheduler.add_job(yahooCodeFromSql, 'cron', hour=0,minute=0) # scheduler.add_job(yahooCodeFromSql, 'cron', hour=0,minute=0)
#3天执行一次
scheduler.add_job(yahooCodeFromSql, 'interval', days=3)
try: try:
yahooCodeFromSql() # 定时开始前执行一次 yahooCodeFromSql() # 定时开始前执行一次
scheduler.start() scheduler.start()
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
...@@ -150,7 +150,7 @@ class YahooCaiwu(object): ...@@ -150,7 +150,7 @@ class YahooCaiwu(object):
return securitiescode return securitiescode
# 雅虎财经 # 雅虎财经
def get_content2(self,securitiescode): def get_content2(self,securitiescode):
self.logger.info(f"需要采集的股票代码{securitiescode}")
conn,cursor=self.conn11() conn,cursor=self.conn11()
try: try:
# sql1 = """select social_credit_code,securities_code,securities_short_name from sys_base_enterprise_ipo where category in ('4') """ # and stock_code = "SYNH" # sql1 = """select social_credit_code,securities_code,securities_short_name from sys_base_enterprise_ipo where category in ('4') """ # and stock_code = "SYNH"
...@@ -158,7 +158,7 @@ class YahooCaiwu(object): ...@@ -158,7 +158,7 @@ class YahooCaiwu(object):
cursor.execute(sql1) cursor.execute(sql1)
result_data = cursor.fetchall() result_data = cursor.fetchall()
except Exception as e: except Exception as e:
print("数据查询异常!") self.logger.info("数据查询异常!")
for data in result_data: for data in result_data:
try: try:
...@@ -173,7 +173,7 @@ class YahooCaiwu(object): ...@@ -173,7 +173,7 @@ class YahooCaiwu(object):
stock2=stock2[1:] stock2=stock2[1:]
url = f'https://finance.yahoo.com/quote/{stock2}/financials?p={stock2}' url = f'https://finance.yahoo.com/quote/{stock2}/financials?p={stock2}'
try: try:
print(f'正在采集:{url}') self.logger.info(f'正在采集:{url}')
self.driver.get(url) self.driver.get(url)
# 等待页面加载完成 # 等待页面加载完成
wait = WebDriverWait(self.driver, 300) wait = WebDriverWait(self.driver, 300)
...@@ -293,13 +293,13 @@ class YahooCaiwu(object): ...@@ -293,13 +293,13 @@ class YahooCaiwu(object):
try: try:
resp = requests.get(get_url) resp = requests.get(get_url)
print(resp.text) print(resp.text)
print('调用接口成功!!') self.logger.info('调用接口成功!!')
except: except:
with open('雅虎财经-财务数据_发送错误ID.txt', 'a', encoding='utf8')as f: with open('雅虎财经-财务数据_发送错误ID.txt', 'a', encoding='utf8')as f:
f.write(stock + '\n') f.write(stock + '\n')
except Exception as e: except Exception as e:
print(e) print(e)
print(f'采集:{url}失败') self.logger.info(f'采集:{url}失败')
self.driver.quit() self.driver.quit()
time.sleep(10) time.sleep(10)
self.driver=self.get_webdriver() self.driver=self.get_webdriver()
...@@ -308,7 +308,7 @@ class YahooCaiwu(object): ...@@ -308,7 +308,7 @@ class YahooCaiwu(object):
self.driver.quit() self.driver.quit()
time.sleep(10) time.sleep(10)
driver=self.get_webdriver() driver=self.get_webdriver()
print('出错,重试中!') self.logger.info('出错,重试中!')
continue continue
# driver.close() # driver.close()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论