Beispiel #1
0
    def btnOkClicked():

        my_id = LoginFrame.lineEdit_id.text()
        my_pw = LoginFrame.lineEdit_pw.text()

        result = Communication.login(my_id, my_pw)

        if result['success']:
            LoginFrame.qwidget.hide()
            User.u_id = my_id
            setattr(DeviceInfoThread.friend_device_info[0], 'u_id', my_id)
            result = FriendCommunication.friend_list(my_id)
            for i in result['friends']:
                DeviceInfoThread.friend_device_info.append(
                    DeviceInfo(i['op_id'], i['op_id']))

            MainFrame.MainFrame.listwidget_item()

        else:
            FailDialog.retranslateUi('Fail', result['message'])
            FailDialog.widget_show()
Beispiel #2
0
class Communication(object):
    #url = "http://" + MyYaml.node_js_host + ":" + str(MyYaml.node_js_port)
    url = "http://127.0.0.1:3000"

    info = DeviceInfo('1', '1')

    @staticmethod
    def send():
        routes = "/device/info"
        params = urllib.parse.urlencode(
            DeviceInfoThread.friend_device_info[0].__dict__)
        binary_data = params.encode()

        try:
            data = urllib.request.urlopen(Communication.url + routes,
                                          binary_data).read()
        except Exception as e:
            print(e)

    @staticmethod
    def send2(op_id):
        routes = "/friend/info?op_id=" + op_id
        try:
            data = urllib.request.urlopen(Communication.url + routes).read()
            # print(data)
            return json.loads(data.decode("utf-8"))
        except Exception as e:
            print(e)
            return {'success': False, 'message': 'error'}

    @staticmethod
    def login(my_id, my_pw):
        routes = "/account?u_id=" + my_id + "&u_pw=" + my_pw
        try:
            data = urllib.request.urlopen(Communication.url + routes).read()
            print(data)
            return json.loads(data.decode("utf-8"))
        except Exception as e:
            print(e)
            return {'success': False, 'message': 'error'}

    @staticmethod
    def join(account):
        routes = "/account"
        params = urllib.parse.urlencode({
            'u_id': account.u_id,
            'u_pw': account.u_pw,
        })
        binary_data = params.encode()
        try:
            data = urllib.request.urlopen(Communication.url + routes,
                                          binary_data).read()
        except Exception as e:
            print(e)

        return json.loads(data.decode("utf-8"))

    @staticmethod
    def profile(image_path):

        routes = '/account/profile'
        files = {"file": open(image_path, "rb")}
        print(files)
        params = {"key": "value"}
        requests.post(Communication.url + routes, params=params, files=files)
Beispiel #3
0
import sys

from PyQt5.QtWidgets import QApplication
from FailDialog import FailDialog
from DeviceinfoThread import DeviceInfoThread
from JoinFrame import JoinFrame
from MainFrame import MainFrame
from model.Device import DeviceInfo
from Myhttp import ThreadFriendInfoCommunication
from Myhttp import ThreadCommunication
from AddFriendDialog import AddFriendDialog
from webChatFrame import WebChatFrame

if __name__ == '__main__':

    my_info = DeviceInfo('1', '1')

    thread = DeviceInfoThread()
    thread.start()

    comm = ThreadCommunication()
    comm.start()

    comm2 = ThreadFriendInfoCommunication()
    comm2.start()

    app = QApplication(sys.argv)

    MainFrame.init()

    AddFriendDialog.init()
Beispiel #4
0
    def __init__(self):
        QThread.__init__(self)
        DeviceInfoThread.friend_device_info.append(DeviceInfo(None, None))

        setattr(self.friend_device_info[0], 'd_boot_t', self.get_my_booting_time())
        setattr(self.friend_device_info[0], 'd_name', socket.gethostname())