zhaoyang hace 2 años
padre
commit
84f4c5bc62

BIN
content_spider/spiders/futian/JSON-interface.docx


+ 206 - 0
content_spider/spiders/futian/futian.py

@@ -0,0 +1,206 @@
+# -*- 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 = 'futian'
+allowed_domains = ['www.futian.com']
+source = 'zy_futian'
+source_name = 'futian伏天	'
+source_id = 32
+base_url = 'http://www.futianbook.com/api/json'
+apikey = '3399b12e976734c318754c24b5b5dfd0'
+
+category =  [
+    {
+		"channel_id": 1,
+		"channel_name": "男频",
+		"cate_id": 1,
+		"cate_name": "现代都市",
+        "category_id":"54",
+        "category_name":"都市爱情"
+	},
+    {
+		"channel_id": 1,
+		"channel_name": "男频",
+		"cate_id": 2,
+		"cate_name": "悬疑灵异",
+        "category_id":"81",
+        "category_name":"灵异恐怖"
+	}
+    {
+		"channel_id": 1,
+		"channel_name": "男频",
+		"cate_id": 3,
+		"cate_name": "玄幻仙侠",
+        "category_id":"21",
+        "category_name":"武侠仙侠"
+	},
+    {
+		"channel_id": 1,
+		"channel_name": "男频",
+		"cate_id": 4,
+		"cate_name": "历史军事",
+        "category_id":"51",
+        "category_name":"特种军旅"
+	},
+    {
+		"channel_id": 1,
+		"channel_name": "男频",
+		"cate_id": 5,
+		"cate_name": "体育电竞",
+        "category_id":"19",
+        "category_name":"游戏竞技"
+	},
+    {
+		"channel_id": 1,
+		"channel_name": "男频",
+		"cate_id": 6,
+		"cate_name": "科幻末日",
+        "category_id":"23",
+        "category_name":"玄幻奇幻"
+	}
+    {
+		"channel_id": 1,
+		"channel_name": "男频",
+		"cate_id": 7,
+		"cate_name": "同人其他",
+        "category_id":"127",
+        "category_name":"其他"
+	},
+    {
+		"channel_id": 2,
+		"channel_name": "女频",
+		"cate_id": 8,
+		"cate_name": "现代言情",
+        "category_id":"87",
+        "category_name":"婚恋情感"
+	},
+    {
+		"channel_id": 2,
+		"channel_name": "女频",
+		"cate_id": 8,
+		"cate_name": "古代言情",
+        "category_id":"83",
+        "category_name":"穿越重生"
+	}
+    ]
+
+
+
+def get_category(category_name):
+    for item in category:
+        if category_name == item['cate_name']:
+            return item
+    return item[0]
+
+
+class futianProcess(object):
+    name = name
+    allowed_domains = allowed_domains
+    source = source
+    source_name = source_name
+    source_id = source_id
+
+
+    def get_start_url(self):
+        return base_url + '/info?apikey=' + apikey
+
+    def bid_list_result(self, response):
+        result = json.loads(response.text)
+        if result is None or result.get('msg') is None:
+            return []
+        result_list = []
+        for item in result['msg']:
+            result_list.append({'id': item['id']})
+        return result_list
+
+    def get_book_info_url(self, bid):
+        return base_url + '/book?apikey={}&bookid={}'.format(apikey, bid)
+
+    def book_info_result(self, response):
+        result = json.loads(response.text)
+        result = result.get('msg')
+        category_info = get_category(result['ctitle']);
+        return {
+            'bid': result['id'], 'name': result['title'], 'author': result['author'],
+            'intro': result['description'], 'cover': result['cover'], 'keyword': '',
+            'status': result['status'], 'category': category_info['category_name'],'category_id':category_info['category_id'],
+            'channel': result['channel_id']
+        }
+
+    def get_chapter_list_url(self, bid):
+        return base_url + '/chapterlist?apikey={}&bookid={}'.format(apikey, bid)
+
+    def chapter_list_result(self, response):
+        result = json.loads(response.text)
+        if result is None or result.get('msg') is None:
+            return []
+
+        result_list = []
+        i = 0
+        for chapter_item in result['msg']:
+            i = i+1
+            result_list.append({
+                'source_chapter_id': chapter_item['id'], 'name': chapter_item['title'],
+                'sequence': i, 'is_vip': chapter_item['isvip'],
+                'size': 0, 'recent_update_at': chapter_item['update_time']
+            })
+        return result_list
+
+    def get_chapter_content_url(self, bid, cid):
+        return base_url + '/chapter?apikey={}&bookid={}&chapterid={}'.format(apikey, bid, cid)
+
+    def chapter_content_result(self, response):
+        result = json.loads(response.text)
+        if result is None or result.get('msg') is None:
+            return {'content': ''}
+
+        return {
+            'content': result['msg']['content'],
+            'size': result['msg']['char'],
+            'sequence': result['msg']['sort']
+        }
+
+    
+class futianSpider(futianProcess,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 futianUpdateSpider(futianProcess,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 futianFixSpider(futianProcess,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 futianBookInfoSpider(futianProcess,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'
+    }

BIN
content_spider/spiders/futian/伏天文学分类.xlsx


+ 192 - 0
content_spider/spiders/wangyou/wangyou.py

@@ -0,0 +1,192 @@
+# -*- 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
+from content_spider.Util import md5
+import time
+import json
+
+
+name = 'wangyou'
+allowed_domains = ['api.wangyou2.com']
+source = 'zy_wangyou'
+source_name = 'wangyou忘忧'
+source_id = 31
+sid = '100000106'
+key = '4MWJrBwwEdsXnGW426e85f5NYc8TwfJN'
+base_url = 'http://api.wangyou2.com/apis/api/{}.php?sid=' + sid + '&sign={}'
+doc = 'https://help.2cms.top/web/#/13'
+
+
+category = [{'channel_id': 1, 'cate_id': '1001', 'cate_name': '热血青春', 'sub_cate_id': '1001001', 'category_id': 67, 'category_name': '校园励志'},
+ {'channel_id': 1, 'cate_id': '1001', 'cate_name': '', 'sub_cate_id': '1001002', 'category_id': 67, 'category_name': '校园励志'},
+ {'channel_id': 1, 'cate_id': '1001', 'cate_name': '', 'sub_cate_id': '1001003', 'category_id': 30, 'category_name': '校园黑道'},
+ {'channel_id': 1, 'cate_id': '1001', 'cate_name': '', 'sub_cate_id': '1001004', 'category_id': 94, 'category_name': '青春爱情'},
+ {'channel_id': 1, 'cate_id': '1001', 'cate_name': '', 'sub_cate_id': '1001005', 'category_id': 94, 'category_name': '青春爱情'},
+ {'channel_id': 1, 'cate_id': '1002', 'cate_name': '现代都市', 'sub_cate_id': '1002001', 'category_id': 54, 'category_name': '都市爱情'},
+ {'channel_id': 1, 'cate_id': '1002', 'cate_name': '', 'sub_cate_id': '1002002', 'category_id': 68, 'category_name': '现代修真'},
+ {'channel_id': 1, 'cate_id': '1002', 'cate_name': '', 'sub_cate_id': '1002003', 'category_id': 55, 'category_name': '官场沉浮'},
+ {'channel_id': 1, 'cate_id': '1002', 'cate_name': '', 'sub_cate_id': '1002004', 'category_id': 54, 'category_name': '都市爱情'},
+ {'channel_id': 1, 'cate_id': '1003', 'cate_name': '悬疑灵异', 'sub_cate_id': '1003001', 'category_id': 81, 'category_name': '灵异恐怖'},
+ {'channel_id': 1, 'cate_id': '1003', 'cate_name': '', 'sub_cate_id': '1003002', 'category_id': 81, 'category_name': '灵异恐怖'},
+ {'channel_id': 1, 'cate_id': '1003', 'cate_name': '', 'sub_cate_id': '1003003', 'category_id': 81, 'category_name': '灵异恐怖'},
+ {'channel_id': 1, 'cate_id': '1003', 'cate_name': '', 'sub_cate_id': '1003004', 'category_id': 81, 'category_name': '灵异恐怖'},
+ {'channel_id': 1, 'cate_id': '1004', 'cate_name': '军事历史', 'sub_cate_id': '1004001', 'category_id': 14, 'category_name': '历史穿越'},
+ {'channel_id': 1, 'cate_id': '1004', 'cate_name': '', 'sub_cate_id': '1004002', 'category_id': 14, 'category_name': '历史穿越'},
+ {'channel_id': 1, 'cate_id': '1004', 'cate_name': '', 'sub_cate_id': '1004003', 'category_id': 14, 'category_name': '历史穿越'},
+ {'channel_id': 1, 'cate_id': '1004', 'cate_name': '', 'sub_cate_id': '1004004', 'category_id': 14, 'category_name': '历史穿越'},
+ {'channel_id': 1, 'cate_id': '1005', 'cate_name': '玄幻奇幻', 'sub_cate_id': '1005001', 'category_id': 23, 'category_name': '玄幻奇幻'},
+ {'channel_id': 1, 'cate_id': '1005', 'cate_name': '', 'sub_cate_id': '1005002', 'category_id': 23, 'category_name': '玄幻奇幻'},
+ {'channel_id': 1, 'cate_id': '1005', 'cate_name': '', 'sub_cate_id': '1005003', 'category_id': 23, 'category_name': '玄幻奇幻'},
+ {'channel_id': 1, 'cate_id': '1005', 'cate_name': '', 'sub_cate_id': '1005004', 'category_id': 23, 'category_name': '玄幻奇幻'},
+ {'channel_id': 1, 'cate_id': '1006', 'cate_name': '武侠仙侠', 'sub_cate_id': '1006001', 'category_id': 23, 'category_name': '玄幻奇幻'},
+ {'channel_id': 1, 'cate_id': '1006', 'cate_name': '', 'sub_cate_id': '1006002', 'category_id': 23, 'category_name': '玄幻奇幻'},
+ {'channel_id': 1, 'cate_id': '1006', 'cate_name': '', 'sub_cate_id': '1006003', 'category_id': 23, 'category_name': '玄幻奇幻'},
+ {'channel_id': 1, 'cate_id': '1006', 'cate_name': '', 'sub_cate_id': '1006004', 'category_id': 23, 'category_name': '玄幻奇幻'},
+ {'channel_id': 1, 'cate_id': '1007', 'cate_name': '网游竞技', 'sub_cate_id': '1007001', 'category_id': 19, 'category_name': '游戏竞技'},
+ {'channel_id': 1, 'cate_id': '1007', 'cate_name': '', 'sub_cate_id': '1007002', 'category_id': 19, 'category_name': '游戏竞技'},
+ {'channel_id': 1, 'cate_id': '1007', 'cate_name': '', 'sub_cate_id': '1007003', 'category_id': 19, 'category_name': '游戏竞技'},
+ {'channel_id': 1, 'cate_id': '1007', 'cate_name': '', 'sub_cate_id': '1007004', 'category_id': 19, 'category_name': '游戏竞技'},
+ {'channel_id': 2, 'cate_id': '1008', 'cate_name': '热血言情', 'sub_cate_id': '1008001', 'category_id': 98, 'category_name': '婚恋情感'},
+ {'channel_id': 2, 'cate_id': '1008', 'cate_name': '', 'sub_cate_id': '1008002', 'category_id': 98, 'category_name': '婚恋情感'},
+ {'channel_id': 2, 'cate_id': '1008', 'cate_name': '', 'sub_cate_id': '1008003', 'category_id': 98, 'category_name': '婚恋情感'},
+ {'channel_id': 2, 'cate_id': '1008', 'cate_name': '', 'sub_cate_id': '1008004', 'category_id': 98, 'category_name': '婚恋情感'},
+ {'channel_id': 2, 'cate_id': '1008', 'cate_name': '', 'sub_cate_id': '1008005', 'category_id': 98, 'category_name': '婚恋情感'},
+ {'channel_id': 2, 'cate_id': '1009', 'cate_name': '古代情缘', 'sub_cate_id': '1009001', 'category_id': 120, 'category_name': '宫斗宅斗'},
+ {'channel_id': 2, 'cate_id': '1009', 'cate_name': '', 'sub_cate_id': '1009002', 'category_id': 120, 'category_name': '宫斗宅斗'},
+ {'channel_id': 2, 'cate_id': '1009', 'cate_name': '', 'sub_cate_id': '1009003', 'category_id': 123, 'category_name': '女尊王朝'},
+ {'channel_id': 2, 'cate_id': '1009', 'cate_name': '', 'sub_cate_id': '1009004', 'category_id': 123, 'category_name': '女尊王朝'},
+ {'channel_id': 2, 'cate_id': '1009', 'cate_name': '', 'sub_cate_id': '1009005', 'category_id': 123, 'category_name': '女尊王朝'},
+ {'channel_id': 2, 'cate_id': '1010', 'cate_name': '现代爱情', 'sub_cate_id': '1010001', 'category_id': 98, 'category_name': '婚恋情感'},
+ {'channel_id': 2, 'cate_id': '1010', 'cate_name': '', 'sub_cate_id': '1010002', 'category_id': 98, 'category_name': '婚恋情 感'},
+ {'channel_id': 2, 'cate_id': '1010', 'cate_name': '', 'sub_cate_id': '1010003', 'category_id': 98, 'category_name': '婚恋情感'},
+ {'channel_id': 2, 'cate_id': '1010', 'cate_name': '', 'sub_cate_id': '1010004', 'category_id': 98, 'category_name': '婚恋情感'},
+ {'channel_id': 2, 'cate_id': '1010', 'cate_name': '', 'sub_cate_id': '1010005', 'category_id': 98, 'category_name': '婚恋情感'},
+ {'channel_id': 2, 'cate_id': '1011', 'cate_name': '幻想世界', 'sub_cate_id': '1011001', 'category_id': 96, 'category_name': '东方玄幻'},
+ {'channel_id': 2, 'cate_id': '1011', 'cate_name': '', 'sub_cate_id': '1011002', 'category_id': 96, 'category_name': '东方玄幻'},
+ {'channel_id': 2, 'cate_id': '1011', 'cate_name': '', 'sub_cate_id': '1011003', 'category_id': 96, 'category_name': '东方玄幻'},
+ {'channel_id': 2, 'cate_id': '1011', 'cate_name': '', 'sub_cate_id': '1011004', 'category_id': 96, 'category_name': '东方玄幻'},
+ {'channel_id': 2, 'cate_id': '1011', 'cate_name': '', 'sub_cate_id': '1011005', 'category_id': 96, 'category_name': '东方玄幻'},
+ {'channel_id': 2, 'cate_id': '1011', 'cate_name': '', 'sub_cate_id': '1011006', 'category_id': 96, 'category_name': '东方玄幻'}]
+
+def get_sign():
+    today = time.strftime("%Y%m%d", time.localtime())
+    sign_str = today + sid + key
+    return md5(sign_str)    
+
+def get_category(sub_cate_id):
+    for item in category:
+        if str(sub_cate_id) == item['sub_cate_id']:
+            return item
+    return item[0]
+
+
+class wangyouProcess(object):
+    name = name
+    allowed_domains = allowed_domains
+    source = source
+    source_name = source_name
+    source_id = source_id
+
+
+    def get_start_url(self):
+        sign = get_sign()
+        return self.base_url.format('BookList',sign)
+
+    def bid_list_result(self, response):
+        result = json.loads(response.text)
+        if result is None or result.get('data') is None:
+            return []
+        result_list = []
+        for item in result['data']:
+            result_list.append({'id': item['id']})
+        return result_list
+
+    def get_book_info_url(self, bid):
+        sign = get_sign()
+        return self.base_url.format('BookInfo',sign) + '&bookid={}'.format(bid)
+
+    def book_info_result(self, response):
+        result = json.loads(response.text)
+        result = result['data']
+        category_info = get_category(result['ctitle']);
+        return {
+            'bid': result['id'], 'name': result['bookTitle'], 'author': result['author'],
+            'intro': result['introduction'], 'cover': result['cover'], 'keyword': result['labels'],
+            'status':result['state'], 'category': category_info['category_name'],'category_id':category_info['category_id'],
+            'channel': result['channel_id']
+        }
+
+    def get_chapter_list_url(self, bid):
+        sign = get_sign()
+        return self.base_url.format('BookChapters',sign) + '&bookid={}'.format(bid)
+
+    def chapter_list_result(self, response):
+        result = json.loads(response.text)
+        if result is None or result.get('data') is None:
+            return []
+
+        result_list = []
+        i = 0
+        for chapter_item in result['data']:
+            i = i+1
+            result_list.append({
+                'source_chapter_id': chapter_item['id'], 'name': chapter_item['title'],
+                'sequence': chapter_item['orders'], 'is_vip': 1 if chapter_item['isVip'] else 0,
+                'size': 0, 'recent_update_at': chapter_item['postTime']
+            })
+        return result_list
+
+    def get_chapter_content_url(self, bid, cid):
+        sign = get_sign()
+        return self.base_url.format('BookChapterInfo',sign) + '&bookid={}&chapterid={}'.format(bid, cid)
+
+    def chapter_content_result(self, response):
+        result = json.loads(response.text)
+        if result is None:
+            return {'content': ''}
+
+        return {
+            'content': result['data']['content'],
+            'size': len(result['data']['content'])
+        }
+
+    
+class wangyouSpider(wangyouProcess,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 wangyouUpdateSpider(wangyouProcess,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 wangyouFixSpider(wangyouProcess,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 wangyouBookInfoSpider(wangyouProcess,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'
+    }

BIN
content_spider/spiders/wangyou/分类.xlsx


+ 68 - 223
content_spider/temp_test.py

@@ -9,233 +9,78 @@ from urllib.parse import parse_qs
 
 import urllib
 from xml.dom.minidom import parseString
-from content_spider.Util import hashUtil, random_str
 
 import time
-from content_spider.Util import my_log
+import xlrd
 
-cate = [
-		{
-			"id": 1,
-			"name": "都市生活",
-			"channel": "男频",
-			"childs": [
-				{
-					"id": 1,
-					"name": "爱情婚姻"
-				},
-				{
-					"id": 2,
-					"name": "商战风云"
-				},
-				{
-					"id": 3,
-					"name": "职场励志"
-				},
-				{
-					"id": 4,
-					"name": "官场沉浮"
-				},
-				{
-					"id": 5,
-					"name": "现实百态"
-				},
-				{
-					"id": 6,
-					"name": "八卦杂谈"
-				},
-				{
-					"id": 32,
-					"name": "都市异能"
-				},
-				{
-					"id": 40,
-					"name": "现代修真"
-				}
-			]
-		},
-		{
-			"id": 2,
-			"name": "女性言情",
-			"channel": "女频",
-			"childs": [
-				{
-					"id": 9,
-					"name": "总裁豪门"
-				},
-				{
-					"id": 8,
-					"name": "穿越时空"
-				},
-				{
-					"id": 11,
-					"name": "青春纯爱"
-				},
-				{
-					"id": 12,
-					"name": "架空历史"
-				},
-				{
-					"id": 7,
-					"name": "悬疑推理"
-				},
-				{
-					"id": 10,
-					"name": "综合其他"
-				}
-			]
-		},
-		{
-			"id": 3,
-			"name": "玄幻小说",
-			"channel": "男频",
-			"childs": [
-				{
-					"id": 13,
-					"name": "东方玄幻"
-				},
-				{
-					"id": 14,
-					"name": "异界大陆"
-				},
-				{
-					"id": 15,
-					"name": "西方奇幻"
-				},
-				{
-					"id": 16,
-					"name": "异术超能"
-				},
-				{
-					"id": 33,
-					"name": "转世重生"
-				}
-			]
-		},
-		{
-			"id": 4,
-			"name": "历史军事",
-			"channel": "男频",
-			"childs": [
-				{
-					"id": 19,
-					"name": "架空历史"
-				},
-				{
-					"id": 20,
-					"name": "历史传记"
-				},
-				{
-					"id": 21,
-					"name": "论古谈今"
-				},
-				{
-					"id": 22,
-					"name": "军事战争"
-				},
-				{
-					"id": 23,
-					"name": "军旅生活"
-				},
-				{
-					"id": 24,
-					"name": "抗战烽火"
-				}
-			]
-		},
-		{
-			"id": 5,
-			"name": "科幻灵异",
-			"channel": "男频",
-			"childs": [
-				{
-					"id": 25,
-					"name": "未来世界"
-				},
-				{
-					"id": 26,
-					"name": "星际战争"
-				},
-				{
-					"id": 27,
-					"name": "古武机甲"
-				},
-				{
-					"id": 28,
-					"name": "灵异奇谈"
-				},
-				{
-					"id": 29,
-					"name": "恐怖惊悚"
-				},
-				{
-					"id": 30,
-					"name": "悬疑探险"
-				},
-				{
-					"id": 35,
-					"name": "侦探推理"
-				},
-				{
-					"id": 36,
-					"name": "末日危临"
-				}
-			]
-		},
-		{
-			"id": 6,
-			"name": "武侠仙侠",
-			"channel": "男频",
-			"childs": [
-				{
-					"id": 17,
-					"name": "奇幻修真"
-				},
-				{
-					"id": 18,
-					"name": "古典仙侠"
-				},
-				{
-					"id": 34,
-					"name": "经典武侠"
-				}
-			]
-		},
-		{
-			"id": 7,
-			"name": "综合其他",
-			"channel": "男频",
-			"childs": [
-				{
-					"id": 31,
-					"name": "其他类别"
-				},
-				{
-					"id": 37,
-					"name": "电子竞技"
-				},
-				{
-					"id": 38,
-					"name": "虚拟网游"
-				},
-				{
-					"id": 39,
-					"name": "体育竞技"
-				}
-			]
-		}
-	]
 
 
-res = []
-for i in cate:
 
-    if i['channel'] == '男频':
-        channel_id = 1
-    else:
-        channel_id = 2
-    for j in i['childs']:
-        temp  = {'id': j['id'], 'name': j['name'], 'my_category_id': 0, 'ncategory_id': 0, 'my_category_name': '古代言情', 'channel_id': channel_id}
-        res.append(temp)
 
-print(res)
+
+def get_category(c_id):
+    if c_id == '1001001' or c_id == '1001002':
+        return {"id":67,"name":"校园励志"}
+    if c_id == '1001003':
+        return {"id":30,"name":"校园黑道"}
+    if c_id == '1001004' or c_id == '1001005':
+        return {"id":94,"name":"青春爱情"}
+    if c_id == '1002001'  or c_id == '1002004':
+        return {"id":54,"name":"都市爱情"}
+    if c_id == '1002002':
+        return {"id":68,"name":"现代修真"}
+    if c_id == '1002003':
+        return {"id":55,"name":"官场沉浮"}
+    if c_id == '1003001' or c_id == '1003002' or c_id == '1003003' or c_id == '1003004':
+        return {"id":81,"name":"灵异恐怖"}
+    if c_id == '1004001'or c_id == '1004002' or c_id == '1004003' or c_id == '1004004':
+        return {"id":14,"name":"历史穿越"}
+    if c_id == '1005001'or c_id == '1005002' or c_id == '1005003' or c_id == '1005004' or c_id == '1006001'or c_id == '1006002' or c_id == '1006003' or c_id == '1006004':
+        return {"id":23,"name":"玄幻奇幻"}
+    if c_id == '1007001' or c_id == '1007002' or c_id == '1007003' or c_id == '1007004':
+        return {"id":19,"name":"游戏竞技"}
+    
+    if c_id == '1008001' or c_id == '1008002'  or c_id == '1008003'  or c_id == '1008004'  or c_id == '1008005':
+        return {"id":98,"name":"婚恋情感"}
+    if c_id == '1009001' or c_id == '1009002':
+        return {"id":120,"name":"宫斗宅斗"}
+    if c_id == '1009003' or c_id == '1009004' or c_id == '1009005':
+        return {"id":123,"name":"女尊王朝"}
+    if c_id == '1010001' or c_id == '1010002' or c_id == '1010003' or c_id == '1010004' or c_id == '1010005':
+        return {"id":98,"name":"婚恋情感"}
+    if c_id == '1011001' or c_id == '1011002' or c_id == '1011003' or c_id == '1011004' or c_id == '1011005' or c_id  == '1011006':
+        return {"id":96,"name":"东方玄幻"}
+    
+
+wb = xlrd.open_workbook("fff.xls")
+sh1 = wb.sheet_by_index(0)
+
+print( u"sheet %s 共 %d 行 %d 列" % (sh1.name, sh1.nrows, sh1.ncols))
+last_cate_id = 0
+last_channel_id = 0
+result = []
+for item in range(1,sh1.nrows):
+	rows = sh1.row_values(item)
+	if rows[0] == '':
+		channel_id = last_channel_id
+	else:
+		channel_id = 1 if rows[0] == '男频' else 2
+		last_channel_id = channel_id
+	if rows[1] == '' or  rows[1] is None:
+		cate_id = last_cate_id
+	else:
+		cate_id = int(rows[1])
+
+	last_cate_id = cate_id
+
+	cate_name = rows[2]
+	sub_cate_id = int(rows[3])
+	sub_cate_name = rows[4]
+	category_info = get_category(str(sub_cate_id))
+	result.append({
+        "channel_id":channel_id,'cate_id':str(cate_id),'cate_name':cate_name,'sub_cate_id':str(sub_cate_id),'category_id':category_info['id'],'category_name':category_info['name']
+	})
+    
+	#print(channel_id)
+print(result)
+