def synachronize_sqlite_with_firebase():
    if (InternetConnection.is_connected_to_network()):
        firebaseDBManager = DBManager.FirebaseDBManager()
        all_data = firebaseDBManager.getAllData()

        sqlitebaseDBManager = DBManager.SQLiteDBManager()
        if (all_data != None):
            for id in all_data:
                data, existence = verify_item_existence_in_sqlite(id)
                # break;
                if (not existence):

                    temp_dict = all_data[id]
                    temp_dict['ID'] = id
                    sqlitebaseDBManager.insert(temp_dict)

                    fileManager = FileManager.FileManager()
                    fileManager.download(id)

                if (existence):
                    dict_firebase = all_data[id]
                    dict_firebase['ID'] = id

                    # sqlitebaseDBManager = DBManager.SQLiteDBManager()
                    dict_sqlite, existence = sqlitebaseDBManager.getSpecificData(id)

                    # dict_sqlite = convert_to_dict(data_sqlite)

                    compare_two_dictionaries(dict_firebase, dict_sqlite)

                    fileManager = FileManager.FileManager()
                    fileManager.download(id)

            for sqlite_data_id in sqlitebaseDBManager.getAllIDs():

                try:
                    if sqlite_data_id not in all_data.keys():
                        sqlitebaseDBManager.delete(sqlite_data_id)

                        fileManager = FileManager.FileManager()
                        fileManager.remove_from_local(sqlite_data_id)

                except:
                    print("")
        else:
            for sqlite_data_id in sqlitebaseDBManager.getAllIDs():
                try:
                    sqlitebaseDBManager.delete(sqlite_data_id)
                    fileManager = FileManager.FileManager()
                    fileManager.remove_from_local(sqlite_data_id)

                except:
                    print("")
Esempio n. 2
0
    def __init__(self, top=None, name=None):

        top.destroy()
        root = Tk()

        root.geometry("600x450+364+221")
        root.minsize(1, 1)
        root.maxsize(1265, 994)
        root.resizable(1, 1)
        root.title("Image Viewer")
        root.configure(cursor="watch")

        self.last_img_object_list = []
        self.ButtonNext = Button(root, command=lambda: self.load_next_image(root))
        self.ButtonNext.place(relx=0.833, rely=0.889, height=31, width=59)
        self.ButtonNext.configure(text='''Next''')

        self.ButtonPrevious = Button(root, command=lambda:self.load_prev_image(root))
        self.ButtonPrevious.place(relx=0.667, rely=0.889, height=31, width=84)
        self.ButtonPrevious.configure(text='''Previous''')

        self.ButtonBack = Button(root, command=lambda: self.go_back(root))
        self.ButtonBack.place(relx=0.501, rely=0.889, height=31, width=84)
        self.ButtonBack.configure(text='''Back''')

        sqliteManager = DBManager.SQLiteDBManager()
        self.all_names = sqliteManager.getAllNames()
        self.current_name = name
        self.current_index = self.all_names.index(self.current_name)

        self.load_current_image(self.current_name, root)

        root.mainloop()
def compare_two_dictionaries(dict_firebase, dict_sqlite):
    if(dict_firebase == dict_sqlite):

        return
    else:
        sqlitebaseDBManager = DBManager.SQLiteDBManager()
        sqlitebaseDBManager.update(dict_sqlite['ID'], 'Name', dict_firebase['Name'])
        sqlitebaseDBManager.update(dict_sqlite['ID'], 'Phone', dict_firebase['Phone'])
        sqlitebaseDBManager.update(dict_sqlite['ID'], 'Note', dict_firebase['Note'])
        sqlitebaseDBManager.update(dict_sqlite['ID'], 'Gender', dict_firebase['Gender'])
        sqlitebaseDBManager.update(dict_sqlite['ID'], 'Date', dict_firebase['Date'])
        sqlitebaseDBManager.update(dict_sqlite['ID'], 'Address', dict_firebase['Address'])
    def run(self):
        while True:
            try:
                dbManager = DBManager.SQLiteDBManager()
                self.Scrolledtreeview1.delete(
                    *self.Scrolledtreeview1.get_children())
                dbManager.fill_treeview(self.Scrolledtreeview1)

                self.set_label_no_of_images()
                time.sleep(self.interval)
            except:
                print("")
Esempio n. 5
0
    def load_current_image(self, name, root):
        sqliteManager = DBManager.SQLiteDBManager()
        id_dict, exist = sqliteManager.getSpecificDataFromName(name)

        if (exist == 1):
            image_path = "images/" + id_dict['ID'] + "/image.jpg"
            saved_image, opened = self.open_resized_image(image_path)
            self.last_img_object_list.append(saved_image)

            self.img = Label(root, image=self.last_img_object_list[-1])
            # self.img.place(relx=0.101, rely=0.2)
            self.img.place(relx=0.41, rely=0.023, height=21, width=79)
            self.img.image = self.last_img_object_list[-1]
            self.img.pack()
def update_feature_by_name(name, data):

    firebase_manager = DBManager.FirebaseDBManager()
    id = find_object_id_by_name(name, firebase_manager)

    if(id != None):
        firebase_manager.update(id, 'Name', data['Name'])
        firebase_manager.update(id, 'Phone', data['Phone'])
        firebase_manager.update(id, 'Note', data['Note'])
        firebase_manager.update(id, 'Gender', data['Gender'])
        firebase_manager.update(id, 'Address', data['Address'])
    else:
        messagebox.showwarning("Not found",
                               "Name Not Found!!")
def get_selected_image(name):
    sqliteManager = DBManager.SQLiteDBManager()
    id_dict, exist = sqliteManager.getSpecificDataFromName(name)

    if (exist == 1):
        path = "./images/"+id_dict['ID']+"/image.jpg"
        im = Image.open(path)

        width = 300
        wpercent = (width / float(im.size[0]))
        hsize = int((float(im.size[1]) * float(wpercent)))
        newsize = (width, hsize)
        im = im.resize(newsize)
        im.show()
    def add_feature(self):
        if (InternetConnection.is_connected_to_network()):
            name = self.EntryName.get()
            phone = self.EntryPhone.get()
            note = self.EntryNote.get()
            gender_value = self.var.get()

            gender = "Male"
            if (gender_value == 2):
                gender = "Female"

            date = self.cal.get_date()
            address = self.EntryAddress.get()
            has_image = '0'
            if (self.photo_path != None):
                has_image = '1'

            if (len(name) != 0 and len(phone) != 0 and len(note) != 0
                    and len(address) != 0 and gender_value != 0):

                data = {
                    'Name': name,
                    'Phone': phone,
                    'Note': note,
                    'Gender': gender,
                    'Date': date,
                    'Address': address,
                    'Image': has_image
                }

                firebase_db_manager = DBManager.FirebaseDBManager()
                results = firebase_db_manager.insert(data)

                if (self.photo_path != None):
                    fileManager = FileManager.FileManager()
                    fileManager.insert(results['name'], self.photo_path)

                self.clear_records()
                time.sleep(3)
                self.update_treeview()
            else:
                messagebox.showwarning("Incomplete Details",
                                       "Please fill all the fields!")

        else:
            messagebox.showwarning(
                "No internet connection.",
                "Connect to the internet to complete the requested data insertion!"
            )
def delete_feature_by_name(name):

    firebase_manager = DBManager.FirebaseDBManager()
    id = find_object_id_by_name(name, firebase_manager)

    if(id != None):
        firebase_manager.delete(id)

        try:
            fileManager = FileManager.FileManager()
            fileManager.remove_from_remote(id)
        except:
            print("")
    else:
        messagebox.showwarning("Not found",
                               "Name Not Found!!")
def inquiry_data(data):
    firebaseDBManager = DBManager.FirebaseDBManager()
    all_data = firebaseDBManager.getAllData()

    equal = False
    for id in all_data:
        dict_firebase = all_data[id]

        new_dict = {'Name':dict_firebase['Name'], 'Phone':dict_firebase['Phone'], 'Note':dict_firebase['Note'],
                    'Gender':dict_firebase['Gender'], 'Date':dict_firebase['Date'], 'Address':dict_firebase['Address']
                    }

        if(data == new_dict):
            equal = True

    return equal
def get_no_of_images():
    sqliteManager = DBManager.SQLiteDBManager()
    count = sqliteManager.getImageCount()
    return count
def verify_item_existence_in_sqlite(id):
    sqlitebaseDBManager = DBManager.SQLiteDBManager()
    data, existence = sqlitebaseDBManager.getSpecificData(id)
    return data, existence
 def update_treeview(self):
     dbManager = DBManager.SQLiteDBManager()
     self.Scrolledtreeview1.delete(*self.Scrolledtreeview1.get_children())
     dbManager.fill_treeview(self.Scrolledtreeview1)