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_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")