コード例 #1
0
ファイル: address_pharmacy.py プロジェクト: tudormi/FaW
    @property
    def observation(self):
        try:
            self.__observation = self.json_data['OBSERVATII']
        except KeyError:
            self.__observation = ''
        return self.__observation


if __name__ == "__main__":
    filename = sys.argv[1]

    start = int(sys.argv[3])
    API_KEY = sys.argv[2]
    db = DatabaseConnection(SETTINGS.DATABASE_NAME, SETTINGS.DATABASE_USERNAME, SETTINGS.DATABASE_PASSWORD)
    con = db.connection
    #db.reset_tables(con, "faw_create_address_pharmacy_company.sql")

    address_counter = db.count_all(con, "SELECT * FROM address;")

    json_file = open(SETTINGS.JSON_PATH + filename, 'r')
    json_data = json.load(json_file)

    addresses = [json_data[x]['ADRESA'] for x in range(0, len(json_data))]
    localities = [json_data[x]['LOCALITATE'] for x in range(0, len(json_data))]
    cities = [SETTINGS.COUNTY[json_data[x]['JUD/SECT']] for x in range(0, len(json_data))]

    end = len(json_data)

    for i in range(start, end):
コード例 #2
0
ファイル: locality.py プロジェクト: tudormi/FaW
import json
import os

from databasehelper import DatabaseConnection
from settings import SETTINGS

if __name__ == "__main__":
    db = DatabaseConnection(SETTINGS.DATABASE_NAME, SETTINGS.DATABASE_USERNAME, SETTINGS.DATABASE_PASSWORD)
    con = db.connection

    #table = open(SETTINGS.SQL_PATH + "faw_create_locality.sql", 'r').read()
    #db.execute_query(con, table)
    db.reset_tables(con, "faw_create_locality.sql")

    try:
        os.remove(SETTINGS.SQL_PATH + "insert_locality.sql")
    except OSError:
        pass

    file = open(SETTINGS.SQL_PATH + "insert_locality.sql", 'a')
    for filename in os.listdir(SETTINGS.JSON_PATH):
        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']
コード例 #3
0
ファイル: medicine.py プロジェクト: tudormi/FaW
            db.execute_query(con, query_one)
            composition_id = db.count_all(con, "SELECT * FROM composition;")
            print(composition_id, medicine_id)
            query_two = "INSERT INTO medicine_composition (medicine_id, composition_id) VALUES (%d, %d)" % (
                medicine_id, composition_id)
            print("INSERT IN MED_COMP:", query_two)
            db.execute_query(con, query_two)
        else:
            query_two = "INSERT INTO medicine_composition (medicine_id, composition_id) VALUES (%d, %d)" % (
                medicine_id, comp_id_if_exists)
            print("INSERT IN MED_COMP: ", query_two)
            db.execute_query(con, query_two)


if __name__ == "__main__":
    db = DatabaseConnection(SETTINGS.DATABASE_NAME, SETTINGS.DATABASE_USERNAME, SETTINGS.DATABASE_PASSWORD)
    con = db.connection

    db.reset_tables(con, "faw_create_medicine_composition.sql")

    json_file = open(SETTINGS.JSON_PATH + '_medicine_list.json', 'r')
    json_data = json.load(json_file)

    for i in range(0, len(json_data)):
        data = json_data[i]

        # medicine
        medicine = Medicine(data)
        query = "INSERT INTO medicine (name, concentrate, package, form, producer, producer_country, price) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %.2f);" %(
            medicine.name, medicine.concentrate, medicine.package, medicine.form,
            medicine.producer, medicine.producer_country, medicine.price)
コード例 #4
0
ファイル: timetable.py プロジェクト: tudormi/FaW
    @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)
コード例 #5
0
ファイル: pharmacy_medicine.py プロジェクト: tudormi/FaW
        self.pharmacy_len = pharmacy_len
        self.medicine_len = medicine_len

    @property
    def pharmacy_id(self):
        self.__pharmacy_id = random.randint(1, self.pharmacy_len)
        return self.__pharmacy_id

    @property
    def medicine_id(self):
        self.__medicine_id = random.randint(1, self.medicine_len)
        return self.__medicine_id


if __name__ == "__main__":
    db = DatabaseConnection(SETTINGS.DATABASE_NAME, SETTINGS.DATABASE_USERNAME, SETTINGS.DATABASE_PASSWORD)
    con = db.connection
    db.reset_tables(con, "faw_create_pharmacy_medicine.sql")
    
    pharmacy_len = db.count_all(con, "SELECT * FROM pharmacy;")
    medicine_len = db.count_all(con, "SELECT * FROM medicine;")
    
    pharmacy_medicine = PharmacyMedicine(pharmacy_len, medicine_len)
    
    for i in range(1, 10000):
        while True:
            pharm_id = pharmacy_medicine.pharmacy_id
            med_id = pharmacy_medicine.medicine_id
            query_search = "SELECT * FROM pharmacy_medicine WHERE pharmacy_id=%d and medicine_id=%d;" % (pharm_id, med_id)
            try:
                query_count_results = db.count_all(con, query_search)