def status(self): tulisan = None token = encrypt( str(self.tujuan) + str(Mesin.versiSoftware) + str(Mesin.jumlahMac) + str(Mesin.jumlahPegawai) + str(Mesin.jumlahAdmin) + str(Mesin.jumlahAbsensiF) + str(Mesin.jumlahPegawai) + str(Mesin.jumlahAdmin) + str(Mesin.jumlahAbsensiL) + str(instansi_id.ID_INSTANSI)) hasil = webAPI.LOG_RASPBERRY(({ 'ip': self.tujuan, 'versi': Mesin.versiSoftware, 'jumlahmac': Mesin.jumlahMac, 'jumlahpegawaifinger': Mesin.jumlahPegawai, 'jumlahadminfinger': Mesin.jumlahAdmin, 'jumlahabsensifinger': Mesin.jumlahAbsensiF, 'jumlahpegawailocal': Mesin.jumlahPegawai, 'jumlahadminlocal': Mesin.jumlahAdmin, 'jumlahabsensilocal': Mesin.jumlahAbsensiL, 'instansi_id': instansi_id.ID_INSTANSI, 'token': token })) if hasil: tulisan = 'CONNECTED' else: tulisan = 'DISCONNECTED' tampil.teks(text1='VERSI : %s' % Mesin.versiSoftware, text2='JUMLAH PEGAWAI : %s' % Mesin.jumlahPegawai, text3='STATUS : %s' % tulisan)
def POST(self, payload): try: r = requests.post('http://%s:80/iWsService' % self.ipAddress, headers={'Content-Type': 'text/xml'}, data=payload, timeout=5) # print r.content return ET.fromstring(r.content) # return None except (requests.exceptions.RequestException, ET.ParseError, ValueError, TypeError, IndexError) as err: if str(self.ipAddress) == str('10.10.10.10'): fingerprintName = 'FINGERPRINT A' elif str(self.ipAddress) == str('10.10.10.20'): fingerprintName = 'FINGERPRINT B' elif str(self.ipAddress) == str('10.10.10.30'): fingerprintName = 'FINGERPRINT C' elif str(self.ipAddress) == str('10.10.10.40'): fingerprintName = 'FINGERPRINT D' elif str(self.ipAddress) == str('10.10.10.50'): fingerprintName = 'FINGERPRINT E' tampil.teks(text1='KONEKSI', text2=fingerprintName, text3='TERPUTUS') time.sleep(1) logger.error(err) pass
def status_data(self): try: token = encrypt( str(self.ip_addr) + str(versi_software) + str(self.count_mac) + str(len(self.user)) + str(len(self.admin)) + str(len(self.attendance)) + str(len(self.user)) + str(len(self.admin)) + str(self.get_success_flag(self.mac_address)) + str(skpd)) _send_status = self.post_server( api['Status'], { 'ip': self.ip_addr, 'versi': versi_software, 'jumlahmac': self.count_mac, 'jumlahpegawaifinger': len(self.user), 'jumlahadminfinger': len(self.admin), 'jumlahabsensifinger': len(self.attendance), 'jumlahpegawailocal': len(self.user), 'jumlahadminlocal': len(self.admin), 'jumlahabsensilocal': self.get_success_flag( self.mac_address), 'instansi_id': skpd, 'token': token }) if _send_status is 'Success' or _send_status is 'Failed': tulisan = 'CONNECTED' else: tulisan = 'DISCONNECTED' lcd_.teks(text1='VERSI : %s' % versi_software, text2='JUMLAH PEGAWAI : %s' % len(self.user), text3='STATUS : %s' % tulisan) except TypeError as error: logger.error(error)
def save_macaddress(): mac_local = RpiDatabase().get_all_mac() mac_server = API().get_server(api['Macaddress']) lcd_.teks(text1='MENGAMBIL', text2='DATA', text3='MACADDRESS') time.sleep(1.2) if mac_server is 'ServerConnectionError' or mac_server is None: #tampilkan bahwa koneksi error lcd_.teks(text1='GAGAL', text2='MENGAMBIL', text3='DATA MACADDRESS') time.sleep(1.2) else: for progress, mac_server_ in enumerate(mac_server): lcd_.progress_bar(progress + 1, len(mac_server), text="CHECKING MAC") lcd_.disp.image(lcd_.image) lcd_.disp.display() #check_macaddress_exists if RpiDatabase().is_macaddress_registered( mac_server_['macaddress']): # print 'mac terdaftar' continue else: # print 'mendaftarkan'+mac_server_['macaddress'] RpiDatabase().insert('macaddress', 'mac_', mac_server_['macaddress'])
def clear_absensi(self): # print self.count_attendance_sent # print len(self.attendance) if len(self.attendance ) >= 50000 and self.count_attendance_sent >= 50000: print 'hapus' self.clear_attendance() RpiDatabase().truncate('attendance') lcd_.teks(text1='MENGHAPUS', text2='DATA', text3='ATTENDANCE') time.sleep(1.2) run('sudo reboot', shell=True) else: pass
def kirim(self): dataAbsensi = self.ambil() if self.jumlahFinger > self.jumlahLocal: for iterasi in range(self.jumlahLocal, self.jumlahFinger): token = encrypt( str(dataAbsensi[iterasi]['Jam']) + str(dataAbsensi[iterasi]['Tanggal']) + str(dataAbsensi[iterasi]['PIN']) + str(instansi_id.ID_INSTANSI) + str(dataAbsensi[iterasi]['Status'])) kirim = webAPI.KEHADIRAN({ 'status': dataAbsensi[iterasi]['Status'], 'instansi': instansi_id.ID_INSTANSI, 'jam': dataAbsensi[iterasi]['Jam'], 'tanggal': dataAbsensi[iterasi]['Tanggal'], 'user_id': dataAbsensi[iterasi]['PIN'], 'token': token }) if kirim: dataLocal.inputdataabsensi(dataAbsensi[iterasi]['PIN'], self.mesin.Mac) tampil.progress_bar(iterasi, self.jumlahFinger, text='MENGIRIMKAN ABSENSI') tampil.disp.image(tampil.image) tampil.disp.display() tampil.teks(text2='SELESAI') time.sleep(1.2) else: pass if self.jumlahFinger > 50000 and self.jumlahLocal > 50000: self.hapus()
def update(version): SRC = '/home/pi/finger' CMD = { 'REMOVESOURCE': 'sudo rm -rf %s', 'CLONETOSOURCE': 'sudo git clone https://github.com/Nat4Lia/finger.git %s', 'COPYTOETC': 'sudo cp -R /home/pi/finger /etc/', 'REBOOT': 'sudo reboot' } tampil.teks(text1='UPDATE PROGRAM', text2='RASPBERRY') time.sleep(1.2) if os.path.isdir(SRC): run(CMD['REMOVESOURCE'] % SRC, shell=True) run(CMD['CLONETOSOURCE'] % SRC, shell=True) run(CMD['COPYTOETC'], shell=True) dataLocal.updateversion(version) else: run(CMD['CLONETOSOURCE'] % SRC, shell=True) run(CMD['COPYTOETC'], shell=True) dataLocal.tambahversion(version) tampil.teks(text1='PROGRAM RASPBERRY', text2='UPDATE', text3='KE VERSI %s' % dataLocal.ambilversion()) time.sleep(1.2) time.sleep(5) tampil.teks(text1='RASPBERRY', text2='AKAN MELAKUKAN', text3='RESTART') time.sleep(1.2) run(CMD['REBOOT'], shell=True)
def validasi_user(self): try: data_API = self.get_server(api['Pegawai']) data_Mesin = self.user if data_API is 'ServerConnectionError': # print 'ada error' raise Exception else: if data_Mesin is None: raise Exception else: if len(data_API) == len(data_Mesin): lcd_.teks(text1='USER', text2='TELAH', text3='TERVALIDASI') time.sleep(1.2) else: lcd_.teks(text1='VALIDASI', text2='USER') time.sleep(1.2) for progress, user_mesin in enumerate(data_Mesin): hasil = False lcd_.progress_bar(progress + 1, len(data_Mesin), text=user_mesin['Nama']) lcd_.disp.image(lcd_.image) lcd_.disp.display() for user_API in data_API: if str(user_mesin['PIN']) == str( user_API['pegawai_id']): hasil = True break else: continue if not hasil: self.delete_user(user_mesin['PIN']) except Exception as error: logger.error(error)
def checking_table( table_check=[attendance_table, maccaddress_table, version_table]): # check table try: import time lcd_.teks(text1='CHECKING', text2='DATABASE') time.sleep(1.2) for index, structure in enumerate(table_check): if RpiDatabase().is_table_exists(structure['table']['name']): for column in structure['table']['column']: if RpiDatabase().is_column_exists( structure['table']['name'], column['name']): continue else: RpiDatabase().create_column(structure['table']['name'], column['name'], column['structure']) for index in structure['table']['index']: if RpiDatabase().is_index_exists( structure['table']['name'], index['name']): continue else: column_index = "" for column in structure['table']['column']: for indexing_column in column['index']: if indexing_column is index['name']: column_index += column['name'] + ", " RpiDatabase().create_index(index['name'], structure['table']['name'], column_index[:-2]) else: RpiDatabase().create_table(structure) lcd_.teks(text1='DATABASE', text2='READY') time.sleep(1.2) except Exception as error: logger.error(error) lcd_.teks(text1='DATABASE', text2='NOT READY') time.sleep(1.2) # # + is_table_exists (tablename): return True # + is_column_exists (columnname): return True # + is_index_exists : return True # + is_table_ready (table : json) : return True # + change_column (table : json) : return True # + create_table (table : json) : return True # + create_column (table : json) : return True # + create_index (table : json) : return True # + truncate (table) : return True
def main_Program(IP_Address): try: mesin = Mesin(IP_Address) if mesin.registered: version = webAPI.VERSI() trigger = webAPI.TRIGGER() daftar_Pegawai = webAPI.PEGAWAI() daftar_Admin = webAPI.ADMIN() update_Pegawai = webAPI.GANTI_FINGER(IP_Address) absensi = Absensi(IP_Address) absensi.kirim() mesin.status() if trigger is 1: if update_Pegawai is not None: for pegawai in update_Pegawai: oPegawai = Pegawai(IP_Address, pegawai['pegawai_id'], pegawai['nama']) oPegawai.update() if (daftar_Admin and daftar_Pegawai) is not None: if len(daftar_Admin) != mesin.jumlahAdmin: #Admin if mesin.semuaAdmin() is not None: for adminFinger in mesin.semuaAdmin(): hasil = False for adminAPI in daftar_Admin: if str(adminAPI['pegawai_id']) == str( adminFinger['PIN']): hasil = True break else: hasil = False if not hasil: oAdmin = Admin(IP_Address, adminFinger['PIN'], adminFinger['Name']) oAdmin.hapus() for admin in daftar_Admin: oAdmin = Admin(IP_Address, admin['id'], admin['nama']) oAdmin.daftar() else: for admin in daftar_Admin: oAdmin = Admin(IP_Address, admin['id'], admin['nama']) oAdmin.daftar() if len(daftar_Pegawai) != mesin.jumlahPegawai: #Pegawai if mesin.semuaPegawai() is not None: for pegawaiFinger in mesin.semuaPegawai(): hasil = False for pegawaiAPI in daftar_Pegawai: if str(pegawaiAPI['pegawai_id']) == str( pegawaiFinger['PIN']): hasil = True break else: hasil = False if not hasil: oPegawai = Pegawai(IP_Address, pegawaiFinger['PIN'], pegawaiFinger['Name']) oPegawai.hapus() for loading, pegawai in enumerate(daftar_Pegawai): oPegawai = Pegawai(IP_Address, pegawai['id'], pegawai['nama']) oPegawai.daftar() tampil.progress_bar(loading + 1, len(daftar_Pegawai), text='MENAMBAHKAN PEGAWAI') tampil.disp.image(tampil.image) tampil.disp.display() else: for loading, pegawai in enumerate(daftar_Pegawai): oPegawai = Pegawai(IP_Address, pegawai['id'], pegawai['nama']) oPegawai.daftar() tampil.progress_bar(loading + 1, len(daftar_Pegawai), text='MENAMBAHKAN PEGAWAI') tampil.disp.image(tampil.image) tampil.disp.display() elif trigger is 3: if dataLocal.cekversion(version): update(version) else: raise Exception else: tampil.teks(text1='MACADDRESS', text2='FINGERPRINT', text3='BELUM TERDAFTAR') time.sleep(1.2) tampil.teks(text1='SILAKAN', text2='HUBUNGI PIHAK', text3='DISKOMINFO') time.sleep(1.2) except Exception: logger.error(Exception) tampil.teks(text1='ERROR', text2='RESTART', text3='RASPBERRY') run('sudo reboot', shell=True)
def play(ip_address): # save_macaddress() global trigger_api, trigger, spesific_date, spesific_instansi _MainProgram = MainProgram(ip_address) try: trigger_api = API().get_server(api['Trigger'])[0] trigger = trigger_api['status'] spesific_date = trigger_api['patokantanggal'] spesific_instansi = trigger_api['instansi_id'] except Exception: trigger_api = 'ServerConnectionError' try: if _MainProgram.is_mesin_registered: _MainProgram.management_admin() _MainProgram.status_data() if trigger == 1: # print 'main' _MainProgram.send_attendance() _MainProgram.management_employee() _MainProgram.clear_absensi() elif trigger == 2: _MainProgram.validasi_user() elif trigger == 3: pass # try: # version = (API().get_server(api['Versi']))['version'] # except Exception : # version = 'ServerConnectionError' # if RpiDatabase().is_version_same(version): # lcd_.teks(text1='RASPBERRY', text2='SUDAH', text3='TERUPDATE') # time.sleep(1.2) # else : # update(version) elif trigger == 4: if RpiDatabase().is_table_zero('attendance'): RpiDatabase().truncate('attendance') lcd_.teks(text1='MENGHAPUS', text2='DATA', text3='ATTENDANCE') time.sleep(1.2) run('sudo reboot', shell=True) else: lcd_.teks(text1='DATA ATTENDANCE', text2='KOSONG') time.sleep(1.2) elif trigger == 5: if (spesific_instansi == skpd) or (spesific_instansi is None): _MainProgram.spesific_send_attendance(spesific_date) _MainProgram.management_employee() else: lcd_.teks(text2='MENUNGGU', text3='HARAP SABAR') time.sleep(1.2) elif trigger_api == 'ServerConnectionError': raise Exception else: pass else: lcd_.teks(text1='PERIKSA APAKAH', text2='MESIN TERDAFTAR') time.sleep(1.2) lcd_.teks(text1='JIKA PESAN INI', text2='SELALU MUNCUL') time.sleep(1.2) lcd_.teks(text1='SEGERA', text2='HUBUNGI', text3='DISKOMINFO') time.sleep(1.2) except Exception as error: logger.error(error)
def management_employee(self): print 'management employee' api_pegawai = self.post_return_data( api['GetQueue'], { 'instansi': skpd, 'macaddress': self.mac_address, 'fingerprint_ip': self.ip_addr }) try: if api_pegawai is 'ServerConnectionError': raise Exception else: if self.user is None: raise Exception else: for data in api_pegawai: #mendaftarkan pegawai cek = self.check_user( data['pegawai_id']) #cek pendaftaran # print 'CEK '+data['nama'] api_sidikjari = self.get_server( api['Autentikasi'] % data['pegawai_id']) #ambil sidik jari # print len(api_sidikjari) if str(data['command']) == 'daftar': #cek user terdaftar/tidak if cek is True: #sudah terdaftar laporan = lapor_employee( self.mac_address, self.ip_addr, data['id']) lcd_.teks(text1=data['nama'], text2='TERDAFTAR') time.sleep(1.2) # print 'LAPORAN '+laporan # print 'SUDAH TERDAFTAR' # elif cek is False: #belum terdaftar #mengambil data api sidik jari if api_sidikjari is 'ServerConnectionError': raise Exception else: #password if len(api_sidikjari[0] ['templatefinger']) <= 8: #daftarkan pegawai set_pegawai = self.set_user( data['pegawai_id'], data['nama'].replace("'", " "), api_sidikjari[0]['templatefinger']) if set_pegawai is True: laporan = lapor_employee( self.mac_address, self.ip_addr, data['id']) lcd_.teks(text1=data['nama'], text2='TERDAFTAR') time.sleep(1.2) # print 'LAPORAN '+laporan # print 'SUKSES USER PASSWORD' elif set_pegawai is False: lcd_.teks(text1=data['nama'], text2='GAGAL', text3='TERDAFTAR') time.sleep(1.2) elif set_pegawai is None: raise Exception # # #sidik jari elif len(api_sidikjari[0] ['templatefinger']) > 8: #daftarkan pegawai set_pegawai = self.set_user( data['pegawai_id'], data['nama'].replace("'", " "), None) if set_pegawai is True: #daftarkan sidik jari # print 'SUKSES USER' set_sidikjari = self.set_template( api_sidikjari) if set_sidikjari is True: laporan = lapor_employee( self.mac_address, self.ip_addr, data['id']) lcd_.teks(text1=data['nama'], text2='TERDAFTAR') time.sleep(1.2) # print 'LAPORAN '+laporan # print 'SUKSES SIDIK JARI' elif set_sidikjari is False: lcd_.teks(text1=data['nama'], text2='GAGAL', text3='TERDAFTAR') time.sleep(1.2) print 'GAGAL SIDIK JARI' elif set_sidikjari is None: raise Exception # elif set_pegawai is False: lcd_.teks(text1='GAGAL', text2='MENDAFTARKAN', text3=data['nama']) time.sleep(1.2) # print 'GAGAL USER' elif set_pegawai is None: raise Exception # # # elif cek is None: raise Exception # # elif str(data['command']) == 'ganti': #cek user terdaftar/tidak if cek is True: if api_sidikjari is 'ServerConnectionError': raise Exception else: #password if len(api_sidikjari[0] ['templatefinger']) <= 8: #hapus user, ganti dengan password del_user = self.delete_user( data['pegawai_id']) if del_user: set_pegawai = self.set_user( data['pegawai_id'], data['nama'].replace("'", " "), api_sidikjari[0] ['templatefinger']) if set_pegawai is True: laporan = lapor_employee( self.mac_address, self.ip_addr, data['id']) # print 'LAPORAN '+laporan # print 'SUKSES GANTI KE PASSWORD' lcd_.teks(text1=data['nama'], text2='GANTI KE', text3='PASSWORD') time.sleep(1.2) elif set_pegawai is False: lcd_.teks( text1=data['nama'], text2='GAGAL GANTI KE', text3='PASSWORD') time.sleep(1.2) # print 'GAGAL GANTI KE PASSWORD' elif set_pegawai is None: raise Exception else: raise Exception # # #sidik jari elif len(api_sidikjari[0] ['templatefinger']) > 8: #hapus user, ganti dengan password del_user = self.delete_user( data['pegawai_id']) if del_user: #daftarkan pegawai set_pegawai = self.set_user( data['pegawai_id'], data['nama'].replace("'", " "), None) if set_pegawai is True: #daftarkan sidik jari # print 'SUKSES USER' set_sidikjari = self.set_template( api_sidikjari) if set_sidikjari is True: laporan = lapor_employee( self.mac_address, self.ip_addr, data['id']) # print 'LAPORAN '+laporan # print 'SUKSES MENGGANTI JARI' lcd_.teks( text1=data['nama'], text2='GANTI KE', text3='SIDIK JARI') time.sleep(1.2) elif set_sidikjari is False: lcd_.teks( text1=data['nama'], text2='GAGAL GANTI KE', text3='SIDIK JARI') time.sleep(1.2) elif set_sidikjari is None: raise Exception # elif set_pegawai is False: # print 'GAGAL MENGGANTI SIDIK JARI USER' lcd_.teks( text1='GAGAL', text2='GANTI AUTENTIKASI', text3=data['nama']) time.sleep(1.2) elif set_pegawai is None: raise Exception # else: raise Exception # # elif cek is False: lcd_.teks(text1=data['nama'], text2='TIDAK TERDAFTAR', text3='DI MESIN') time.sleep(1.2) elif cek is None: raise Exception # elif str(data['command']) == 'hapus': # cek user terdaftar/tidak if cek is True: #hapus user del_user = self.delete_user(data['pegawai_id']) if del_user: laporan = lapor_employee( self.mac_address, self.ip_addr, data['id']) lcd_.teks(text1=data['nama'], text2='TERHAPUS DARI', text3='MESIN') time.sleep(1.2) # print 'LAPORAN '+laporan # print 'SUKSES MENGHAPUS PEGAWAI' else: raise Exception # elif cek is False: lcd_.teks(text1=data['nama'], text2='TIDAK TERDAFTAR', text3='DI MESIN') time.sleep(1.2) laporan = lapor_employee( self.mac_address, self.ip_addr, data['id']) elif cek is None: raise Exception # except Exception as error: logger.error(error) lcd_.teks(text1='TERJADI KESALAHAN', text2='MANAGEMENT', text3='EMPLOYEE') time.sleep(1.2)
if connection_on(alamat): list_used_ip_fp.append(alamat) if __name__ == '__main__': from main_program import play from main_program import save_macaddress import time ping_ip(ip_address) save_macaddress() checking_table() if not list_used_ip_fp: try_update() lcd_.teks( text1='TIDAK ADA', text2='FINGERPRINT', text3='YANG TERHUBUNG') time.sleep(1.2) lcd_.teks( text1='HARAP HUBUNGKAN', text2='RASPBERRY', text3='KE FINGERPRINT') time.sleep(1.2) lcd_.teks(text1='KEMUDIAN', text2='RESTART', text3='RASPBERRY') time.sleep(1.2) else: lcd_.teks( text1='RASPBERRY MENGGUNAKAN', text2='%s BUAH FINGERPRINT' % len(list_used_ip_fp)) while True: try_update()
def main_Program(IP_Address): try: mesin = Mesin(IP_Address) if mesin.registered: version = webAPI.VERSI() trigger = webAPI.TRIGGER() daftar_Pegawai = webAPI.PEGAWAI() daftar_Admin = webAPI.ADMIN() update_Pegawai = webAPI.GANTI_FINGER(IP_Address) absensi = Absensi(IP_Address) absensi.kirim() if trigger is 1: if update_Pegawai is not None: for pegawai in update_Pegawai: oPegawai = Pegawai(IP_Address, pegawai['pegawai_id'], pegawai['nama']) oPegawai.update() if (daftar_Admin and daftar_Pegawai) is not None: if len(daftar_Admin) != mesin.jumlahAdmin: #Admin if mesin.semuaAdmin() is not None: for adminFinger in mesin.semuaAdmin(): hasil = False for adminAPI in daftar_Admin: if str(adminAPI['pegawai_id']) == str( adminFinger['PIN']): hasil = True break else: hasil = False if not hasil: oAdmin = Admin(IP_Address, adminFinger['PIN'], adminFinger['Name']) oAdmin.hapus() for admin in daftar_Admin: oAdmin = Admin(IP_Address, admin['id'], admin['nama']) oAdmin.daftar() else: for admin in daftar_Admin: oAdmin = Admin(IP_Address, admin['id'], admin['nama']) oAdmin.daftar() if len(daftar_Pegawai) != mesin.jumlahPegawai: #Pegawai if mesin.semuaPegawai() is not None: for pegawaiFinger in mesin.semuaPegawai(): hasil = False for pegawaiAPI in daftar_Pegawai: if str(pegawaiAPI['pegawai_id']) == str( pegawaiFinger['PIN']): hasil = True break else: hasil = False if not hasil: oPegawai = Pegawai(IP_Address, pegawaiFinger['PIN'], pegawaiFinger['Name']) oPegawai.hapus() for loading, pegawai in enumerate(daftar_Pegawai): oPegawai = Pegawai(IP_Address, pegawai['id'], pegawai['nama']) oPegawai.daftar() tampil.progress_bar(loading, len(daftar_Pegawai), text='MENAMBAHKAN PEGAWAI') tampil.disp.image(tampil.image) tampil.disp.display() else: for loading, pegawai in enumerate(daftar_Pegawai): oPegawai = Pegawai(IP_Address, pegawai['id'], pegawai['nama']) oPegawai.daftar() tampil.progress_bar(loading, len(daftar_Pegawai), text='MENAMBAHKAN PEGAWAI') tampil.disp.image(tampil.image) tampil.disp.display() elif trigger is 3: if dataLocal.cekversion(version): update(version) else: raise Exception else: tampil.teks(text1='MACADDRESS', text2='FINGERPRINT', text3='BELUM TERDAFTAR') time.sleep(1.2) tampil.teks(text1='SILAKAN', text2='HUBUNGI PIHAK', text3='DISKOMINFO') time.sleep(1.2) except Exception: logger.error(Exception) tampil.teks(text1='ERROR', text2='RESTART', text3='RASPBERRY') exit() # for pegawai in update_Pegawai: # oPegawai = Pegawai('10.10.10.10',pegawai['pegawai_id'], pegawai['nama']) # print "Pendaftaran {}, {}".format(oPegawai.name, oPegawai.update()) # print "Total Pegawai Berhasil Di Daftarkan: {}".format(Pegawai.jumlahPegawai) # if __name__ == "__main__" : # while True: # main_Program('10.10.10.10') # print encrypt("10219110.10.10.1019") #Yang Belum #Konfirmasi Update Pegawai #Update #Main
def spesific_send_attendance(self, tanggal): from datetime import datetime if self.is_mesin_registered: #Jika Mesin Terdaftar #ambil jumlah absensi yg terkirim attendance_sent = self.get_all_attendace_sent(self.mac_address) # #ambil row failed # get_row_local_att_failed = self.get_failed_flag(self.mac_address) # #jika data attendance dari fingerprint ada if self.attendance is not None: #mengumpulkan data absensi yg failed dari mesin sesuai dengan data local # attendance_failed = [] # for row_id in get_row_local_att_failed : # attendance_failed.append(self.attendance[row_id[0]]) # #mengumpulkan absensi diatas tanggal yg ditentukan attendance_new = [] attendance_old = [] for row_id in range(attendance_sent, len(self.attendance)): tgl_khusus = datetime.strptime(tanggal, '%Y-%m-%d') tgl_fingerprint = datetime.strptime( self.attendance[row_id]['Tanggal'], '%Y-%m-%d') #convert str to date if tgl_fingerprint >= tgl_khusus: #jika data absensi diatas tanggal yg ditentukan attendance_new.append( self.attendance[row_id] ) #dikumpulkan menjadi absensi baru else: #jika tidak attendance_old.append( self.attendance[row_id] ) #dikumpulkan menjadi absensi lama # #simpan absensi lama dengan status success for attendance in attendance_old: self.insert_absensi(self.mac_address, attendance['Row_ID'], attendance['PIN'], attendance['Tanggal'], attendance['Jam'], attendance['Status'], 'Success') # #absensi yang akan dikirim (gabungan absensi failed dan absensi belum terkirim) #attendance_will_send = attendance_failed + attendance_new # # iterasi absensi yang akan dikirim lcd_.teks(text1='BERSIAP', text2='MENGIRIMKAN', text3='ABSENSI') time.sleep(1.2) if attendance_new: try: for progress, attendance in enumerate( attendance_new): #Kasih loading pengiriman # buat otp token = encrypt(attendance['Jam'] + attendance['Tanggal'] + attendance['PIN'] + str(skpd) + attendance['Status']) # # kirimkan absensi _send_attendance = self.post_server( api['Absensi'], { 'status': attendance['Status'], 'instansi': skpd, 'jam': attendance['Jam'], 'tanggal': attendance['Tanggal'], 'user_id': attendance['PIN'], 'macaddress': self.mac_address, 'token': token }) # lcd_.progress_bar(progress + 1, len(attendance_new), text=attendance['Tanggal']) lcd_.disp.image(lcd_.image) lcd_.disp.display() # jika pengiriman diterima, insert ke database if _send_attendance is 'Success' or _send_attendance is 'Failed': self.insert_absensi( self.mac_address, attendance['Row_ID'], attendance['PIN'], attendance['Tanggal'], attendance['Jam'], attendance['Status'], _send_attendance) else: lcd_.teks(text1='KONEKSI', text2='SERVER', text3='BERMASALAH') time.sleep(1.2) lcd_.teks(text1='TIDAK DAPAT', text2='MENGIRIM ABSENSI', text3='KE SERVER') time.sleep(1.2) raise Exception # print 'KONEKSI KE SERVER BERMASALAH' # print 'TIDAK DAPAT MENGIRIM ABSENSI KE SERVER' time.sleep(1.2) # except Exception as error: lcd_.teks(text2=str(error)) time.sleep(1.2) lcd_.teks(text1='GAGAL', text2='MENGIRIMKAN', text3='ABSENSI') time.sleep(1.2) else: lcd_.teks(text1='TIDAK ADA', text2='ABSENSI', text3='BARU') time.sleep(1.2) # else: lcd_.teks(text1='KESALAHAN PADA', text2='DATABASE', text3='RASPBERRY') time.sleep(1.2) lcd_.teks(text1='HARAP', text2='RESTART', text3='RASPBERRY') time.sleep(1.2) lcd_.teks(text1='JIKA PESAN INI', text2='SELALU MUNCUL') time.sleep(1.2) lcd_.teks(text1='SEGERA', text2='HUBUNGI', text3='DISKOMINFO') time.sleep(1.2) # print 'KESALAHAN PADA DATABASE RASPBERRY' # print 'HARAP RESTART RASPBERRY' # print 'JIKA PESAN INI SELALU MUNCUL, SEGERA HUBUNGI DISKOMINFO' else: lcd_.teks(text1='PERIKSA APAKAH', text2='MESIN TERDAFTAR', text3='DI DISKOMINFO') time.sleep(1.2) lcd_.teks(text1='PERIKSA KEMBALI', text2='KONEKSI MESIN', text3='DENGAN RASPBERRY') time.sleep(1.2)
for i, alamat in enumerate(listAlamat): tampil.progress_bar(i + 1, len(listAlamat), text='%s' % localhost.ambilversion()) tampil.disp.image(tampil.image) tampil.disp.display() if connect(alamat): useAlamat.append(alamat) if __name__ == "__main__": checkAlamat() if len(useAlamat) is 0: while True: tampil.teks(text1='TIDAK ADA', text2='FINGERPRINT', text3='YANG TERHUBUNG') time.sleep(1.2) tampil.teks(text1='HARAP HUBUNGKAN', text2='RASPBERRY', text3='KE FINGERPRINT') time.sleep(1.2) tampil.teks(text1='KEMUDIAN', text2='RESTART', text3='RASPBERRY') time.sleep(1.2) else: tampil.teks(text1='RASPBERRY MENGGUNAKAN', text2='%s BUAH FINGERPRINT' % len(useAlamat)) while True: for alamat in useAlamat: Fingerprint.main_Program(alamat)
def try_update(): try: lcd_.teks('CEK', 'UPDATE') new_version = get_new_version() # Mendapatkan versi terbaru if new_version: if Version < new_version: lcd_.teks('UPDATE', 'KE VERSI', str(new_version)) if download_file(new_version): # download file dari github if unzip_file(new_version): # unzip file hasil download lcd_.teks('UPDATE...') if not os.path.isdir(dst): os.system(command['copy']) else: os.chdir(dst) # masuk direktori /etc/finger os.system(command['rmexcept']) # hapus semua # kecuali instansi_id os.system(command['copy']) # copy replace all dari /home/pi/finger # ke /etc/finger os.system(command['removezip'].format(new_version)) # hapus file zip os.system(command['rmdirfinger']) # hapus direktori /home/pi/finger lcd_.teks('REBOOT...') os.system(command['reboot']) else: raise Exception else: raise Exception else: lcd_.teks('TIDAK ADA', 'UPDATE') time.sleep(2) else: lcd_.teks('GAGAL', 'MENDAPATKAN', 'VERSI TERBARU') except Exception: lcd_.teks('UPDATE', 'GAGAL')