Use Python to connect to the central control attendance machine. Download and analyze the data and send the results to the personnel.
Central Control SDK Package: x32 Address x64 Address
SDK Package recommended 32-bit, on the Win7 64-bit system with 64-bit development package does not, with 32 can.
Python also pywin32 note version, I use the 32-bit Python 2.7 and then this PYWIN32
#!/usr/bin/env python#_*_ coding:gbk _*_import win32com.clientimport timeimport sysimport smtplibfrom email.mime.multipart import mimemultipart from Email.mime.text import mimetext from email.mime.image import mimeimage def write_file (Filename, data): with open (filename, ' W ' ) as f: f.write (data) def send_mail (filename=[], picname=[], content_txt= ", content_html="): smtpserver = ' smtp.163.com ' username = ' [ Email protected] ' password = ' abc123 ' msg = mimemultipart () msg[' Subject '] = ' check_iN ' msg[' from '] = ' [email protected] ' msg[' to '] = "[email protected]" # attchment If len (filename) > 0: for i in filename: att = Mimetext (Open (i, ' RB '). Read (), ' base64 ', ' gf2312 ') att["Content-type"] = ' Application/octet-stream ' att["Content-Disposition"] = ' attachment; filename= "%s" ' % i.split (' \ \ ') [-1] msg.attach (ATT) # attchment picture if len (Picname) &NBSP;≫ 0 and content_html != ': for I in range (0,len (picname)): # content_html = ' <b>some <i>html</i> text</b> and an image.<br><br>good! ' % i msg_content_ Html = mimetext (content_html, ' html ', ' gb2312 ') msg.attach (msg_content_html) With open (picname[i], ' RB ') as f: msgImage = Mimeimage (F.read ()) msgimage.add_header (' Content-ID ', ' < Image%s> ' % (i + 1) msg.attach (msgimage) # content text if content_txt != ': Msg_content_txt = mimetext (content_txt,_subtype= ' plain ', _charset= ' gb2312 ') msg.attach (msg_content_txt) # content html if content_html != ' and len (picname) == 0: msg_content_html = mimetext (content_html,_subtype= ' HTML ', _charset= ' gb2312 ') msg.attach (msg_content_html) smtp = smtplib. SMTP () smtp.connect (smtpserver) Smtp.starttls () smtp.login (Username, password) smtp.sendmail (msg[' from '], msg[' to '], msg.as_string ()) smtp.quit () def col_name (): all = ', ' for i in uid_name: all = all + get_id (i) + ', ' return all def get_id (Idnum): try: return uid[idnum].split (U ' \x00 ') [0].encode (' GBK ') &nBsp; except: return str (IdNum) zk = win32com.client.dispatch (' Zkemkeeper. Zkem.1 ') If not zk. Connect_net (' 192.168.1.2 ', 4370): print "Connect error" sys.exit (1) zk. Setdevicetime (1) #使用PC时间同步到考勤机if time.localtime () [2] != 1: zk. Disconnect () sys.exit (1) zk. Readalluserid (1) uid = {}while 1: exists, idnum, username, other, privilege, enable = zk. Getalluserinfo (1) if not exists: break else: if enable: uid[idNum] = usernamecheckin = {}last_month = time.localtime () [1]-1 or 12if last_month == 12: cur_year = time.localtime () [0]-1else: cur_year = Time.localtime () [0]if zk. Readgenerallogdata (1): #read all checkin data while 1: exists, machNum, idNum, emachNum, Verifymode, outmode, year, month, day, hour, minute = zk. Getgenerallogdata (1) #2 if not exists: break if cur_year == year and last_month == month: if day not in checkin: checkin[day] = {} if idNum in checkin[day]: checkin[day][idnum]. Append (Hour * 60 + minute) else: checkin[day][idnum] = [hour * 60 + minute]zk. Disconnect () csv_name = r ' D:\CheckIn\%s-%s.csv ' % (cur_year, last_month) uid_name = sorted (Uid.keys ()) report = col_name () + ' \ n ' for daynum in range (1,35 ): if daynum not in checkin: break report = report + '%s-%s-%s, ' % (cur_year, last_month, daynum) for col in uid_name: if col not in checkin[daynum]: report = report + ', ' Continue if len (Checkin[dayNum][col]) < 2: report = report + ' 0, ' else: daytime = max (Checkin[daynum][col]) - min (checkin[ Daynum][col]) if dayTime%60 >= 45: report = report + str (daytime//60 + 1) + ', ' elif 15 < dayTime%60 < 45: &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;REPORT&NBSP;=&NBSP;REPORT&NBSP;+&NBSP;STR ( daytime//60 + 0.5) + ', ' else: Report = report + str (DAYTIME//60) + ', ' report = report + ' \ n ' write_file (csv_name, report) send_mail (filename=[csv_ name], content_txt= ' check_in %s-%s ' % (cur_year, last_month))
Python Connect the time Machine analysis data