Skip to content

Commit e1f4721

Browse files
committed
更新代码
1 parent a34946a commit e1f4721

File tree

1 file changed

+0
-52
lines changed

1 file changed

+0
-52
lines changed

xianhuan/disspider/spider-project/spiders/spider_test.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -55,40 +55,6 @@ def parse(self, request, response):
5555
result['count'] = int(obj['count']) # 近一月个股研报数
5656
yield result
5757

58-
def save_data(self, items):
59-
result_list = []
60-
for i in items['data']:
61-
result = {}
62-
obj = i
63-
result['orgName'] = obj['orgName'] #机构名称
64-
result['orgSName'] = obj['orgSName'] #机构简称
65-
result['publishDate'] = obj['publishDate'] #发布日期
66-
result['predictNextTwoYearEps'] = obj['predictNextTwoYearEps'] #后年每股盈利
67-
result['title'] = obj['title'] #报告名称
68-
result['stockName'] = obj['stockName'] #股票名称
69-
result['stockCode'] = obj['stockCode'] #股票code
70-
result['orgCode'] = obj['stockCode'] #机构code
71-
result['predictNextTwoYearPe'] = obj['predictNextTwoYearPe'] #后年市盈率
72-
result['predictNextYearEps'] = obj['predictNextYearEps'] # 明年每股盈利
73-
result['predictNextYearPe'] = obj['predictNextYearPe'] # 明年市盈率
74-
result['predictThisYearEps'] = obj['predictThisYearEps'] #今年每股盈利
75-
result['predictThisYearPe'] = obj['predictThisYearPe'] #今年市盈率
76-
result['indvInduCode'] = obj['indvInduCode'] # 行业代码
77-
result['indvInduName'] = obj['indvInduName'] # 行业名称
78-
result['lastEmRatingName'] = obj['lastEmRatingName'] # 上次评级名称
79-
result['lastEmRatingValue'] = obj['lastEmRatingValue'] # 上次评级代码
80-
result['emRatingValue'] = obj['emRatingValue'] # 评级代码
81-
result['emRatingName'] = obj['emRatingName'] # 评级名称
82-
result['ratingChange'] = obj['ratingChange'] # 评级变动
83-
result['researcher'] = obj['researcher'] # 研究员
84-
result['encodeUrl'] = obj['encodeUrl'] # 链接
85-
result['count'] = int(obj['count']) # 近一月个股研报数
86-
87-
result_list.append(result)
88-
89-
self.insertdb(result_list)
90-
91-
return result_list
9258

9359
def download_midware(self, request):
9460
request.headers = {
@@ -104,23 +70,5 @@ def validate(self, request, response):
10470
raise Exception("response code not 200") # 重试
10571

10672

107-
def insertdb(self, data_list):
108-
attrs = ['title', 'stockName', 'stockCode', 'orgCode', 'orgName', 'orgSName', 'publishDate', 'predictNextTwoYearEps',
109-
'predictNextTwoYearPe', 'predictNextYearEps', 'predictNextYearPe', 'predictThisYearEps', 'predictThisYearPe',
110-
'indvInduCode', 'indvInduName', 'lastEmRatingName', 'lastEmRatingValue', 'emRatingValue',
111-
'emRatingName', 'ratingChange', 'researcher', 'encodeUrl', 'count']
112-
insert_tuple = []
113-
for obj in data_list:
114-
insert_tuple.append((obj['title'], obj['stockName'], obj['stockCode'], obj['orgCode'], obj['orgName'], obj['orgSName'], obj['publishDate'], obj['predictNextTwoYearEps'], obj['predictNextTwoYearPe'], obj['predictNextYearEps'], obj['predictNextYearPe'], obj['predictThisYearEps'], obj['predictThisYearPe'], obj['indvInduCode'], obj['indvInduName'], obj['lastEmRatingName'], obj['lastEmRatingValue'], obj['emRatingValue'],obj['emRatingName'], obj['ratingChange'], obj['researcher'], obj['encodeUrl'], obj['count']))
115-
values_sql = ['%s' for v in attrs]
116-
attrs_sql = '('+','.join(attrs)+')'
117-
values_sql = ' values('+','.join(values_sql)+')'
118-
sql = 'insert into %s' % 'report'
119-
sql = sql + attrs_sql + values_sql
120-
121-
self.db.add_batch(sql, insert_tuple)
122-
123-
124-
12573
if __name__ == "__main__":
12674
SpiderTest(redis_key="spider:report").start()

0 commit comments

Comments
 (0)