def main(): p = Printer() graph = facebook.GraphAPI(FB_API_KEY) last_check = datetime.utcnow() last_check = last_check.replace(tzinfo=pytz.utc) while True: time.sleep(5) print "Polling" try: msgs = check_mail(last_check) last_check = datetime.utcnow() last_check = last_check.replace(tzinfo=pytz.utc) fb = check_fb(graph, p) talks = check_talktome() except: print "Issue retrieving data, is there interwebs?" continue prnt = False if len(msgs) > 0: prnt = True p.add_line( p.wide("Email") ) p.add_line( p.black(strftime("%a, %d %b %Y %X", localtime())) ) for frm, subject in msgs: p.add_line( p.black("From: ") +\ p.red(frm if frm.strip() != "" else "Unknown") ) p.add_line( p.black("Subject: ") +\ p.red(subject if subject.strip() != "" else "None") ) if len(msgs) > 1: p.add_line(p.black("\n")) if len(fb) > 0: prnt = True p.add_line( p.wide("Facebook") ) p.add_line( p.black(strftime("%a, %d %b %Y %X", localtime())) ) for frm, txt in fb: txt = p.black(txt) txt = txt.replace(p.black(frm), p.red(frm)) p.add_line(txt) if len(msgs) > 1: p.add_line(p.black("\n")) if len(talks) > 0: prnt = True p.add_line( p.wide("Talk At Me") ) for t, frm, msg in talks: p.add_line( p.black(t) ) p.add_line( p.black("From: ") +\ p.red(frm) ) if len(msg) > 6: msg = msg[:6] for m in msg: p.add_line( p.black(m) ) if len(talks) > 1: p.add_line(p.black("\n")) if prnt: p.output()
def Printmain(name=None, phone=None, data=None, fin=None, keyongThing=None, Hand_FinList=None): p = Printer() p.lines = [] p.add_line("医琦母婴护理") p.add_line("**************") p.add_line("下单时间:" + strftime("%d/%m/%Y %X", localtime())) if name: p.add_line("顾客姓名:" + name) if phone: p.add_line("顾客电话:" + phone) p.add_line("**************") if Hand_FinList: for temp in Hand_FinList: p.add_line("手法名称:" + str(temp[0])) p.add_line("使用次数:" + str(temp[2])) p.add_line("剩余次数:" + str(temp[1])) p.add_line(" ") if data: p.add_line("品名 金额 数量") for x in data: name_id = x[0] price = x[2] num = x[3] p.add_line(name_id + ' ' + str(price) + ' ' + str(num)) p.add_line("合计: " + str(fin)) p.add_line("可用于购买商品的金额:" + str(keyongThing)) p.add_line("**************") p.add_line("欢迎光临,谢谢惠顾!") p.add_line("医琦母婴护理") p.add_line("\n") p.add_line("******自此裁剪******") p.add_line("医琦母婴护理") p.add_line("**************") p.add_line("下单时间:" + strftime("%d/%m/%Y %X", localtime())) if name: p.add_line("顾客姓名:" + name) if phone: p.add_line("顾客电话:" + phone) p.add_line("**************") if Hand_FinList: for temp in Hand_FinList: p.add_line("手法名称:" + str(temp[0])) p.add_line("使用次数:" + str(temp[2])) p.add_line("剩余次数:" + str(temp[1])) p.add_line(" ") if data: p.add_line("品名 金额 数量") for x in data: name_id = x[0] price = x[2] num = x[3] p.add_line(name_id + ' ' + str(price) + ' ' + str(num)) p.add_line("合计: " + str(fin)) p.add_line("可用于购买商品的金额:" + str(keyongThing)) p.add_line("**************") p.add_line("欢迎光临,谢谢惠顾!") p.add_line("医琦母婴护理") p.add_line("\n") p.output()
print("\nAccuracy: " + str(accuracy)) # ===================== TEST DOCX ===================== docx_test = TextDS("FILES/DOCX_TO_TEXT/146844.txt", cdict, seq_len=100) docx_test_loader = DataLoader(docx_test) with torch.no_grad(): seq_num = 0 for x, y in docx_test_loader: pred = model(x) loss = criterion(pred, y.long()).squeeze() soft_max = functional.softmax(pred, 1) res = torch.argmax(soft_max, dim=1) print('test loss:', loss.item()) non_zero = count_nonzero(x.numpy() - res.numpy()) original = cdict.decode(x.squeeze()) predicted = cdict.decode(res.squeeze()) if non_zero is not 0: # tagger.add_error(docx_test.file_name, seq_num, original, predicted) printer.add_line(original, predicted) else: printer.add_line(original, -1) seq_num += 1 # tagger.print_tree_to_file() printer.print_to_file()