Replace requests as mds client by tornado

This commit is contained in:
SuperSonic 2020-02-25 21:02:14 +08:00
parent fac8f41cf2
commit 193b30dfca
7 changed files with 27 additions and 34 deletions

View file

@ -68,7 +68,7 @@ class Yuuki_Config:
if "Account" in self.config.get("LINE"):
for key in self.config["LINE"]["Account"]:
if key in ["X-Line-Application", "User-Agent"]:
self.config["LINE"]["Account"][key] = self.config["LINE"]["Account"][key].replace("\\t","\t")
self.config["LINE"]["Account"][key] = self.config["LINE"]["Account"][key].replace("\\t", "\t")
if key in self.connectHeader:
self.connectHeader[key] = self.config["LINE"]["Account"][key]

View file

@ -16,6 +16,8 @@ try:
from thrift.protocol import fastbinary
except ImportError:
print("[No fast_binary using]")
##########################################

View file

@ -11,7 +11,7 @@ import os
import random
import time
import requests
from tornado.httpclient import HTTPClient, HTTPRequest
from yuuki_core.ttypes import OpType
from .data_mds import listen as msd_listen
@ -20,7 +20,6 @@ from .thread_control import Yuuki_Thread
class Yuuki_Data:
# Data Struct Define
Data = {}
@ -115,14 +114,7 @@ class Yuuki_Data:
# MDS Sync
time.sleep(1)
requests.post(
url=self.mdsHost,
json={
"code": self.mdsCode,
"do": "SYC",
"path": self.Data
}
)
self.mdsShake("SYC", self.Data)
return self._Log_Initialize()
def _Log_Initialize(self):
@ -145,16 +137,19 @@ class Yuuki_Data:
def mdsShake(self, do, path, data=None):
if self.threading:
mds = requests.post(
http_client = HTTPClient()
http_request = HTTPRequest(
url=self.mdsHost,
json={
method="POST",
body=json.dumps({
"code": self.mdsCode,
"do": do,
"path": path,
"data": data
}
})
)
over = mds.json()
response = http_client.fetch(http_request)
over = json.loads(response.body)
assert_result = "mds - ERROR\n{} on {}".format(do, path)
assert over["status"] == 200, assert_result
return over

View file

@ -123,8 +123,8 @@ class IndexHandler(RequestHandler):
if req_res.get("code") == auth_code:
result = _work[req_res.get("do")](
{
"path":req_res.get("path"),
"data":req_res.get("data")
"path": req_res.get("path"),
"data": req_res.get("data")
}
)
else:

View file

@ -7,13 +7,13 @@ License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
import time
import socket
import requests
import time
from yuuki_core.ttypes import Operation
from .tools import Yuuki_StaticTools, Yuuki_DynamicTools
from yuuki_core.ttypes import Operation
class Yuuki_Poll:
Power = True
@ -89,9 +89,6 @@ class Yuuki_Poll:
self._action()
self.Power = self.Yuuki.data.syncData()
except requests.exceptions.ConnectionError:
self.Power = False
except SystemExit:
self.Power = False
@ -102,4 +99,4 @@ class Yuuki_Poll:
pass
except:
self._exception()
self._exception()

View file

@ -7,14 +7,14 @@ License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
import os
import sys
import json
import ntpath
import os
import random
import requests
import sys
import traceback
import requests
from yuuki_core.ttypes import OpType, MIDType, ContentType, Group, Message
@ -62,9 +62,9 @@ class Yuuki_StaticTools:
:param ncMessage: Operation
:return: tuple
"""
if ncMessage.type == OpType.NOTIFIED_UPDATE_GROUP or\
ncMessage.type == OpType.NOTIFIED_INVITE_INTO_GROUP or\
ncMessage.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION or\
if ncMessage.type == OpType.NOTIFIED_UPDATE_GROUP or \
ncMessage.type == OpType.NOTIFIED_INVITE_INTO_GROUP or \
ncMessage.type == OpType.NOTIFIED_ACCEPT_GROUP_INVITATION or \
ncMessage.type == OpType.NOTIFIED_KICKOUT_FROM_GROUP:
return {
"GroupID": ncMessage.param1,
@ -347,7 +347,6 @@ class Yuuki_DynamicTools:
'params': json.dumps(params)
}
url = self.Yuuki.LINE_Media_server + '/talk/m/upload.nhn'
r = requests.post(
url, headers=self.Yuuki.connectHeader, data=data, files=files)
r = requests.post(url, headers=self.Yuuki.connectHeader, data=data, files=files)
if r.status_code != 201:
self.sendText(send_to, "Error!")

View file

@ -16,9 +16,9 @@ from yuuki_core.TalkService import *
from .connection import Yuuki_Connect
from .data import Yuuki_Data
from .events import Yuuki_Command, Yuuki_JoinGroup, Yuuki_Security
from .i18n import Yuuki_LangSetting
from .poll import Yuuki_Poll
from .events import Yuuki_Command, Yuuki_JoinGroup, Yuuki_Security
from .thread_control import Yuuki_Multiprocess
from .webadmin.server import Yuuki_WebAdmin
@ -169,4 +169,4 @@ class Yuuki:
def main(self):
handle = Yuuki_Poll(self)
handle.init()
handle.init()