forked from muzea/666666
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlucky.py
69 lines (60 loc) · 2.22 KB
/
lucky.py
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
# coding: utf-8
import time
import json
import requests
from urllib.parse import quote
def search_keyword(qusetion, answers):
header = {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36",
"Host":
"www.baidu.com",
"Cache-Control":
"no-cache"
}
counts = []
if '不是' in qusetion:
qusetion = qusetion.replace('不是', '')
url = 'https://www.baidu.com/s?wd=' + quote(qusetion)
req = requests.get(url=url, headers=header).text
for i in range(len(answers)):
counts.append(req.count(answers[i]))
index = counts.index(min(counts))
if (counts[index] == 0):
print('无结果')
else:
print(answers[index] + " : " + str(counts[index]))
print('******************************************')
else:
url = 'https://www.baidu.com/s?wd=' + quote(qusetion)
req = requests.get(url=url, headers=header).text
for i in range(len(answers)):
counts.append(req.count(answers[i]))
index = counts.index(max(counts))
if (counts[index] == 0):
print('无结果')
else:
print(answers[index] + " : " + str(counts[index]))
print('******************************************')
time.sleep(5)
def get_question():
resp = requests.get(
'http://htpmsg.jiecaojingxuan.com/msg/current', timeout=4).text
# resp = requests.get('http://localhost:8000/Desktop/3.json', ).text
resp_dict = json.loads(resp)
if resp_dict['msg'] == 'no data':
print('...........')
else:
question = resp_dict['data']['event']['desc']
question = question[question.find('.') + 1:question.find('?')]
answers = eval(resp_dict['data']['event']['options'])
print('******************************************')
print(question)
print(answers)
print('******************************************')
search_keyword(question, answers)
if __name__ == '__main__':
while True:
print(time.strftime('%H:%M:%S', time.localtime(time.time())))
get_question()
time.sleep(1)