-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
125 lines (111 loc) · 3.41 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from wxpy import *
from meme_maker import *
from emotional import *
from pymongo import *
import requests
import time
import json
import re
# Init the env, login
bot = Bot()
print("========INIT SUCCESSFULLY=====")
frs = bot.friends()
dummy = ''
yuze = bot.friends().search('Yuze Ma 鱼哲')[0]
apiUrl = 'http://www.tuling123.com/openapi/api'
data = {
"key": "c306b319ca4541d78a6413ccc16c8119",
"info": "你好呀",
"userid":"123"
}
dummy_dict = dict()
# connect to mongodb
client = MongoClient("mongodb://localhost:27017/")
db = client.codemao_data_analysis_dbs
collection = db.msg_records
@bot.register(Group, TEXT)
def auto_reply(msg):
# 如果是群聊,但没有被 @,则不回复
if isinstance(msg.chat, Group) and not msg.is_at:
# print(msg.raw)
# data["info"] = msg.text
# try:
# time.sleep(1200)
# res = requests.post(apiUrl, data = data).json()
# return res["text"]
# except:
# return "你说什么我听不见!"
print("==EXECUTRED==")
get_meme()
msg.sender.send_image("out.png")
return
else:
# 回复消息内容和类型
try:
print("==EXECUTRED==")
get_meme()
msg.sender.send_image("out.png")
return "lolol"
# data["info"] = msg.text
# res = requests.post(apiUrl, data = data).json()
# return res["text"]
except:
return "Connection lost"
@bot.register(Group, PICTURE)
def auto_reply(msg):
# 如果是群聊,但没有被 @,则不回复
if isinstance(msg.chat, Group) and not msg.is_at:
try:
print("==Execute by pic in a group chat==")
get_meme()
msg.sender.send_image("out.png")
return
except:
return "Connection lost"
# return
else:
# 回复消息内容和类型
try:
print("==Execute by pic in a group chat==")
get_meme()
msg.sender.send_image("out.png")
return "lolol"
except:
return "Connection lost"
@bot.register(bot.friends(), PICTURE)
def auto_reply(msg):
raw_content = msg.raw['Content']
print(raw_content)
url = re.findall("cdnurl=(.*) des",raw_content, re.S)
real_url = re.findall("\"(.*)\"",url[0], re.S)[0]
print("=================================")
emotional_data = get_emotion_from_img(real_url)
print(emotional_data)
get_meme_by_emotion(emotional_data)
msg.sender.send_image("out.png")
# Send emotion data to front-end server
try:
# r = requests.post("http://10.2.12.201:9090/getData", data=emotional_data)
r = requests.post("http://localhost:9090/getData", data=emotional_data)
print("req suceessfully made")
except:
return "你说什么我没听清"
# return emotional_data
@bot.register(bot.friends(), TEXT)
def auto_r(msg):
print(">>>>>>>>>>>>>>>GET: \n",msg.text)
try:
print("==EXECUTRED==")
text_content = msg.text
collection.insert_one(msg.raw)
get_meme()
msg.sender.send_image("out.png")
data["info"] = msg.text
try:
res = requests.post(apiUrl, data = data).json()
except:
print("Tuling is down...")
return res["text"] # return
except:
print("Tuling is down...")
return "23333"