def buildLanguage(args, language): if language == defaultLanguage: buildDirectory = "" isTranslation = False else: buildDirectory = "translations/" + language + "/" isTranslation = True buildDir = buildRootDir + buildDirectory if not os.path.exists(buildDir): os.makedirs(buildDir) pdfName = languageData[language]["pdf"] srcDir = "translations/" + language if isTranslation else "wca-regulations" print "%s Generating HTML in %s" % ( ("[" + language + "]").ljust(max_lang_width + 2), buildDir) html.html(language, srcDir, buildDir, pdfName + ".pdf", isTranslation=isTranslation, verbose=args.verbose) if args.pdf: pdf.pdf(language, buildDir, isTranslation, pdfName, languageData[language]["tex_encoding"], languageData[language]["tex_command"], verbose=args.verbose)
def buildLanguage(args, language): if language == defaultLanguage: buildDirectory = "" isTranslation = False else: buildDirectory = "translations/" + language + "/" isTranslation = True buildDir = buildRootDir + buildDirectory if not os.path.exists(buildDir): os.makedirs(buildDir) pdfName = languageData[language]["pdf"] srcDir = "translations/" + language if isTranslation else "wca-regulations" print "%s Generating HTML in %s" % (("[" + language + "]").ljust(max_lang_width + 2), buildDir) html.html(language, srcDir, buildDir, pdfName + ".pdf", isTranslation=isTranslation, verbose=args.verbose) if args.pdf: pdf.pdf( language, buildDir, isTranslation, pdfName, languageData[language]["tex_encoding"], languageData[language]["tex_command"], verbose=args.verbose )
def buildLanguage(args, language): if language == defaultLanguage: buildDirectory = "" isTranslation = False else: buildDirectory = "translations/" + language + "/" isTranslation = True buildDir = buildRootDir + buildDirectory if not os.path.exists(buildDir): os.makedirs(buildDir) pdfName = languageData[language]["pdf"] html.html(language, buildDir, pdfName + ".pdf", isTranslation=isTranslation, verbose=args.verbose) if args.pdf: pdf.pdf( language, buildDir, isTranslation, pdfName, languageData[language]["tex_encoding"], languageData[language]["tex_command"], verbose=args.verbose )
def main(): s.set_options(sys.argv[1:]) topo = SingleSwitchTopo(s.n) m = Mininet(switch=UserSwitch, topo=topo, controller=None, rate=s.rate) m.start() if s.stop: m.stop() return if s.test == 'iperf': it = IPerfOneToAllTest(m.hosts, s.t) it.start() if s.detach: return if not s.dryrun: prompt = colored('Without asking why, type 1 and RET when you want to stop: ', 'cyan') while True: x = int(raw_input(prompt)) if x == 1: break if len(s.test): res = it.end() html.html(s.outputfile, html.comments([ 'test: %s' % (s.test), 'topology: %s' % (topo), ]) + res) m.stop()
def main(): test_file = r'../data/amr_sentences.txt' with open(test_file, 'r', encoding='utf8') as f: for html in TXT.finditer(f.read()): html = TXT(html) print(html.html())
def generate(idjudge_s): try: dlg = wx.FileDialog(None, 'Save report as', t_setup.get_value("path_html"), '', '*.html', wx.SAVE) if dlg.ShowModal() == wx.ID_OK: file_name = dlg.GetPath() t_setup.update({"path_html": os.path.dirname(file_name)}) data = mount_data(idjudge_s) # Report beginning rows = len(data) clss = len(idjudge_s) h = html.html(output_type=html.OUTPUT_FILE, file_name=file_name) h.open() h.page_header("Classified spectrums") h.open_table() # table header h.open_tr() h.th("Tray", 50) h.th("Slide", 50) h.th("Colony", 50) h.th("File name", 50) for name in judge_names(idjudge_s): h.th(name, 50) h.close_tr() i = 0 ii = 0 colony_code_last = -1 for row in data: # row is (idspectrum, flag_active, tray code, slide code, colony code, file name, ...) h.open_tr() for value in row[NO_COLS_SKIP:]: h.td(value) h.close_tr() i += 1 ii += 1 if ii == 123: progress(float(i + 1) / rows) ii = 0 progress(1) h.close_table() h.close() except error_x, e: act_main.handle_error(e)
def build_page(self, headers, data): """Build table html containing data rows.""" table = html.doclist(headers, data) styles = self.get_styles() scripts = self.get_scripts() doc = html.html(styles + scripts, table, cls='noselect') basepath = os.path.abspath(os.path.dirname(__file__)) self.setHtml(doc, QtCore.QUrl.fromLocalFile(basepath))
def main(): test_file = 'test_ud.txt' color_word = 'fault' color_edge = '' text = open(test_file, 'r', encoding='utf8').read() print(UD2html.test(text)) if UD2html.test(text): html = UD2html(text, 1) print(html.HTML_START + html.html() + html.HTML_END)
def gen_html(): if "id" in form: body = single_message() else: body = list_messages() return html.html( html.head(html.title("a858 auto-analysis"), html.script(language='javascript', src='functions.js')), body)
def buildToDirectory(args, directory, lang=defaultLang, translation=False): buildDir = buildRootDir + directory if not os.path.exists(buildDir): os.makedirs(buildDir) pdfName = languageData[lang]["pdf"] html.html(lang, buildDir, pdfName + ".pdf", gitBranch=languageData[lang]["branch"], translation=translation, verbose=args.verbose) if args.pdf: pdf.pdf( lang, buildDir, translation, pdfName, languageData[lang]["tex_encoding"], languageData[lang]["tex_command"], verbose=args.verbose )
def gen_html(): if "id" in form: body = single_message() else: body = list_messages() return html.html( html.head( html.title("a858 auto-analysis"), html.script(language='javascript', src='functions.js') ), body )
def html_page(title, *content, **arguments): head = html.head( html.link(rel="shortcut icon", href=config["favicon"]), html.title("{} - {}".format(title, config["title"])), html.style(style), ) nav = html.nav( html.ul( html.li(html.a("⚗", href=html.absolute())), html.li(html.a("Reviews", href=html.absolute("reviews"))), html.li(html.a("Commits", href=html.absolute("commits", repo.head.ref.name))), html.li(html.a("Tree", href=html.absolute("tree", repo.head.ref.name))), html.li(html.a("Refs", href=html.absolute("refs"))), ) ) return http.Html(html.html(head, html.body(*((nav,) + content + (html.script(script),)), **arguments)))
def test(self) : self.assertEquals(breaks("hello world"),"\nhello world\n") self.assertEquals(p('hello world'),"<p>hello world</p>") self.assertEquals(div('hello world'),"<div>hello world</div>") self.assertEquals(div({'class':'myclass','id':'myd'},'hello world'), """<div class="myclass" id="myd">hello world</div>""") self.assertEquals(div('a','b'),'<div>ab</div>') self.assertEquals(p(),'<p/>') self.assertEquals(html( head(), body( h2("Header"), p('para1'), p('para2') )), """<html><head/><body><h2>Header</h2><p>para1</p><p>para2</p></body></html>""")
def write_html(data_dic): head = "" body = "" fill_content = "<td>" + str(0) + "</td>" fill_time = 0 tester_info = {} count_dic = {} sum_value = "<tr>" + "<td>" + "SUM" + "</td>" for time_key in sorted(data_dic): head = head + "<th><b>" + str(time_key) + "</b></th>" sum_value += "<td><b>" + str(len(data_dic[time_key])) + "</b></td>" count_dic[time_key] = Counter(data_dic[time_key]) for count_key in count_dic: #print count_key for tester_key, value in count_dic[count_key].items(): if tester_key not in tester_info.keys(): output_bodies = "<tr>" + "<td>" + tester_key + "</td>" tester_info[ tester_key] = output_bodies + fill_content * fill_time tester_info[tester_key] = tester_info[ tester_key] + "<td class='highlight'>" + str( value) + "</td>" for tester in tester_info.keys(): if count_dic[count_key].has_key(tester) is False: tester_info[tester] = tester_info[tester] + fill_content fill_time += 1 for key, value in tester_info.items(): body = body + value output_bodies = body + sum_value + "</tr>" now_time = strftime('%Y-%m-%d %H:%M:%S', localtime()) return html(now_time, head, output_bodies)
def generate(idcl, idcls): try: dlg = wx.FileDialog(None, 'Save report as', t_setup.get_value("path_html"), '', '*.html', wx.SAVE) if dlg.ShowModal() == wx.ID_OK: file_name = dlg.GetPath() t_setup.update({"path_html": os.path.dirname(file_name)}) data1 = get_data(idcl) data_more = [] for idcl_ in idcls: data_more.append(get_data(idcl_)) # Mounts a dict to find judge names ... data_cl = t_judge.get_all_data(("id", "name", "class_name")) dict_judge = {} for row in data_cl: dict_judge[row[0]] = row[1:3] # ... and a list of judgement objects as well ... judgements = [] for idcl_ in idcls: j = judge_object(dict_judge[idcl_][1]) judgements.append(j.judgement_object()) # ... and the reference judge j1 = judge_object(dict_judge[idcl][1]) judgement1 = j1.judgement_object() # Report beginning rows = len(data1) clss = len(idcls) print rows, len(data_more[0]) h = html.html(output_type=html.OUTPUT_FILE, file_name=file_name) h.open() h.page_header("Comparison") h.subtitle("Reference judge: " + dict_judge[idcl][0]) h.open_table() # table header h.open_tr() h.th("Classifier name", 200) h.th("% Concordance", 100) h.close_tr() i_cl = 0 for idcl_ in idcls: h.open_tr() h.td(dict_judge[idcl_][0]) count_eq = 0 # counts equalities for row1, row2 in zip(data1, data_more[i_cl]): (d1, params1) = row1 (d3, params2) = row2 judgement1.set_params(params1) judgements[i_cl].set_params(params2) count_eq = count_eq + (judgement1.compare_to( judgements[i_cl])) h.td(str(float(count_eq) / rows * 100) + "%") h.close_tr() i_cl += 1 h.close_table() h.close() except error_x, e: act_main.handle_error(e)
def _fmtPi_html(x): if x == "" or x == "--": return x else: return _hu.html(x) + "π"
def _fmtBold_html(x): return "<b>%s</b>" % _hu.html(x)
def _fmtEBPi_html(t): if t[1] is not None: return "(%s +/- %s)π" % (_hu.html(t[0]), _hu.html(t[1])) else: return _fmtPi_html(t[0])
def _fmtEBvec_html(t): if t[1] is not None: return "%s +/- %s" % (_hu.html(t[0]), _hu.html(t[1])) else: return _hu.html(t[0])
def _fmtBrk_html(x): return _hu.html(x, brackets=True)
def form(object): body = '' body += object.html(True) body += '<input type="submit" value="Save">' return html.html(body)
def _fmtNml_html(x): return _hu.html(x) def _fmtNml_latex(x): return _lu.latex(x)
def _fmtBold_html(x): return "<b>%s</b>" % _hu.html(x) def _fmtBold_latex(x): return "\\textbf{%s}" % _lu.latex(x)
def __init__(self): self.html_pages = html.html()._get_html_pages()
def _fmtSml_html(x): return _hu.html(x) def _fmtSml_latex(x): return "\\small" + _lu.latex(x)
def _fmtSml_html(x): return _hu.html(x)
except ValueError: conf[i].append(m[i]) except KeyError: conf[i] = [] conf[i].append(m[i]) # Add umounted drivers for i in conf.keys(): try: if m[i] == conf[i]: continue except: for k in conf[i]: print '<tr ondblclick="map_row(event)"><td>' print i + ":</td><td>" + k + "</td><td>" html.gen_button("map_row_click(event)", "enable") print "</td></tr>" f = file(setting_file, "w") cPickle.dump(conf, f) f.close() print "</table>" print "</body>" h = html.html() h.genHead("map drivers") gen_body()
def _fmtBrk_html(x): return _hu.html(x, brackets=True) def _fmtBrk_latex(x): return _lu.latex(x, brackets=True)
def main(): print("Getting data from the sheet...") creds = None if os.path.exists('token.pickle'): with open('token.pickle', 'rb') as token: creds = pickle.load(token) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: flow = InstalledAppFlow.from_client_secrets_file( 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run with open('token.pickle', 'wb') as token: pickle.dump(creds, token) service = build('sheets', 'v4', credentials=creds) # Call the Sheets API sheet = service.spreadsheets() result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID, range=SAMPLE_RANGE_NAME).execute() values = result.get('values', []) if not values: print('No data found.') else: # We can access the sheet values here print("Data received.") for row in values: reg_id = row[0] name = row[1] + ' ' + row[2] email = row[3] designation = row[18] org = row[21] print('Generating card for %s...' % (name)) qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=10, border=2, ) qr.add_data(reg_id) qr.make(fit=True) img = qr.make_image() # Resize the QR code to 150px X 150px img.thumbnail((221, 221), Image.ANTIALIAS) img.save(os.path.join('qrcodes', email + '.png')) template = Image.open('template.png') # Paste QR code template.paste(img, (205, 360)) # Write the name draw = ImageDraw.Draw(template) font = ImageFont.truetype(FONT, 55) x, y = font.getsize(name) draw.text(((321 - x / 2), (710 - y / 2)), name, font=font, fill='black') # Write the designation if designation != 'NA': draw = ImageDraw.Draw(template) font = ImageFont.truetype(FONT, 26) x, y = font.getsize(designation) draw.text(((321 - x / 2), (770 - y / 2)), designation, font=font, fill='black') if org != 'NA': draw = ImageDraw.Draw(template) font = ImageFont.truetype(FONT, 30) x, y = font.getsize(org) draw.text(((321 - x / 2), (810 - y / 2)), org, font=font, fill='black') # Get and paste the profile picture # print('\tGetting profile picture...') # imageResponse = requests.get(imageUrl) # profileImage = Image.open(BytesIO(imageResponse.content)) # profileImage.thumbnail((288, 288), Image.ANTIALIAS) # # Make the image a circle # bigsize = (profileImage.size[0] * 3, profileImage.size[1] * 3) # mask = Image.new('L', bigsize, 0) # maskDraw = ImageDraw.Draw(mask) # maskDraw.ellipse((0,0) + bigsize, fill=255) # mask = mask.resize(profileImage.size, Image.ANTIALIAS) # profileImage.putalpha(mask) # template.paste(profileImage, (175, 282), profileImage) # Add abstract element element = Image.open('element.png') element.thumbnail((59, 59), Image.ANTIALIAS) template.paste(element, (407, 557), element) # Save the card template.save(os.path.join('cards', email + '.png')) buffer = BytesIO() template.save(buffer, format="PNG") base64Value = base64.b64encode(buffer.getvalue()) # SEND THE CARD AS AN EMAIL data = { 'Messages': [{ "From": { "Email": ORG_EMAIL, "Name": ORG_NAME, }, "To": [{ "Email": email, "Name": name }], "Subject": "[ID Card] GDG Gandhinagar - DevFest 2019", "HTMLPart": html(name, email), "Attachments": [{ "Filename": name + '.png', "ContentType": "image/png", "Base64Content": base64Value.decode("utf-8") }] }] } print("\tSending mail to " + name + "...") result = mailjet.send.create(data=data) if result.status_code == 200: print("\t\tMail sent.") else: print("\t\tMail not sent.") print('All cards sent successfully.')
def __init__(self): handler = logging.FileHandler("Log_test.txt") logger.addHandler(handler) logger.setLevel(logging.NOTSET) logging.info(time.strftime('%Y-%m-%d %H:%M:%S') + "---" + u"初始化系统") #处理日期初始化,可以从config中读取 parseDate = DateClass() parseconfig = config() parsehtml = html() self.parseday = parseconfig.date #初始化配置信息 logging.info( time.strftime('%Y-%m-%d %H:%M:%S') + "---" + "初始化日至处理日期:" + self.parseday) self.binpath = parseconfig.getBinPath() + '\\' logging.info( time.strftime('%Y-%m-%d %H:%M:%S') + "---" + u"初始化可执行文件目录:" + self.binpath) self.logpath = parseconfig.getLogPath() + '\\' logging.info( time.strftime('%Y-%m-%d %H:%M:%S') + "---" + u"初始化日志文件目录:" + self.logpath) self.docpath = parseconfig.getDocPath() + '\\' logging.info( time.strftime('%Y-%m-%d %H:%M:%S') + "---" + u"初始化文档目录:" + self.docpath) self.dbpath = parseconfig.getDbPath() + '\\' logging.info( time.strftime('%Y-%m-%d %H:%M:%S') + "---" + u"初始化数据库文件目录:" + self.dbpath) self.filepath = parseconfig.getFilePath() + '\\' logging.info( time.strftime('%Y-%m-%d %H:%M:%S') + "---" + u"初始化日志文件目录:" + self.filepath) self.header = parsehtml.header self.css = parsehtml.css self.start = parsehtml.start self.end = parsehtml.end self.js = parsehtml.js logging.info(time.strftime('%Y-%m-%d %H:%M:%S') + "---" + u"初始化html参数") #设置数据库表名 self.tablename = "sn" + parseconfig.date logging.info( time.strftime('%Y-%m-%d %H:%M:%S') + "---" + u"初始化数据库表名:" + self.tablename) #数据库文件存储地址 self.dbfile = self.dbpath + self.parseday + '.db' logging.info( time.strftime('%Y-%m-%d %H:%M:%S') + "---" + u"初始化数据库文件:" + self.dbfile) self.export = self.docpath + parseconfig.date + "\\" logging.info( time.strftime('%Y-%m-%d %H:%M:%S') + "---" + u"初始化html文档目录:" + self.export) ff = FileUtil() ff.mkDir(self.export) logging.info( time.strftime('%Y-%m-%d %H:%M:%S') + "---" + u"创建html文档导出目录:" + self.export) fileCheck = FileUtil() errorLog = self.logpath + self.parseday fileCheck.checkFile('log/' + errorLog) fileCheck.checkFile('db/' + self.parseday)