Ejemplo n.º 1
0
class Motion(Thread):
    def __init__(self):
        self.db = DbHelper("iot.db")
        self.db.connect_to_db()

    def run(self):
        while (True):
            row = db.executeQuery("Select is_motion from house where id = 1")
            if row is not None:
                is_motion = row.fetchone()[0]
                if (is_motion == 1):
                    #GPIO.add_event_detect(SENSOR_PIN,GPIO.RISING,callback=motionDetect)
                    if (GPIO.input(10)):
                        RaspberryPi.changeStateMotion(16, 0)
                        RaspberryPi.changeStateMotion(18, 0)
                        RaspberryPi.changeStateMotion(2, 0)

                    else:
                        RaspberryPi.changeStateMotion(16, 1)
                        RaspberryPi.changeStateMotion(18, 1)
                        RaspberryPi.changeStateMotion(2, 1)

    def motionDetect():
        rpi.changeState(16, 1)
        rpi.changeState(18, 1)
        rpi.changeState(2, 1)
Ejemplo n.º 2
0
    def __init__(self):
        self.db = DbHelper()
        sql = "CREATE TABLE IF NOT EXISTS `" + self.TABLE_NAME + "` (" \
              + self.FIELD_TITLE + " TEXT NOT NULL," \
              + self.FIELD_COUNT + " INT NOT NULL DEFAULT '1'," \
              + "PRIMARY KEY (`" + self.FIELD_TITLE + "`(100)));"

        self.db.execute(sql)
Ejemplo n.º 3
0
class Service():
    def __init__(self):
        self.db_helper = DbHelper()
        self.doctors_list = []
        self.patients_list = []

    def get_doctors_list(self):
        mas = []
        for i in self.db_helper.get_doctors_ids():
            ar_doc = ActiveRecordDoctor(i, "", "", 0)
            mas.append(ar_doc.form_title_string())
        return mas

    def get_patients_list(self):
        mas = []
        for i in self.db_helper.get_patients_ids():
            ar_doc = ActiveRecordPatientCard(i, "", "")
            mas.append(ar_doc.form_title_string())
        return mas

    def get_doctors_count(self):
        ar_doc = ActiveRecordDoctor(0, '', '', 0)
        for i in self.db_helper.get_doctors_ids():
            ar_doc = ActiveRecordDoctor(i, "", "", 0)
            self.doctors_list.append(ar_doc)
        return self.doctors_list

    def get_patients_count(self):
        ar_doc = ActiveRecordPatientCard(0, '', '')
        for i in self.db_helper.get_patients_ids():
            ar_doc = ActiveRecordPatientCard(i, "", "")
            self.patients_list.append(ar_doc)
        return self.patients_list

    def get_doctor_object(self, q):
        line = q.currentText().split(' ')
        id = line[0]
        current_doctor = ActiveRecordDoctor(0, '', '', 0)
        qq = self.get_doctors_count()
        for i in qq:
            if int(id) == ActiveRecordDoctor.get_id(i):
                current_doctor = i
        return current_doctor

    def get_patient_object(self, q):
        line = q.currentText().split(' ')
        id = line[0]
        current_patient = ActiveRecordPatientCard(0, '', '')
        qq = self.get_patients_count()
        for i in qq:
            if int(id) == ActiveRecordPatientCard.get_id(i):
                current_patient = i
                # current_patient
        return current_patient.form_title_end()

    def save_card(self, card_number, name, surname):
        new_card = ActiveRecordPatientCard(card_number, name, surname)
        new_card.insert_record()
Ejemplo n.º 4
0
    def put(self, collection=None,_id=None):
        """
        Function to update a db.
        """
        try:
            if collection is None:
                return Response('Collection name cannot be null', status = 500)
            dbhelper =DbHelper(collectionName=collection)
            q_params = utils.parse_q_params(request.query_string)

            try:
                valuestr = json.dumps(request.get_json(),separators=(',',':'), sort_keys=True)
                body = json.loads(valuestr)
            except:
                return Response("Request cannot be parsed as json", 500)
            if q_params and q_params.get('_id'):
                if '_id' in body: del body['_id']
                records_updated = dbhelper.collection.update_one({"_id": ObjectId(q_params.get('_id'))}, {"$set" : body})
            else:
                return Response("ObjectId not provided", 404)

            if records_updated.modified_count > 0:
                return Response(json.dumps("Updated {} items!".format(records_updated.modified_count)), status=200, mimetype = 'application/json')
            else:
                return "", 404
        except:
            raise #return "", 500
Ejemplo n.º 5
0
 def get(self):
     """
     Function to get the userinfos.
     """
     try:
         dbhelper = DbHelper()
         q_params = utils.parse_q_params(request.query_string)
         if q_params:
             query = {
                 k: int(v) if isinstance(v, str) and v.isdigit() else v
                 for k, v in q_params.items()
             }
             records_fetched = dbhelper.collection.find(query)
             if records_fetched.count() > 0:
                 return json_util.dumps(records_fetched)
             else:
                 return "No Records found", 404
         else:
             if dbhelper.collection.find().count > 0:
                 return Response(dumps(dbhelper.collection.find()),
                                 mimetype='application/json')
             else:
                 return jsonify([])
     except:
         raise  #return "", 500
Ejemplo n.º 6
0
    def __init__(self, parent=None):
        super(MainWind, self).__init__(parent)
        self.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.WindowSystemMenuHint)
        self.setWindowModality(QtCore.Qt.WindowModal)
        self.setFixedSize(800, 500)

        self.db_helper = DbHelper()

        self.doctors_list = []
        self.code = str

        self.current_doctor = ActiveRecordDoctor(0, 0, " ", " ")

        self.but_enter = QtGui.QPushButton('Выбрать', self)
        self.rw_login = QtGui.QLineEdit()
        self.rw_pass = QtGui.QLineEdit()
        self.rw_doctor_name = QtGui.QComboBox()
        self.layout = QtGui.QVBoxLayout()
        self.frame_full = QtGui.QFrame()
        self.fr_empty = QtGui.QFrame()
        self.layout_2 = QtGui.QVBoxLayout()
        self.layout_3 = QtGui.QHBoxLayout()
        self.grid_start = QtGui.QGridLayout()
        self.frame_start = QtGui.QFrame()
        self.frame_start_empty = QtGui.QFrame()
        self.vlay_start = QtGui.QVBoxLayout()
        self.hlay_start = QtGui.QHBoxLayout()
        self.label = QtGui.QLabel('Криминалистическая лаборатория')

        self.filling()
Ejemplo n.º 7
0
    def __init__(self):
        self.db = DbHelper()
        sql = "CREATE TABLE IF NOT EXISTS `" + self.TABLE_NAME + "` (" \
              + self.FIELD_TITLE + " TEXT NOT NULL," \
              + self.FIELD_COUNT + " INT NOT NULL DEFAULT '1'," \
              + "PRIMARY KEY (`" + self.FIELD_TITLE + "`(100)));"

        self.db.execute(sql)
Ejemplo n.º 8
0
def main():
    # Communication object
    communication = Communication()
    # connecting to the client
    communication.connect()
    # connecting with database
    db = DbHelper("iot.db")
    db.connect_to_db()
    # receiving data from client and processing the data
    while 1:
        motion = Motion()
        motion.start()
        # receive the message
        recv_msg = communication.receive_data()
        # calls the handleRequest function to handle the message
        send_msg = handle_request(db, recv_msg)
        print(send_msg)

        communication.send_data(send_msg)
Ejemplo n.º 9
0
class CatagoryManager(object):
    TABLE_NAME = "catagory"
    FIELD_TITLE = "title"
    FIELD_COUNT = "count"

    def __init__(self):
        self.db = DbHelper()
        sql = "CREATE TABLE IF NOT EXISTS `" + self.TABLE_NAME + "` (" \
              + self.FIELD_TITLE + " TEXT NOT NULL," \
              + self.FIELD_COUNT + " INT NOT NULL DEFAULT '1'," \
              + "PRIMARY KEY (`" + self.FIELD_TITLE + "`(100)));"

        self.db.execute(sql)

    @checkDB
    def add(self, entry):
        for title in entry.catagories:
            sql = "INSERT INTO `" + self.TABLE_NAME + "` VALUES ('" \
                  + title + "', 1) " \
                  + "ON DUPLICATE KEY UPDATE " + self.FIELD_COUNT + " = " + self.FIELD_COUNT + " + 1;"
            self.db.execute(sql)

    @checkDB
    def clear(self):
        sql = "DELETE FROM " + self.TABLE_NAME + ";"
        self.db.execute(sql)
Ejemplo n.º 10
0
 def delete(self, id=None):
     """
     Function to delete a userinfo.
     """
     try:
         dbhelper = DbHelper()
         q_params = utils.parse_q_params(request.query_string)
         delete_user = dbhelper.collection.delete_one({"_id": ObjectId(id)})
         if delete_user.deleted_count > 0:
             return Response("Deleted {} items!".format(
                 delete_user.deleted_count),
                             status=204,
                             mimetype='application/json')
         else:
             return "", 404
     except:
         raise  #return "", 500
Ejemplo n.º 11
0
    def delete(self, collection=None, _id=None):
        """
        Function to delete a db.
        """
        try:
            if collection is None:
                return Response('Collection name cannot be null', status = 500)
            dbhelper =DbHelper(collectionName=collection)
            q_params = utils.parse_q_params(request.query_string)

            if q_params and q_params.get('_id'):
                delete_user = dbhelper.collection.delete_one({"_id": ObjectId(q_params.get('_id'))})
                if delete_user.deleted_count > 0 :
                    return Response("Deleted {} items!".format(delete_user.deleted_count), status=204, mimetype = 'application/json')
                else:
                    return Response("Record not found", 404)
            else:
                return Response("ObjectId not provided", 404)
        except:
            raise #return "", 500
Ejemplo n.º 12
0
    def put(self, id=None):
        """
        Function to update a userinfo.
        """
        try:
            dbhelper = DbHelper()
            try:
                body = ast.literal_eval(json.dumps(request.get_json()))
            except:
                return "", 400
            records_updated = dbhelper.collection.update_one(
                {"_id": ObjectId(id)}, body)

            if records_updated.modified_count > 0:
                return Response(jsonify("Updated {} items!".format(
                    records_updated.modified_count)),
                                status=200,
                                mimetype='application/json')
            else:
                return "", 404
        except:
            raise  #return "", 500
Ejemplo n.º 13
0
    def post(self):
        """
        Function to add new userinfo(s).
        """
        try:
            dbhelper = DbHelper()
            try:
                body = ast.literal_eval(json.dumps(request.get_json()))
            except:
                return "", 400

            record_created = dbhelper.collection.insert(body)

            if isinstance(record_created, list):
                return Response(jsonify([str(v) for v in record_created]),
                                status=201,
                                mimetype='application/json')
            else:
                return Response(jsonify(str(record_created)),
                                status=201,
                                mimetype='application/json')
        except:
            raise  #return "", 500
Ejemplo n.º 14
0
 def get(self, collection=None):
     """
     Function to get the dbs.
     """
     try:
         if collection is None:
             return Response('Collection name cannot be null', status = 500)
         dbhelper =DbHelper(collectionName=collection)
         q_params = utils.parse_q_params(request.query_string)
         if q_params:
             query = {k: ObjectId(v) if isinstance(v, str) and k=='_id' else v for k, v in q_params.items()}
             records_fetched = dbhelper.collection.find(query)
             if records_fetched.count() > 0:
                 return Response(dumps(records_fetched),status = 200)
             else:
                 return "No Records found", 404
         else:
             if dbhelper.collection.find().count > 0:
                 return Response(dumps(dbhelper.collection.find()), mimetype='application/json')
             else:
                 return jsonify([])
     except:
         raise #return "", 500
Ejemplo n.º 15
0
    def post(self, collection=None):
        """
        Function to add new db(s).
        """
        try:
            if collection is None:
                return Response('Collection name cannot be null', status = 500)
            dbhelper =DbHelper(collectionName=collection)
            try:
                valuestr = json.dumps(request.get_json(),separators=(',',':'), sort_keys=True)
                body = json.loads(valuestr)
            except:
                return Response("Request cannot be parsed as json", 500)

            if '_id' in body: del body['_id']

            record_created = dbhelper.collection.insert(body)

            if isinstance(record_created, list):
                return Response(json.dumps([str(v) for v in record_created]), status=201, mimetype = 'application/json')
            else:
                return Response(json.dumps(str(record_created)), status=201, mimetype = 'application/json')
        except:
            raise #return "", 500
Ejemplo n.º 16
0
class CatagoryManager(object):
    TABLE_NAME = "catagory"
    FIELD_TITLE = "title"
    FIELD_COUNT = "count"

    def __init__(self):
        self.db = DbHelper()
        sql = "CREATE TABLE IF NOT EXISTS `" + self.TABLE_NAME + "` (" \
              + self.FIELD_TITLE + " TEXT NOT NULL," \
              + self.FIELD_COUNT + " INT NOT NULL DEFAULT '1'," \
              + "PRIMARY KEY (`" + self.FIELD_TITLE + "`(100)));"

        self.db.execute(sql)
    @checkDB
    def add(self, entry):
        for title in entry.catagories:
            sql = "INSERT INTO `" + self.TABLE_NAME + "` VALUES ('" \
                  + title + "', 1) " \
                  + "ON DUPLICATE KEY UPDATE " + self.FIELD_COUNT + " = " + self.FIELD_COUNT + " + 1;"
            self.db.execute(sql)
    @checkDB
    def clear(self):
        sql = "DELETE FROM " + self.TABLE_NAME + ";"
        self.db.execute(sql)
Ejemplo n.º 17
0
class QueueProxy(object):
    TABLE_NAME = "queue"
    FIELD_URL = "url"
    FIELD_ID = "id"

    def __init__(self):
        self.db = DbHelper()
        sql = "CREATE TABLE IF NOT EXISTS `" + self.TABLE_NAME \
              + "` (" + self.FIELD_URL + " TEXT NOT NULL, " \
              + self.FIELD_ID + " INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`" + self.FIELD_ID + "`));"
        self.db.execute(sql)

    @checkDB
    def push(self, url):
        sql = "INSERT INTO " + self.TABLE_NAME + " (" + self.FIELD_URL + ") VALUES ('" + url + "');"
        self.db.execute(sql)

    @checkDB
    def pop(self):
        sql = "SELECT " + self.FIELD_URL + ", " + self.FIELD_ID + " FROM " + self.TABLE_NAME + " ORDER BY " + self.FIELD_ID + " LIMIT 1;"
        self.db.execute(sql)
        row = self.db.getResult()[0]
        url, id = row
        sql = "DELETE FROM " + self.TABLE_NAME + " WHERE " + self.FIELD_ID + " = " + str(
            id) + ";"
        self.db.execute(sql)
        return url

    def clear(self):
        sql = "DELETE FROM " + self.TABLE_NAME + ";"
        self.db.execute(sql)
Ejemplo n.º 18
0
 def __init__(self):
     self.db = DbHelper()
     sql = "CREATE TABLE IF NOT EXISTS `" + self.TABLE_NAME \
           + "` (" + self.FIELD_URL + " TEXT NOT NULL, " \
           + self.FIELD_ID + " INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`" + self.FIELD_ID + "`));"
     self.db.execute(sql)
Ejemplo n.º 19
0
class QueueProxy(object):
    TABLE_NAME = "queue"
    FIELD_URL = "url"
    FIELD_ID = "id"

    def __init__(self):
        self.db = DbHelper()
        sql = "CREATE TABLE IF NOT EXISTS `" + self.TABLE_NAME \
              + "` (" + self.FIELD_URL + " TEXT NOT NULL, " \
              + self.FIELD_ID + " INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`" + self.FIELD_ID + "`));"
        self.db.execute(sql)

    @checkDB
    def push(self, url):
        sql = "INSERT INTO " + self.TABLE_NAME + " (" + self.FIELD_URL + ") VALUES ('" + url + "');"
        self.db.execute(sql)

    @checkDB
    def pop(self):
        sql = "SELECT " + self.FIELD_URL + ", " + self.FIELD_ID + " FROM " + self.TABLE_NAME + " ORDER BY " + self.FIELD_ID + " LIMIT 1;"
        self.db.execute(sql)
        row = self.db.getResult()[0]
        url, id = row
        sql = "DELETE FROM " + self.TABLE_NAME + " WHERE " + self.FIELD_ID + " = " + str(id) + ";"
        self.db.execute(sql)
        return url

    def clear(self):
        sql = "DELETE FROM " + self.TABLE_NAME + ";"
        self.db.execute(sql)
Ejemplo n.º 20
0
class EntryManager:
    TABLE_NAME = "entry"
    FIELD_TITLE = "title"
    FIELD_URL = "url"
    FIELD_COUNT = "count"

    def __init__(self):
        self.db = DbHelper()
        sql = "CREATE TABLE IF NOT EXISTS `" + self.TABLE_NAME + "` (" \
              + self.FIELD_URL + " TEXT NOT NULL," \
              + self.FIELD_TITLE + " TEXT NOT NULL," \
              + self.FIELD_COUNT + " INT NOT NULL DEFAULT '1'," \
              + "PRIMARY KEY (`" + self.FIELD_URL + "`(100)));"

        self.db.execute(sql)

    @checkDB
    def add(self, entry):
        sql = "INSERT INTO `" + self.TABLE_NAME + "` VALUES ('" \
              + entry.url + "', '" + entry.title + "', 1);"
        self.db.execute(sql)

    @checkDB
    def update(self, url):
        sql = "UPDATE " + self.TABLE_NAME + " SET " \
              + self.FIELD_COUNT + " = " + self.FIELD_COUNT + " + 1 WHERE " + self.FIELD_URL + " = '" + url + "';"
        self.db.execute(sql)

    @checkDB
    def clear(self):
        sql = "DELETE FROM " + self.TABLE_NAME + ";"
        self.db.execute(sql)

    @checkDB
    def contains(self, url):
        sql = "SELECT * FROM `" + self.TABLE_NAME + "` WHERE " + self.FIELD_URL + " = '" + url + "';"
        self.db.execute(sql)
        rows = self.db.getResult()
        return len(rows) > 0
Ejemplo n.º 21
0
def after_request(response):
    response.headers["Cache-Control"] = "no-cache, no-store, must-re-validate"
    response.headers["Expires"] = 0
    response.headers["Pragma"] = "no-cache"
    return response


# Configure session to use filesystem (instead of signed cookies)
app.config["SESSION_FILE_DIR"] = mkdtemp()
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)

# Configure to use database
dbfile = "data.db"
db = DbHelper(cfg)

# Start the upkeep thread for renewals
if cfg.get_site()['site'] != "http://127.0.0.1:5000":
    upkeep = Upkeep(db, project_directory)

# The family class helps with family memberships
family = FamilyClass(dbfile)
# The square class helps with purchases
square = square_handler(cfg)
# The member class represents a member and has member functions.
mdb = Member(db, project_directory)
# PayLogHelper class is for logging payments.
pay_log = PayLogHelper(db)
# Email class for sending emails.
email_helper = Email(project_directory)
Ejemplo n.º 22
0
 def __init__(self):
     self.db = DbHelper()
     sql = "CREATE TABLE IF NOT EXISTS `" + self.TABLE_NAME \
           + "` (" + self.FIELD_URL + " TEXT NOT NULL, " \
           + self.FIELD_ID + " INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`" + self.FIELD_ID + "`));"
     self.db.execute(sql)
Ejemplo n.º 23
0
    def lisiten_msg(recv_msg):
        # print(recv_msg['MsgType'])  # 1:文本    3:图片      34:语音     47:表情     49:红包     62:视频     10000:系统信息
        # print(recv_msg['User'])
        # print(recv_msg['User']['MemberList'])
        # print(recv_msg['User']['NickName'])
        # print(recv_msg['Text'])
        # print(recv_msg)

        dbhelper = DbHelper()
        sql = """ INSERT INTO ITCHAT_MSGINFO (MSG_ID,
                FR_USERNAME,
                TO_USERNAME,
                MSG_TYPE,
                CONTENT,
                STATUS,
                IMG_STATUS,
                CREATE_TIME,
                VOICE_LENGTH,
                PLAY_LENGTH,
                FILE_NAME,
                FILE_SIZE,
                MEDIAL_ID,
                URL,
                APP_MSG_TYPE,
                STATUSNOTIFYCODE,
                STATUSNOTIFYUSERNAME,
                REC_USERNAME,
                REC_NICKNAME,
                REC_QQNUM,
                REC_PROVINCE,
                REC_CITY,
                REC_CONTENT,
                REC_SIGNATURE,
                REC_ALIAS,
                REC_SCENE,
                REC_VERIFYFLAG,
                REC_ATTRSTATUS,
                REC_SEX,
                REC_TICKET,
                REC_OPCODE,
                FORWARDFLAG,
                APP_ID,
                APP_TYPE,
                HASPRODUCTID,
                TICKET,
                IMGHEIGHT,
                IMGWIDTH,
                SUBMSGTYPE,
                NEWMSGID,
                ORICONTENT,
                ENCRYFILENAME,
                -- USER_MEMBERLIST,
                USER_UIN,
                USER_USERNAME,
                USER_NICKNAME,
                USER_HEADIMGURL,
                USER_CONTACTFLAG,
                USER_MEMBERCOUNT,
                USER_REMARKNAME,
                USER_HIDEINPUTBARFLAG,
                USER_SEX,
                USER_SIGNATURE,
                USER_VERIFYFLAG,
                USER_OWNERUIN,
                USER_PYINITIAL,
                USER_PYQUANPIN,
                USER_REMARKPYINITIAL,
                USER_REMARKPYQUANPIN,
                USER_STARFRIEND,
                USER_APPACCOUNTFLAG,
                USER_STATUES,
                USER_ATTRSTATUS,
                USER_PROVINCE,
                USER_CITY,
                USER_ALIAS,
                USER_SNSFLAG,
                USER_UNIFRIEND,
                USER_DISPLAYNAME,
                USER_CHATROOMID,
                USER_KEYWORD,
                USER_ENCRYCHATROOMID,
                USER_ISOWNER,
                TYPE,
                TEXT,
                ISFRIENDCHAT,
                ISGROUPCHAT,
                ISMPCHAT) VALUES
                (:MSG_ID,
                :FR_USERNAME,
                :TO_USERNAME,
                :MSG_TYPE,
                :CONTENT,
                :STATUS,
                :IMG_STATUS,
                :CREATE_TIME,
                :VOICE_LENGTH,
                :PLAY_LENGTH,
                :FILE_NAME,
                :FILE_SIZE,
                :MEDIAL_ID,
                :URL,
                :APP_MSG_TYPE,
                :STATUSNOTIFYCODE,
                :STATUSNOTIFYUSERNAME,
                :REC_USERNAME,
                :REC_NICKNAME,
                :REC_QQNUM,
                :REC_PROVINCE,
                :REC_CITY,
                :REC_CONTENT,
                :REC_SIGNATURE,
                :REC_ALIAS,
                :REC_SCENE,
                :REC_VERIFYFLAG,
                :REC_ATTRSTATUS,
                :REC_SEX,
                :REC_TICKET,
                :REC_OPCODE,
                :FORWARDFLAG,
                :APP_ID,
                :APP_TYPE,
                :HASPRODUCTID,
                :TICKET,
                :IMGHEIGHT,
                :IMGWIDTH,
                :SUBMSGTYPE,
                :NEWMSGID,
                :ORICONTENT,
                :ENCRYFILENAME,
                -- :USER_MEMBERLIST,
                :USER_UIN,
                :USER_USERNAME,
                :USER_NICKNAME,
                :USER_HEADIMGURL,
                :USER_CONTACTFLAG,
                :USER_MEMBERCOUNT,
                :USER_REMARKNAME,
                :USER_HIDEINPUTBARFLAG,
                :USER_SEX,
                :USER_SIGNATURE,
                :USER_VERIFYFLAG,
                :USER_OWNERUIN,
                :USER_PYINITIAL,
                :USER_PYQUANPIN,
                :USER_REMARKPYINITIAL,
                :USER_REMARKPYQUANPIN,
                :USER_STARFRIEND,
                :USER_APPACCOUNTFLAG,
                :USER_STATUES,
                :USER_ATTRSTATUS,
                :USER_PROVINCE,
                :USER_CITY,
                :USER_ALIAS,
                :USER_SNSFLAG,
                :USER_UNIFRIEND,
                :USER_DISPLAYNAME,
                :USER_CHATROOMID,
                :USER_KEYWORD,
                :USER_ENCRYCHATROOMID,
                :USER_ISOWNER,
                :TYPE,
                :TEXT,
                :ISFRIENDCHAT,
                :ISGROUPCHAT,
                :ISMPCHAT) """
        params = {
            'MSG_ID': recv_msg['MsgId'],
            'FR_USERNAME': recv_msg['FromUserName'],
            'TO_USERNAME': recv_msg['ToUserName'],
            'MSG_TYPE': recv_msg['MsgType'],
            'CONTENT': recv_msg['Content'],
            'STATUS': recv_msg['Status'],
            'IMG_STATUS': recv_msg['ImgStatus'],
            'CREATE_TIME': datetime.fromtimestamp((recv_msg['CreateTime'])),
            'VOICE_LENGTH': recv_msg['VoiceLength'],
            'PLAY_LENGTH': recv_msg['PlayLength'],
            'FILE_NAME': recv_msg['FileName'],
            'FILE_SIZE': recv_msg['FileSize'],
            'MEDIAL_ID': recv_msg['MediaId'],
            'URL': recv_msg['Url'],
            'APP_MSG_TYPE': recv_msg['AppMsgType'],
            'STATUSNOTIFYCODE': recv_msg['StatusNotifyCode'],
            'STATUSNOTIFYUSERNAME': recv_msg['StatusNotifyUserName'],
            'REC_USERNAME': recv_msg['RecommendInfo']['UserName'],
            'REC_NICKNAME': recv_msg['RecommendInfo']['NickName'],
            'REC_QQNUM': recv_msg['RecommendInfo']['QQNum'],
            'REC_PROVINCE': recv_msg['RecommendInfo']['Province'],
            'REC_CITY': recv_msg['RecommendInfo']['City'],
            'REC_CONTENT': recv_msg['RecommendInfo']['Content'],
            'REC_SIGNATURE': recv_msg['RecommendInfo']['Signature'],
            'REC_ALIAS': recv_msg['RecommendInfo']['Alias'],
            'REC_SCENE': recv_msg['RecommendInfo']['Scene'],
            'REC_VERIFYFLAG': recv_msg['RecommendInfo']['VerifyFlag'],
            'REC_ATTRSTATUS': recv_msg['RecommendInfo']['AttrStatus'],
            'REC_SEX': recv_msg['RecommendInfo']['Sex'],
            'REC_TICKET': recv_msg['RecommendInfo']['Ticket'],
            'REC_OPCODE': recv_msg['RecommendInfo']['OpCode'],
            'FORWARDFLAG': recv_msg['ForwardFlag'],
            'APP_ID': recv_msg['AppInfo']['AppID'],
            'APP_TYPE': recv_msg['AppInfo']['Type'],
            'HASPRODUCTID': recv_msg['HasProductId'],
            'TICKET': recv_msg['Ticket'],
            'IMGHEIGHT': recv_msg['ImgHeight'],
            'IMGWIDTH': recv_msg['ImgWidth'],
            'SUBMSGTYPE': recv_msg['SubMsgType'],
            'NEWMSGID': recv_msg['NewMsgId'],
            'ORICONTENT': recv_msg['OriContent'],
            'ENCRYFILENAME': recv_msg['EncryFileName'],
            # 'USER_MEMBERLIST':recv_msg['User']['MemberList'],
            'USER_UIN': recv_msg['User']['Uin'],
            'USER_USERNAME': recv_msg['User']['UserName'],
            'USER_NICKNAME': recv_msg['User']['NickName'],
            'USER_HEADIMGURL': recv_msg['User']['HeadImgUrl'],
            'USER_CONTACTFLAG': recv_msg['User']['ContactFlag'],
            'USER_MEMBERCOUNT': recv_msg['User']['MemberCount'],
            'USER_REMARKNAME': recv_msg['User']['RemarkName'],
            'USER_HIDEINPUTBARFLAG': recv_msg['User']['HideInputBarFlag'],
            'USER_SEX': recv_msg['User']['Sex'],
            'USER_SIGNATURE': recv_msg['User']['Signature'],
            'USER_VERIFYFLAG': recv_msg['User']['VerifyFlag'],
            'USER_OWNERUIN': recv_msg['User']['OwnerUin'],
            'USER_PYINITIAL': recv_msg['User']['PYInitial'],
            'USER_PYQUANPIN': recv_msg['User']['PYQuanPin'],
            'USER_REMARKPYINITIAL': recv_msg['User']['RemarkPYInitial'],
            'USER_REMARKPYQUANPIN': recv_msg['User']['RemarkPYQuanPin'],
            'USER_STARFRIEND': recv_msg['User']['StarFriend'],
            'USER_APPACCOUNTFLAG': recv_msg['User']['AppAccountFlag'],
            'USER_STATUES': recv_msg['User']['Statues'],
            'USER_ATTRSTATUS': recv_msg['User']['AttrStatus'],
            'USER_PROVINCE': recv_msg['User']['Province'],
            'USER_CITY': recv_msg['User']['City'],
            'USER_ALIAS': recv_msg['User']['Alias'],
            'USER_SNSFLAG': recv_msg['User']['SnsFlag'],
            'USER_UNIFRIEND': recv_msg['User']['UniFriend'],
            'USER_DISPLAYNAME': recv_msg['User']['DisplayName'],
            'USER_CHATROOMID': recv_msg['User']['ChatRoomId'],
            'USER_KEYWORD': recv_msg['User']['KeyWord'],
            'USER_ENCRYCHATROOMID': recv_msg['User']['EncryChatRoomId'],
            'USER_ISOWNER': recv_msg['User']['IsOwner'],
            'TYPE': recv_msg['Type'],
            'TEXT': recv_msg['Text'],
            'ISFRIENDCHAT': '1',
            'ISGROUPCHAT': '0',
            'ISMPCHAT': '0'
        }

        if dbhelper.Execute(sql, params):
            ...
Ejemplo n.º 24
0
 def __init__(self):
     self.db_helper = DbHelper()
     self.doctors_list = []
     self.patients_list = []
Ejemplo n.º 25
0
import json
from entities import Dataset
from DbHelper import DbHelper
from errors import MoreThanOneResultError

db = DbHelper()


def add_dataset(dataset):
    """
    Method gets the formatted insert query from the given Dataset object and
    executes insert method on the DbHelper object in order to insert Dataset
    object values to the database
    :param dataset: Dataset object to be inserted to the database
    :return: the same Dataset object with ID in database after insert
    """
    dataset.dataset_id = db.insert(dataset.get_insert_query())
    return dataset


def get_dataset(dataset):
    """
    Method gets the formatted query from the given dataset object and
    executes the query method on the DbHelper object in order to fetch values
    and fill the Dataset object from database
    :param dataset: Dataset object with ID to be filled with other details
    :return: the same Dataset object filled with details after search query
    """
    result = db.query(dataset.get_search_query())
    if len(result) != 1:
        raise MoreThanOneResultError()
Ejemplo n.º 26
0
    def download_otodom_offers(self, no_of_pages=1, delay=0):
        offers = self.get_otodom_offers(no_of_pages, delay)

        with DbHelper() as db:
            db.save_offers(offers)
        return offers
Ejemplo n.º 27
0
from HandleFiles import HandleFiles
from DbHelper import DbHelper

path = raw_input('HandleFiles in Path : ')

a = HandleFiles()
b = DbHelper()

b.create_table_on_db()
a.scan_for_files_with_extension(path)


file = a.get_file()

files = file.split(" - ")


for file in files:
    if not file: continue
    b.insert_value_in_table(file)
Ejemplo n.º 28
0
# Trap init, set input IFC
trap = pytrap.TrapCtx()
trap.init(sys.argv, 1, 0)
trap.setRequiredFmt(0, pytrap.FMT_UNIREC)

# Set Logger
logger = logging.getLogger('[COLIOT]')
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

# Init DbHelper - SQLite DB
helper = DbHelper()
helper.connect()

# Read templates
reader = TemplateReader()
templates = reader.getTml()

# Main loop
while True:
    try:
        data = trap.recv()
    except pytrap.FormatChanged as e:
        fmttype, inputspec = trap.getDataFmt(0)
        rec = pytrap.UnirecTemplate(inputspec)
        data = e.data
    if len(data) <= 1:
Ejemplo n.º 29
0
 def __init__(self):
     self.db = DbHelper("iot.db")
     self.db.connect_to_db()