def determineTemplate(self, templates): if templates: text = self.simplifyFullText() #print(text) for template in templates: try: a = template.getPattern().match(text) #print(a) if template.getPattern().match(text): self.template = template.getTemplate() self.message_type = template.getType() return True except BaseException: pass return False
def replyMessage_flex(lineChannel, event): ''' Flex Message Simulator -> get json -> make dict -> use as content https://developers.line.biz/console/fx/ ''' print('Replying flex: {}'.format(event['replyTemplate'])) try: lineChannel.reply_message( event['lineReplyToken'], FlexSendMessage(alt_text='flex', contents=getTemplate(event['replyTemplate'])( event['replyContent']))) except LineBotApiError: raise
def replyMessage_carousel(lineChannel, event): ''' event { 'eventType': LINE_EVENT_TYPES.REPLY_CAROUSEL, 'lineReplyToken': event.reply_token, 'replyTemplate': LINE_MESSAGE_TEMPLATES.HOMEWORK, 'replyContent': [{}] } ''' print('Replying carousel: {}'.format(event['replyTemplate'])) try: lineChannel.reply_message( event['lineReplyToken'], TemplateSendMessage(alt_text='Carousel template', template=getTemplate(event['replyTemplate'])( event['replyContent']))) except LineBotApiError: raise
import re import load import template import removeStress title = "イギリス" fn = "jawiki-country.json.gz" def removeInnerLinks(dic): ret = {} r = re.compile('\[\[(.+\||)(.+?)\]\]') for key, value in dic.items(): ret[key] = r.sub(r'\2', value) return ret if __name__ == "__main__": text = load.load_text(fn, title) template = template.getTemplate(text) removed_stress = removeStress.removeStress(template) # print (removed_stress) print(removeInnerLinks(removed_stress))
def parseHtml(): soup = BeautifulSoup(template.getTemplate()) a_list = soup.findAll("a") for a in a_list: print a print len(a_list)