def build_indexpage(self): Li_Templete = "<li><a href='%s'>%s</a>" menu = [] for art in self.articles: li = Li_Templete % (art[1] + '.html', art[0]) menu.append(li) index_name = self.root + os.sep.join( ['epub', self.filename, 'OEBPS', 'html', 'index.html']) HB.build_file(index_name, HB.INDEX_TEMPLATE, ''.join(menu))
def build_infopage(self): info_name = self.root + os.sep.join([ 'epub', self.filename, 'OEBPS', 'html', 'infoPage.html' ]) HB.build_file(info_name, HB.INFOPAGE_TEMPLATE)
def build_indexpage(self): Li_Templete = "<li><a href='%s'>%s</a>" menu = [] for art in self.articles: li = Li_Templete % (art[1]+'.html', art[0]) menu.append(li) index_name = self.root + os.sep.join([ 'epub', self.filename, 'OEBPS', 'html', 'index.html' ]) HB.build_file(index_name, HB.INDEX_TEMPLATE, ''.join(menu))
def process_json(self): with open(self.root + 'articles.json', 'r') as json_file: for art in json_file: art_dict = json.loads(art) ''' keys in art_dict: [u'origin', u'author', u'title', u'image_urls', u'content', u'date', u'tag', u'en_title', u'images'] ''' # save image names if 'image_urls' in art_dict: for imname in art_dict['image_urls']: self.image_names.add(imname) # save article name for t in ('title', 'en_title', 'tag', 'date'): if not t in art_dict: art_dict[t] = "" self.articles.append((art_dict[u'title'], art_dict[u'en_title'], art_dict[u'tag'], art_dict[u'date'])) # build article html article_file_name = self.root + os.sep.join([ 'epub', self.filename, 'OEBPS', 'html', art_dict[u'en_title']+'.html' ]) HB.build_file(article_file_name, HB.ARTICLE_TEMPLATE, art_dict[u'title'], art_dict[u'title'], art_dict[u'author'], art_dict[u'date'], art_dict[u'tag'], art_dict[u'content'])
class UserLocationProcessor(object): ''' 位置意图查询 ''' def __init__(self): self.database = IkeaDatabase() self.html_builder = HtmlBuilder() def __build_webpage_get_url(self, html_file_name): ''' 页面url地址生成 html_file_name: 文件名 返回值:完整的url地址字符串 ''' rst = '' rst += global_common_params.web_server_url rst += '?' + request_params.key_req_get_type + '=' + request_params.val_req_get_type_webpage rst += '&' + request_params.key_req_get_html_file_name + '=' + html_file_name return rst def process(self, intent): ''' 位置意图处理 intent:百度UNIT返回结果封装 返回值:结果字典 ''' rsp_dict = {} rsp_dict[wechat_msg_params.key_message_type] = wechat_msg_params.val_msg_type_invalid location = intent.get_slot_location() # slot中没有位置信息 if location is None: return rsp_dict index, description = self.database.find_location(location) # 位置信息无效 if (index <= 0): return rsp_dict html_file_name = self.html_builder.location_build(ikearobot_params.pic_resource_dict[index], description) rsp_dict[wechat_msg_params.key_message_type] = wechat_msg_params.val_msg_type_news rsp_dict[wechat_msg_params.key_msg_content_title] = location + u'位置信息' rsp_dict[wechat_msg_params.key_msg_content_description] = u'点击查看详细的位置信息' rsp_dict[wechat_msg_params.key_msg_content_pciurl] = ikearobot_params.pic_resource_dict[index] rsp_dict[wechat_msg_params.key_msg_content_url] = self.__build_webpage_get_url(html_file_name) return rsp_dict
def process_json(self): with open(self.root + 'articles.json', 'r') as json_file: for art in json_file: art_dict = json.loads(art) ''' keys in art_dict: [u'origin', u'author', u'title', u'image_urls', u'content', u'date', u'tag', u'en_title', u'images'] ''' # save image names if 'image_urls' in art_dict: for imname in art_dict['image_urls']: self.image_names.add(imname) # save article name for t in ('title', 'en_title', 'tag', 'date'): if not t in art_dict: art_dict[t] = "" self.articles.append( (art_dict[u'title'], art_dict[u'en_title'], art_dict[u'tag'], art_dict[u'date'])) # build article html article_file_name = self.root + os.sep.join([ 'epub', self.filename, 'OEBPS', 'html', art_dict[u'en_title'] + '.html' ]) HB.build_file(article_file_name, HB.ARTICLE_TEMPLATE, art_dict[u'title'], art_dict[u'title'], art_dict[u'author'], art_dict[u'date'], art_dict[u'tag'], art_dict[u'content'])
def main(): # 引数を解析 parser = argparse.ArgumentParser() parser.add_argument("--t") args = parser.parse_args() # 引数を変数に設定 file_type = args.t if file_type == "plain": textbuilder = TextBuilder() director = Director(textbuilder) director.construct() result = textbuilder.get_result() print(result) elif file_type == "html": htmlbuilder = HtmlBuilder() director = Director(htmlbuilder) director.construct() filename = htmlbuilder.get_result() print("{}が作成されました".format(filename)) else: usage()
def create_password_recovery_mail_html(hash_value): builder = HtmlBuilder() text = builder.append_tag('p', u' سلام') text += builder.br() text += builder.append_tag('p', settings.PASSWORD_RECOVERY_MAIL_CONTENT) text += builder.br() text += builder.append_tag('a', u'برای تغییر رمز عبور حا را کلیک کنید.', **{'href': settings.SITE_URL + "accounts/password_change_recover/" + hash_value}) return text
def create_confirm_email_html(activation_key, type): mail_content = u'ثبتنام شما در سامانه جاک در مراحل نهایی است.برای تکمیل ثبتنام برروی لینک زیر کلیک کنید.همچنین پس از انجام این عمل باید تا زمان تایید مدیریت منتظر بمانید.' builder = HtmlBuilder() text = builder.append_tag('p', u'با سلام') text += builder.br() text += builder.append_tag('p', mail_content) text += builder.br() text += builder.append_tag('a', u'برای تایید ثبت نام در سامانه جاک اینجا را کلیک کنید', **{'href': ( settings.SITE_URL + "accounts/confirm/" + type + "/" + activation_key)}) return text
def create_manager_confirm_html(function): mail_content = '' if function == 'approve': mail_content = u'اطلاعات ثبتنام شما توسط مدیر تایید شد و میتوانید وارد سایت شوید.' elif function == 'remove': mail_content = u'اکانت شما توسط مدیر حذف گردید.' else: return mail_content builder = HtmlBuilder() text = builder.append_tag('p', u'با سلام') text += builder.br() text += builder.append_tag('p', mail_content) text += builder.br() text += builder.append_tag('a', u'سامانه جاک', **{'href': ( settings.SITE_URL )}) return text
def __init__(self): self.html_builder = HtmlBuilder() self.database = IkeaDatabase()
class UserBuyProcessor(object): ''' 商品详情查询处理 ''' def __init__(self): self.html_builder = HtmlBuilder() self.database = IkeaDatabase() def __build_webpage_get_url(self, html_file_name): ''' 页面url地址生成 html_file_name: 文件名 返回值:完整的url地址字符串 ''' rst = '' rst += global_common_params.web_server_url rst += '?' + request_params.key_req_get_type + '=' + request_params.val_req_get_type_webpage rst += '&' + request_params.key_req_get_html_file_name + '=' + html_file_name return rst def process(self, intent): ''' 商品详情意图处理 intent:百度UNIT返回结果封装 返回值:结果字典 ''' rsp_dict = {} rsp_dict[wechat_msg_params.key_message_type] = wechat_msg_params.val_msg_type_invalid goods_name = intent.get_slot_goods_name() # unit中没有商品名的slog if goods_name is None: return rsp_dict goods_filter_type, goods_filter_content = intent.get_slot_goods_filter() find_rst = self.database.find_goods(goods_name, goods_filter_type) # 数据库中没有符合查询条件的商品 if not find_rst: return rsp_dict html_file_name = self.html_builder.goods_detial_build(find_rst) rsp_dict[wechat_msg_params.key_message_type] = wechat_msg_params.val_msg_type_news if goods_filter_content: rsp_dict[wechat_msg_params.key_msg_content_title] = str(goods_filter_content) + u'的' + str( goods_name) + u'详情' else: rsp_dict[wechat_msg_params.key_msg_content_title] = str(goods_name) + u'详情' rsp_dict[wechat_msg_params.key_msg_content_description] = u'点击查看商品详情' # rsp_dict[wechat_msg_params.key_msg_content_pciurl] = ikearobot_params.goods_detail_title_pic_url # 挑选商品详情title图片 for item in find_rst: rst_goods_name = str(item[database.database_params.goods_name]) if rst_goods_name.endswith(goods_name): rsp_dict[wechat_msg_params.key_msg_content_pciurl] = item[database.database_params.goods_img] break else: rsp_dict[wechat_msg_params.key_msg_content_pciurl] = find_rst[0][database.database_params.goods_img] rsp_dict[wechat_msg_params.key_msg_content_url] = self.__build_webpage_get_url(html_file_name) return rsp_dict
def build_infopage(self): info_name = self.root + os.sep.join( ['epub', self.filename, 'OEBPS', 'html', 'infoPage.html']) HB.build_file(info_name, HB.INFOPAGE_TEMPLATE)