Exemple #1
0
def download_file(new_version):
    url_file = 'https://github.com/Nat4Lia/finger/archive/v{}.zip'.format(
        new_version)
    filepath = '/home/pi/download/v{}.zip'.format(new_version)
    try:
        request_file = requests.get(url_file, timeout=5, stream=True)
        if request_file.status_code == 200:
            if not os.path.isdir('/home/pi/download'):
                os.system('mkdir /home/pi/download')
            with open(filepath, 'wb') as f:
                total_size = int(len(request_file.content))
                block_size = 1024 * 10
                progress = 0
                for data in request_file.iter_content(block_size):
                    progress = progress + len(data)
                    lcd_.progress_bar(progress,
                                      total_size,
                                      text="DOWNLOAD UPDATE")
                    lcd_.disp.image(lcd_.image)
                    lcd_.disp.display()
                    f.write(data)
                f.close()
        else:
            raise Exception
    except Exception:
        if os.path.isfile(filepath):
            os.remove(filepath)
    return os.path.isfile(filepath)
Exemple #2
0
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'])
Exemple #3
0
def ping_ip(ip_address):
    from config import versi_software
    for i, alamat in enumerate(ip_address):
        lcd_.progress_bar(i+1, len(ip_address), text=str(versi_software))
        lcd_.disp.image(lcd_.image)
        lcd_.disp.display()
        if connection_on(alamat):
            list_used_ip_fp.append(alamat)
Exemple #4
0
def checkAlamat():
    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)
Exemple #5
0
    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()
Exemple #6
0
 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)
Exemple #7
0
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)
Exemple #8
0
    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)
Exemple #9
0
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