-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcilimao.py
More file actions
81 lines (67 loc) · 2.24 KB
/
cilimao.py
File metadata and controls
81 lines (67 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# coding: utf-8
"""命令行磁力猫查询
默认选择按视频排序,按下载热度排序
Usage:
cilimao [-p] <KEYWORD>
cilimao [-h,--help] 显示帮助菜单
Options:
-h,--help 显示帮助菜单
-p 页数(默认为0)
Example:
cilimao 复仇者联盟
cilimao -p 1 复仇者联盟
"""
import requests
from docopt import docopt
class Parase:
def __init__(self, result):
self.result = result
def parase_a(self):
"""
解析数据
result: 传入待解析的数据
"""
try:
leng = str(self.result['content_size'])
if len(leng) <= 9:
size = int(leng) / 1048576
sizeS = str(size) + 'MB'
elif len(leng) >= 10:
size = int(leng) / 1073741824
sizeS = str(size) + 'GB'
infohash = self.result['infohash']
title = self.result['title']
file_count = self.result['file_count']
cre_time = self.result['created_time']
print('磁链标题: ', title)
print('磁链地址: magnet:?xt=urn:btih:{}'.format(infohash))
print('文件数目: ', file_count)
print('文件大小: ', sizeS)
print('创建时间: ', cre_time , '\n')
except Exception as e:
print('磁链标题: ', title)
print('磁链地址: magnet:?xt=urn:btih:{}'.format(infohash))
print('文件数目: ', file_count)
print('文件大小: ', sizeS)
print('创建时间: ', cre_time , '\n')
print('Error Ex', e, '\n')
def run():
"""程序入口"""
arguments = docopt(__doc__)
keyword = arguments['<KEYWORD>']
if arguments['-p'] is True:
page = arguments['-p']
else:
page = 0
url = ('https://www.cilimao.cc/api/search?size=10&'
'sortDirections=desc&word={}&'
'sortProperties=download_count&page={}').format(
keyword, page)
r = requests.get(url)
print('Crawling data for you.....')
result = r.json()['data']['result']['content']
for item in result:
if 'infohash' in item:
Parase(item).parase_a()
if __name__ == "__main__":
run()