Example #1
0
 def insert_new_pictures(self, id, file_name):
     fs = FilesUtils()
     sql = """update workers
             set picture = {x}
             WHERE id = {y}""".format(x=str(
         fs.file_to_stream(file_name, fs.get_new_path())),
                                      y=id)
     self.custom_query(sql.strip())
     self.connection.commit()
Example #2
0
    def insert_new_pictures_links(self, picture, id):
        fs = FilesUtils()
        path = "'" + str(fs.get_new_path() + picture).replace("\\",
                                                              "\\\\") + "'"
        sql = """update workers
                     set Link_to_picture = {x}
                     WHERE id = {y}""".format(x=path, y=id)

        self.custom_query(sql.strip())
        self.connection.commit()
Example #3
0
 def insert_pictures_links(self):
     fs = FilesUtils()
     i = 1
     for file in fs.get_files(fs.get_path()):
         path = "'" + str(fs.get_path() + file).replace("\\", "\\\\") + "'"
         sql = """update workers
               set Link_to_picture = {x}
               WHERE id = {y}""".format(x=path, y=str(i))
         i += 1
         self.custom_query(sql.strip())
Example #4
0
    def insert_xml(self, xml_file_name, id):
        fs = FilesUtils()
        xml_file = open(fs.get_new_path() + xml_file_name + ".xml")
        xml_data = xml_file.read()

        sql = """update workers
                   set XML = '{x}'
                   WHERE id = {y}""".format(x=xml_data, y=id)
        self.custom_query(sql.strip())
        self.connection.commit()
class XmlGenerator:
    def __init__(self, connection):
        self.connection = connection
        self.cursor = connection.cursor()
        self.qu = Query(self.connection)
        self.fu = FilesUtils()

    def export_to_xml(self, id):
        try:
            result = self.qu.custom_query("select * from workers where id=" +
                                          str(id))
            result = list(result[0])
            first_name = result[2]
            print("Start generating xml file: " + first_name + ".xml")
            xml_file = open(self.fu.get_path_exp() + first_name + ".xml", 'w')
            xml_file.write('<?xml version="1.0" ?>\n')
            xml_file.write('<workers>\n')
            xml_file.write('<first name>%s</first name>\n' % result[1])
            xml_file.write('<last name>%s</last name>\n' % result[2])
            xml_file.write('<Picture>%s</Picture>\n' % result[3])
            xml_file.write('<hierarchy>%s</hierarchy>\n' % result[5])
            xml_file.write('</workers>\n')
            xml_file.flush()
            xml_file.close()
            print("XML generated correctly")

        except Exception as ex:
            print(ex)
            print("XML generation failed")

    def generate_xml(self, last_name, *args):
        try:

            print("Start generating xml file: " + last_name + ".xml")
            xml_file = open(self.fu.get_new_path() + last_name + ".xml", 'w')
            xml_file.write('<?xml version="1.0" ?>\n')
            xml_file.write('<INFO>\n')
            for arg in args:
                xml_file.write('<{x}>{y}</{x}>\n'.format(x=arg[0], y=arg[1]))

            xml_file.write('</INFO>\n')
            xml_file.flush()
            xml_file.close()
            print("XML generated correctly")

        except Exception as ex:
            print(ex)
            print("XML generation failed")
Example #6
0
class Display:
    def __init__(self):

        self.fu = FilesUtils()
        self.path = self.fu.get_path()

    def display_picture_from_db(self, memory_view):
        try:
            x = random_string(30)
            temp_file_name = 'tempFile' + x + '.jpg'
            temp_file_path = self.path + temp_file_name
            byte = bytes(memory_view[0]
                         [0])  # memoryView to lista krotek obiektów memoryview
            print(byte)
            open(temp_file_path, 'wb').write(byte)
            self.image = Image.open(temp_file_path).show()

        except Exception as ex:
            print(ex)

        finally:
            time.sleep(2)
            self.fu.remove_file(temp_file_name)

    def display_pictures_fom_db(self, memory_views):

        for view in memory_views:
            try:

                input("press any key to display next picture: ")
                self.display_picture_from_db(view)
                time.sleep(2)
                del self.image
            except Exception as ex:
                print(ex)

    def display_pictures_via_path(self, paths):
        for path in paths:
            try:
                input("press any key to display next picture: ")
                self.image = Image.open(path[0][0], 'r').show()
            except Exception as ex:
                print(ex)

            finally:
                time.sleep(2)
                del self.image
Example #7
0
    def insert_pictures(self):
        fs = FilesUtils()
        i = 1
        for file in fs.get_files(fs.get_path()):
            sql = """update workers
            set picture = {x}
            WHERE id = {y}""".format(x=str(
                fs.file_to_stream(file, fs.get_path())),
                                     y=str(i))
            i += 1

            self.custom_query(sql.strip())
 def __init__(self, connection):
     self.connection = connection
     self.cursor = connection.cursor()
     self.qu = Query(self.connection)
     self.fu = FilesUtils()
Example #9
0
    def __init__(self):

        self.fu = FilesUtils()
        self.path = self.fu.get_path()