print(filename) json_file = open(SETTINGS.JSON_PATH + filename, 'r') json_data = json.load(json_file) for i in range(0, len(json_data)): data = json_data[i] if data['LOCALITATE'] != 'BUCURESTI': if data['URBAN/RURAL'] == 'URBAN': city = data['LOCALITATE'] #INSERT INTO locality (city, village, commune, urban) VALUES (1, 'Alba Iulia', '', '', True); command = "INSERT INTO locality (city, village, commune, urban) VALUES ('%s', '%s', '%s', %s);" %( city, '', '', True) else: commune = data['ADRESA'].split(',')[0] village = data['LOCALITATE'] command = "INSERT INTO locality (city, village, commune, urban) VALUES ('%s', '%s', '%s', %s);" %( '', village, commune, False) else: #INSERT INTO locality (city, village, commune, urban, sector) VALUES (10, 'Bucuresti', '', '', True, 'sector 1'); sector = SETTINGS.COUNTY[data['JUD/SECT']] command = "INSERT INTO locality (city, village, commune, urban, sector) VALUES ('%s', '%s', '%s', %s, '%s');" %( 'Bucuresti', '', '', True, sector) if db.select_locality(con, data) == 0: file.write(command) file.write('\n') db.execute_query(con, command) file.close()
address.scale.strip(' '), address.address_componenets['locality'].strip(' '), address.address_componenets['city'].strip(' '), address.address_componenets['commune'].strip(' '), sector.strip(' '), address.address_componenets['county'].strip(' '), address.address_componenets['postal_code'].strip(' '), address.full_address.strip(' '), address.address_componenets['latitude'], address.address_componenets['longitude'], address.address_componenets['place_id'] ) row = str(unicodedata.normalize('NFD', str(sql_address_row)).encode('ascii', 'ignore')) print('INSERT IN ADDRESS:', row[2:len(row)-1]) db.execute_query(con, row[2:len(row)-1]) # company company = Company(json_data[i]) company_id = db.select_id(con, "SELECT id FROM company WHERE LOWER(name)=LOWER('%s');" % company.name) if company_id == 0: sql_company_row = "INSERT INTO company (name) VALUES ('%s');" % (company.name) row = str(unicodedata.normalize('NFD', str(sql_company_row)).encode('ascii', 'ignore')) print('INSERT IN COMPANY:', row[2:len(row)-1]) db.execute_query(con, row[2:len(row)-1]) company_id = db.select_id(con, "SELECT id FROM company WHERE LOWER(name)=LOWER('%s');" % company.name) # pharmacy pharmacy = Pharmacy(json_data[i], address) county = str(unicodedata.normalize('NFD', str(address.address_componenets['county'])).encode('ascii', 'ignore')) county_name = county[2:len(county)-1]
@property def start_time(self): d = {1:"06:00", 2:"06:30", 3:"07:00", 4:"07:30", 5:"08:00", 6:"08:30", 7:"09:00", 8:"09:30", 9:"10:00"} self.__start_time = d[int(random.uniform(1,10))] return self.__start_time @property def end_time(self): d = {1:"17:00", 2:"17:30", 3:"18:00", 4:"18:30", 5:"19:00", 6:"19:30", 7:"20:00", 8:"20:30", 9:"21:00", 10:"21:30", 11:"22:00", 12:"22:30", 13:"23:00", 13:"23:30", 14:"00:00"} self.__end_time = d[int(random.uniform(1,15))] return self.__end_time if __name__ == "__main__": db = DatabaseConnection(SETTINGS.DATABASE_NAME, SETTINGS.DATABASE_USERNAME, SETTINGS.DATABASE_PASSWORD) con = db.connection db.reset_tables(con, "faw_create_timetable.sql") not_id = [575, 1961, 4902, 5629, 7435] + list(range(6410, 6466)) + list(range(8531, 8543)) pharmacies_id = db.count_all(con, "SELECT * FROM pharmacy;") for p_id in range(1, pharmacies_id): if p_id in not_id: continue timetable = Timetable() query = "INSERT INTO timetable (monday, tuesday, wednesday, thursday, friday, saturday, sunday, start_time, end_time, pharmacy_id) VALUES (%s, %s, %s, %s, %s, %s, %s, '%s', '%s', %d)" % ( timetable.monday, timetable.tuesday, timetable.wednesday, timetable.thursday, timetable.friday, timetable.saturday, timetable.sunday, timetable.start_time, timetable.end_time, p_id) print("INSERT IN TIMETABLE:", query) db.execute_query(con, query)