|
@@ -0,0 +1,163 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+
|
|
|
+from content_spider.baseSpider import baseSpider
|
|
|
+from content_spider.baseSpider import baseUpdateSpider
|
|
|
+from content_spider.baseSpider import fixChapterSpider
|
|
|
+from content_spider.baseSpider import baseUpdateBookStatusSpider
|
|
|
+import time
|
|
|
+import json
|
|
|
+
|
|
|
+
|
|
|
+name = 'nanjingluochen'
|
|
|
+allowed_domains = ['cp.api.luochen.com']
|
|
|
+source = 'zy_nanjingluochen'
|
|
|
+source_name = '南京落尘'
|
|
|
+source_id = 46
|
|
|
+base_url = 'http://cp.api.luochen.com/interface/Zhuishuyun/{}'
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def get_category(channel,sort_name):
|
|
|
+
|
|
|
+ if int(channel) == 0:
|
|
|
+ if sort_name in ['玄幻','修真','仙侠','武侠','科幻']:
|
|
|
+ return {'channel_id':1,'category_id':'武侠仙侠','category_id':21}
|
|
|
+ if sort_name in ['都市','职场','豪门','总裁','青春','纯爱','乡土']:
|
|
|
+ return {'channel_id':1,'category_id':'都市爱情','category_id':54}
|
|
|
+ if sort_name in ['架空','穿越','历史','军事']:
|
|
|
+ return {'channel_id':1,'category_id':'历史穿越','category_id':14}
|
|
|
+ if sort_name in ['宫斗','宅斗','同人','短篇']:
|
|
|
+ return {'channel_id':1,'category_id':'其他','category_id':127}
|
|
|
+ if sort_name == '游戏':
|
|
|
+ return {'channel_id':1,'category_id':'游戏竞技','category_id':19}
|
|
|
+ if sort_name == '灵异' or sort_name == '悬疑':
|
|
|
+ return {'channel_id':1,'category_id':'灵异恐怖','category_id':81}
|
|
|
+
|
|
|
+ return {'channel_id':1,'category_id':'都市爱情','category_id':54}
|
|
|
+ else:
|
|
|
+ if sort_name in ['婚恋','职场','豪门','总裁']:
|
|
|
+ return {'channel_id':2,'category_id':'婚恋情感','category_id':98}
|
|
|
+
|
|
|
+ if sort_name in ['架空','穿越']:
|
|
|
+ return {'channel_id':2,'category_id':'穿越重生','category_id':83}
|
|
|
+
|
|
|
+ if sort_name in ['宫斗','宅斗']:
|
|
|
+ return {'channel_id':2,'category_id':'宫斗宅斗','category_id':120}
|
|
|
+
|
|
|
+ if sort_name in ['仙侠','修真','玄幻','武侠']:
|
|
|
+ return {'channel_id':2,'category_id':'东方玄幻','category_id':96}
|
|
|
+
|
|
|
+ if sort_name in ['灵异','悬疑']:
|
|
|
+ return {'channel_id':2,'category_id':'悬疑探险','category_id':113}
|
|
|
+
|
|
|
+ if sort_name in ['青春','乡土','纯爱']:
|
|
|
+ return {'channel_id':2,'category_id':'青春纯爱','category_id':103}
|
|
|
+
|
|
|
+ if sort_name in ['历史','同人','短篇']:
|
|
|
+ return {'channel_id':2,'category_id':'其他','category_id':107}
|
|
|
+
|
|
|
+ return {'channel_id':2,'category_id':'婚恋情感','category_id':98}
|
|
|
+
|
|
|
+
|
|
|
+class nanjingluochenProcess():
|
|
|
+ name = name
|
|
|
+ allowed_domains = allowed_domains
|
|
|
+ source = source
|
|
|
+ source_name = source_name
|
|
|
+ source_id = source_id
|
|
|
+
|
|
|
+
|
|
|
+ def get_start_url(self):
|
|
|
+ return base_url.format('booklist')
|
|
|
+
|
|
|
+ def bid_list_result(self, response):
|
|
|
+ result = json.loads(response.text)
|
|
|
+ if result is None or result.get('books') is None:
|
|
|
+ return []
|
|
|
+ result_list = []
|
|
|
+ for item in result['books']:
|
|
|
+ result_list.append({'id': item['bid']})
|
|
|
+ return result_list
|
|
|
+
|
|
|
+ def get_book_info_url(self, bid):
|
|
|
+ return base_url.format('bookInfo/') + '?bid={}'.format(bid)
|
|
|
+
|
|
|
+ def book_info_result(self, response):
|
|
|
+ result = json.loads(response.text)
|
|
|
+ category_info = get_category(result['channel'],result['category']);
|
|
|
+ return {
|
|
|
+ 'bid': result['id'], 'name': result['title'], 'author': result['author'],
|
|
|
+ 'intro': result['summary'], 'cover': result['cover'], 'keyword': result['tag'],
|
|
|
+ 'status': result['isFull'], 'category': category_info['category_name'],'category_id':category_info['category_id'],
|
|
|
+ 'channel': category_info['channel_id']
|
|
|
+ }
|
|
|
+
|
|
|
+ def get_chapter_list_url(self, bid):
|
|
|
+ return base_url.format('chapterList/') + '?bid={}'.format(bid)
|
|
|
+
|
|
|
+ def chapter_list_result(self, response):
|
|
|
+ result = json.loads(response.text)
|
|
|
+ if result is None or result.get('chapters') is None:
|
|
|
+ return []
|
|
|
+
|
|
|
+ result_list = []
|
|
|
+ i = 0
|
|
|
+ for chapter_item in result['chapters']:
|
|
|
+ i = i+1
|
|
|
+ result_list.append({
|
|
|
+ 'source_chapter_id': chapter_item['id'], 'name': chapter_item['title'],
|
|
|
+ 'sequence': chapter_item['chapterOrder'], 'is_vip': chapter_item['isVip'],
|
|
|
+ 'size': chapter_item['chapterLength'], 'recent_update_at': chapter_item['updatetime']
|
|
|
+ })
|
|
|
+ return result_list
|
|
|
+
|
|
|
+ def get_chapter_content_url(self, bid, cid):
|
|
|
+ return base_url.format('chapterContent/') + '?bid={}&cid={}'.format(bid, cid)
|
|
|
+
|
|
|
+ def chapter_content_result(self, response):
|
|
|
+ result = json.loads(response.text)
|
|
|
+ if result is None:
|
|
|
+ return {'content': ''}
|
|
|
+
|
|
|
+ return {
|
|
|
+ 'content': result['content']
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+class nanjingluochenSpider(nanjingluochenProcess,baseSpider):
|
|
|
+ name = name
|
|
|
+ custom_settings = {
|
|
|
+ 'DOWNLOAD_DELAY': 0.1,
|
|
|
+ 'SOURCE': source,
|
|
|
+ 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+class nanjingluochenUpdateSpider(nanjingluochenProcess,baseUpdateSpider):
|
|
|
+ name = name + "update"
|
|
|
+ custom_settings = {
|
|
|
+ 'DOWNLOAD_DELAY': 0.1,
|
|
|
+ 'SOURCE': source,
|
|
|
+ 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class nanjingluochenFixSpider(nanjingluochenProcess,fixChapterSpider):
|
|
|
+ name = name + 'fix'
|
|
|
+ custom_settings = {
|
|
|
+ 'DOWNLOAD_DELAY': 0.1,
|
|
|
+ 'SOURCE': source,
|
|
|
+ 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+class xingheyueduBookInfoSpider(xingheyueduProcess,baseUpdateBookStatusSpider):
|
|
|
+ name = name + "bookinfo"
|
|
|
+ custom_settings = {
|
|
|
+ 'DOWNLOAD_DELAY': 0.1,
|
|
|
+ 'SOURCE': source,
|
|
|
+ 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
|
|
|
+ }
|