Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
fae5a5c1
提交
fae5a5c1
authored
10月 08, 2023
作者:
LiuLiYuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
纳斯达克财务数据 10/8
上级
222110f7
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
17 行增加
和
21 行删除
+17
-21
nasdaq_caiwu.py
comData/caiwushuju/nasdaq_caiwu.py
+17
-21
没有找到文件。
comData/caiwushuju/nasdaq_caiwu.py
浏览文件 @
fae5a5c1
...
@@ -8,7 +8,6 @@ import pymysql
...
@@ -8,7 +8,6 @@ import pymysql
import
redis
import
redis
import
requests
import
requests
from
bs4
import
BeautifulSoup
from
bs4
import
BeautifulSoup
from
requests.adapters
import
HTTPAdapter
from
requests.packages
import
urllib3
from
requests.packages
import
urllib3
from
retry
import
retry
from
retry
import
retry
from
base
import
BaseCore
from
base
import
BaseCore
...
@@ -20,10 +19,6 @@ cnx = pymysql.connect(host='114.115.159.144', user='caiji', password='zzsn9988',
...
@@ -20,10 +19,6 @@ cnx = pymysql.connect(host='114.115.159.144', user='caiji', password='zzsn9988',
charset
=
'utf8mb4'
)
charset
=
'utf8mb4'
)
cursor
=
cnx
.
cursor
()
cursor
=
cnx
.
cursor
()
r
=
baseCore
.
r
r
=
baseCore
.
r
URL
=
'https://www.nasdaq.com/'
session
=
requests
.
session
()
session
.
mount
(
'https://'
,
HTTPAdapter
(
pool_connections
=
20
,
pool_maxsize
=
100
))
session
.
mount
(
'http://'
,
HTTPAdapter
(
pool_connections
=
20
,
pool_maxsize
=
100
))
headers
=
{
headers
=
{
'User-Agent'
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
,
'User-Agent'
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
,
}
}
...
@@ -65,7 +60,6 @@ def add_date(com_code, date_list):
...
@@ -65,7 +60,6 @@ def add_date(com_code, date_list):
# 数据发送端口
# 数据发送端口
def
sendData
(
start_time
,
social_code
,
gpdm
,
dic_info
):
def
sendData
(
start_time
,
social_code
,
gpdm
,
dic_info
):
data
=
json
.
dumps
(
dic_info
)
data
=
json
.
dumps
(
dic_info
)
# print(data)
url_baocun
=
'http://114.115.236.206:8088/sync/finance/nsdk'
url_baocun
=
'http://114.115.236.206:8088/sync/finance/nsdk'
for
nnn
in
range
(
0
,
3
):
for
nnn
in
range
(
0
,
3
):
try
:
try
:
...
@@ -106,7 +100,7 @@ def getlist(table, tableName):
...
@@ -106,7 +100,7 @@ def getlist(table, tableName):
else
:
else
:
value
=
'-'
value
=
'-'
date_
=
years
[
f
'value{i}'
]
date_
=
years
[
f
'value{i}'
]
if
date_
:
if
date_
:
date
=
date_
.
split
(
'/'
)[
2
]
+
'-'
+
date_
.
split
(
'/'
)[
0
]
+
'-'
+
\
date
=
date_
.
split
(
'/'
)[
2
]
+
'-'
+
date_
.
split
(
'/'
)[
0
]
+
'-'
+
\
date_
.
split
(
'/'
)[
1
]
date_
.
split
(
'/'
)[
1
]
list
.
append
({
f
'{tableName}'
:
name
,
'value'
:
value
,
'date'
:
date
,
})
list
.
append
({
f
'{tableName}'
:
name
,
'value'
:
value
,
'date'
:
date
,
})
...
@@ -139,13 +133,12 @@ def reviseData(lists, unit, tableName):
...
@@ -139,13 +133,12 @@ def reviseData(lists, unit, tableName):
# 获取年度财务数据
# 获取年度财务数据
def
getYear
(
start_time
,
s
ession
,
s
ocial_code
,
gpdm
):
def
getYear
(
start_time
,
social_code
,
gpdm
):
ynFirst
=
check_code
(
social_code
)
ynFirst
=
check_code
(
social_code
)
date_list
=
[]
date_list
=
[]
url
=
f
'https://api.nasdaq.com/api/company/{gpdm}/financials?frequency=1'
url
=
f
'https://api.nasdaq.com/api/company/{gpdm}/financials?frequency=1'
try
:
try
:
req
=
session
.
get
(
url
,
headers
=
headers
,
verify
=
False
)
req
=
requests
.
get
(
url
,
headers
=
headers
,
verify
=
False
)
req
.
encoding
=
req
.
apparent_encoding
data
=
req
.
json
()[
'data'
]
data
=
req
.
json
()[
'data'
]
if
data
:
if
data
:
unit
=
getUnit
(
gpdm
)
unit
=
getUnit
(
gpdm
)
...
@@ -188,8 +181,8 @@ def getYear(start_time, session, social_code, gpdm):
...
@@ -188,8 +181,8 @@ def getYear(start_time, session, social_code, gpdm):
state
=
0
state
=
0
takeTime
=
baseCore
.
getTimeCost
(
start_time
,
time
.
time
())
takeTime
=
baseCore
.
getTimeCost
(
start_time
,
time
.
time
())
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
url
,
f
'{social_code}===无年度财务数据'
)
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
url
,
f
'{social_code}===无年度财务数据'
)
except
:
except
Exception
as
e
:
log
.
error
(
f
'{social_code}===年度财务数据访问失败'
)
r
.
rpush
(
'FinanceFromNasdaq:nasdaqfinance_socialCode'
,
social_code
)
state
=
0
state
=
0
takeTime
=
baseCore
.
getTimeCost
(
start_time
,
time
.
time
())
takeTime
=
baseCore
.
getTimeCost
(
start_time
,
time
.
time
())
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
url
,
f
'{social_code}===年度财务数据访问失败'
)
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
url
,
f
'{social_code}===年度财务数据访问失败'
)
...
@@ -198,13 +191,12 @@ def getYear(start_time, session, social_code, gpdm):
...
@@ -198,13 +191,12 @@ def getYear(start_time, session, social_code, gpdm):
# 获取季度财务数据 需要判断日期是否取与年度数据日期重合,重合需要修改类型为dateFlag字段为year
# 获取季度财务数据 需要判断日期是否取与年度数据日期重合,重合需要修改类型为dateFlag字段为year
def
getQuarter
(
start_time
,
s
ession
,
s
ocial_code
,
gpdm
):
def
getQuarter
(
start_time
,
social_code
,
gpdm
):
ynFirst
=
check_code
(
social_code
)
ynFirst
=
check_code
(
social_code
)
date_list
=
[]
date_list
=
[]
url
=
f
'https://api.nasdaq.com/api/company/{gpdm}/financials?frequency=2'
url
=
f
'https://api.nasdaq.com/api/company/{gpdm}/financials?frequency=2'
try
:
try
:
req
=
session
.
get
(
url
,
headers
=
headers
,
verify
=
False
)
req
=
requests
.
get
(
url
,
headers
=
headers
,
verify
=
False
,
timeout
=
60
)
req
.
encoding
=
req
.
apparent_encoding
data
=
req
.
json
()[
'data'
]
data
=
req
.
json
()[
'data'
]
if
data
:
if
data
:
unit
=
getUnit
(
gpdm
)
unit
=
getUnit
(
gpdm
)
...
@@ -250,8 +242,9 @@ def getQuarter(start_time, session, social_code, gpdm):
...
@@ -250,8 +242,9 @@ def getQuarter(start_time, session, social_code, gpdm):
state
=
0
state
=
0
takeTime
=
baseCore
.
getTimeCost
(
start_time
,
time
.
time
())
takeTime
=
baseCore
.
getTimeCost
(
start_time
,
time
.
time
())
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
url
,
f
'{social_code}===无季度财务数据'
)
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
url
,
f
'{social_code}===无季度财务数据'
)
except
:
except
Exception
as
e
:
log
.
error
(
f
'{social_code}===季度财务数据访问失败'
)
r
.
rpush
(
'FinanceFromNasdaq:nasdaqfinance_socialCode'
,
social_code
)
log
.
error
(
f
'{social_code}=={gpdm}===季度财务数据访问失败'
)
state
=
0
state
=
0
takeTime
=
baseCore
.
getTimeCost
(
start_time
,
time
.
time
())
takeTime
=
baseCore
.
getTimeCost
(
start_time
,
time
.
time
())
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
url
,
f
'{social_code}===季度财务数据访问失败'
)
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
takeTime
,
url
,
f
'{social_code}===季度财务数据访问失败'
)
...
@@ -259,8 +252,9 @@ def getQuarter(start_time, session, social_code, gpdm):
...
@@ -259,8 +252,9 @@ def getQuarter(start_time, session, social_code, gpdm):
return
date_list
return
date_list
# 信用代码放入redis中
def
FinanceFromNasdaq
():
def
FinanceFromNasdaq
():
sql
=
"select xydm from mgzqyjwyh_list where state=2 and exchange='Nasdaq
'
;"
sql
=
"select xydm from mgzqyjwyh_list where state=2 and exchange='Nasdaq;"
cursor
.
execute
(
sql
)
cursor
.
execute
(
sql
)
finance
=
cursor
.
fetchall
()
finance
=
cursor
.
fetchall
()
finance_list
=
[
item
[
0
]
for
item
in
finance
]
finance_list
=
[
item
[
0
]
for
item
in
finance
]
...
@@ -268,14 +262,15 @@ def FinanceFromNasdaq():
...
@@ -268,14 +262,15 @@ def FinanceFromNasdaq():
r
.
rpush
(
'FinanceFromNasdaq:nasdaqfinance_socialCode'
,
item
)
r
.
rpush
(
'FinanceFromNasdaq:nasdaqfinance_socialCode'
,
item
)
print
(
'redis放入成功'
)
print
(
'redis放入成功'
)
def
getInfomation
(
social_code
):
def
getInfomation
(
social_code
):
sql
=
f
"select * from mgzqyjwyh_list where state=2 and xydm='{social_code}';"
sql
=
f
"select * from mgzqyjwyh_list where state=2 and xydm='{social_code}';"
cursor
.
execute
(
sql
)
cursor
.
execute
(
sql
)
data
=
cursor
.
fetchone
()
data
=
cursor
.
fetchone
()
return
data
return
data
def
doJob
():
def
doJob
():
session
.
get
(
URL
,
headers
=
headers
)
while
True
:
while
True
:
social_code
=
baseCore
.
redicPullData
(
'FinanceFromNasdaq:nasdaqfinance_socialCode'
)
social_code
=
baseCore
.
redicPullData
(
'FinanceFromNasdaq:nasdaqfinance_socialCode'
)
if
not
social_code
or
social_code
==
None
:
if
not
social_code
or
social_code
==
None
:
...
@@ -288,17 +283,18 @@ def doJob():
...
@@ -288,17 +283,18 @@ def doJob():
social_code
=
data_enterprise
[
6
]
social_code
=
data_enterprise
[
6
]
# print(gpdm,social_code)
# print(gpdm,social_code)
# 采集年度数据
# 采集年度数据
date_list_year
=
getYear
(
start_time
,
s
ession
,
s
ocial_code
,
gpdm
)
date_list_year
=
getYear
(
start_time
,
social_code
,
gpdm
)
# 保存年度数据到redis
# 保存年度数据到redis
add_date
(
social_code
,
date_list_year
)
add_date
(
social_code
,
date_list_year
)
# 采集季度数据
# 采集季度数据
date_list_quarter
=
getQuarter
(
start_time
,
s
ession
,
s
ocial_code
,
gpdm
)
date_list_quarter
=
getQuarter
(
start_time
,
social_code
,
gpdm
)
# 保存季度数据到redis
# 保存季度数据到redis
add_date
(
social_code
,
date_list_quarter
)
add_date
(
social_code
,
date_list_quarter
)
timeCost
=
baseCore
.
getTimeCost
(
start_time
,
time
.
time
())
timeCost
=
baseCore
.
getTimeCost
(
start_time
,
time
.
time
())
state
=
1
state
=
1
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
timeCost
,
''
,
''
)
baseCore
.
recordLog
(
social_code
,
taskType
,
state
,
timeCost
,
''
,
''
)
log
.
info
(
f
'{social_code}=={gpdm}==耗时{timeCost}'
)
log
.
info
(
f
'{social_code}=={gpdm}==耗时{timeCost}'
)
time
.
sleep
(
2
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论