futian.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # -*- coding: utf-8 -*-
  2. from content_spider.baseSpider import baseSpider
  3. from content_spider.baseSpider import baseUpdateSpider
  4. from content_spider.baseSpider import fixChapterSpider
  5. from content_spider.baseSpider import baseUpdateBookStatusSpider
  6. import time
  7. import json
  8. name = 'futian'
  9. allowed_domains = ['www.futian.com']
  10. source = 'zy_futian'
  11. source_name = 'futian伏天 '
  12. source_id = 32
  13. base_url = 'http://www.futianbook.com/api/json'
  14. apikey = '3399b12e976734c318754c24b5b5dfd0'
  15. category = [
  16. {
  17. "channel_id": 1,
  18. "channel_name": "男频",
  19. "cate_id": 1,
  20. "cate_name": "现代都市",
  21. "category_id":"54",
  22. "category_name":"都市爱情"
  23. },
  24. {
  25. "channel_id": 1,
  26. "channel_name": "男频",
  27. "cate_id": 2,
  28. "cate_name": "悬疑灵异",
  29. "category_id":"81",
  30. "category_name":"灵异恐怖"
  31. }
  32. {
  33. "channel_id": 1,
  34. "channel_name": "男频",
  35. "cate_id": 3,
  36. "cate_name": "玄幻仙侠",
  37. "category_id":"21",
  38. "category_name":"武侠仙侠"
  39. },
  40. {
  41. "channel_id": 1,
  42. "channel_name": "男频",
  43. "cate_id": 4,
  44. "cate_name": "历史军事",
  45. "category_id":"51",
  46. "category_name":"特种军旅"
  47. },
  48. {
  49. "channel_id": 1,
  50. "channel_name": "男频",
  51. "cate_id": 5,
  52. "cate_name": "体育电竞",
  53. "category_id":"19",
  54. "category_name":"游戏竞技"
  55. },
  56. {
  57. "channel_id": 1,
  58. "channel_name": "男频",
  59. "cate_id": 6,
  60. "cate_name": "科幻末日",
  61. "category_id":"23",
  62. "category_name":"玄幻奇幻"
  63. }
  64. {
  65. "channel_id": 1,
  66. "channel_name": "男频",
  67. "cate_id": 7,
  68. "cate_name": "同人其他",
  69. "category_id":"127",
  70. "category_name":"其他"
  71. },
  72. {
  73. "channel_id": 2,
  74. "channel_name": "女频",
  75. "cate_id": 8,
  76. "cate_name": "现代言情",
  77. "category_id":"87",
  78. "category_name":"婚恋情感"
  79. },
  80. {
  81. "channel_id": 2,
  82. "channel_name": "女频",
  83. "cate_id": 8,
  84. "cate_name": "古代言情",
  85. "category_id":"83",
  86. "category_name":"穿越重生"
  87. }
  88. ]
  89. def get_category(category_name):
  90. for item in category:
  91. if category_name == item['cate_name']:
  92. return item
  93. return item[0]
  94. class futianProcess(object):
  95. name = name
  96. allowed_domains = allowed_domains
  97. source = source
  98. source_name = source_name
  99. source_id = source_id
  100. def get_start_url(self):
  101. return base_url + '/info?apikey=' + apikey
  102. def bid_list_result(self, response):
  103. result = json.loads(response.text)
  104. if result is None or result.get('msg') is None:
  105. return []
  106. result_list = []
  107. for item in result['msg']:
  108. result_list.append({'id': item['id']})
  109. return result_list
  110. def get_book_info_url(self, bid):
  111. return base_url + '/book?apikey={}&bookid={}'.format(apikey, bid)
  112. def book_info_result(self, response):
  113. result = json.loads(response.text)
  114. result = result.get('msg')
  115. category_info = get_category(result['ctitle']);
  116. return {
  117. 'bid': result['id'], 'name': result['title'], 'author': result['author'],
  118. 'intro': result['description'], 'cover': result['cover'], 'keyword': '',
  119. 'status': result['status'], 'category': category_info['category_name'],'category_id':category_info['category_id'],
  120. 'channel': result['channel_id']
  121. }
  122. def get_chapter_list_url(self, bid):
  123. return base_url + '/chapterlist?apikey={}&bookid={}'.format(apikey, bid)
  124. def chapter_list_result(self, response):
  125. result = json.loads(response.text)
  126. if result is None or result.get('msg') is None:
  127. return []
  128. result_list = []
  129. i = 0
  130. for chapter_item in result['msg']:
  131. i = i+1
  132. result_list.append({
  133. 'source_chapter_id': chapter_item['id'], 'name': chapter_item['title'],
  134. 'sequence': i, 'is_vip': chapter_item['isvip'],
  135. 'size': 0, 'recent_update_at': chapter_item['update_time']
  136. })
  137. return result_list
  138. def get_chapter_content_url(self, bid, cid):
  139. return base_url + '/chapter?apikey={}&bookid={}&chapterid={}'.format(apikey, bid, cid)
  140. def chapter_content_result(self, response):
  141. result = json.loads(response.text)
  142. if result is None or result.get('msg') is None:
  143. return {'content': ''}
  144. return {
  145. 'content': result['msg']['content'],
  146. 'size': result['msg']['char'],
  147. 'sequence': result['msg']['sort']
  148. }
  149. class futianSpider(futianProcess,baseSpider):
  150. name = name
  151. custom_settings = {
  152. 'DOWNLOAD_DELAY': 0.1,
  153. 'SOURCE': source,
  154. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  155. }
  156. class futianUpdateSpider(futianProcess,baseUpdateSpider):
  157. name = name + "update"
  158. custom_settings = {
  159. 'DOWNLOAD_DELAY': 0.1,
  160. 'SOURCE': source,
  161. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  162. }
  163. class futianFixSpider(futianProcess,fixChapterSpider):
  164. name = name + 'fix'
  165. custom_settings = {
  166. 'DOWNLOAD_DELAY': 0.1,
  167. 'SOURCE': source,
  168. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  169. }
  170. class futianBookInfoSpider(futianProcess,baseUpdateBookStatusSpider):
  171. name = name + "bookinfo"
  172. custom_settings = {
  173. 'DOWNLOAD_DELAY': 0.1,
  174. 'SOURCE': source,
  175. 'LOG_FILE': 'content_spider/log/' + name + time.strftime("%Y-%m-%d", time.localtime()) + '.log'
  176. }