Esempio n. 1
0
 def update(self, data):
     for k, v in data.iteritems():
         if not v and (k == 'description' or k == 'style'):
             v = ''
         if k == 'style' and v:
             v = strip_tags(v)
         setattr(self, k, v)
     self.summary = strip_tags(self.description)
     try:
         commit()
     except:
         pass
     return self
Esempio n. 2
0
    def process_sections(self, section):
        AvailableSections.titles[section.title] += 1

        if section.title == 'NAME':
            try:
                contents = []
                for c in section.contents:
                    if not isinstance(c, str):
                        break

                    contents.append(c)

                content = strip_tags(' '.join(contents))
            except:
                raise
            chunks = content.split(' - ', 1)

            if len(chunks) == 1:
                chunks = content.split(' -- ', 1)

            if len(chunks) == 1:
                self.title = content.strip().capitalize()
            else:
                self.title = chunks[-1].strip().capitalize()
            return False
        elif section.title == 'SEE ALSO':
            section.title = "RELATED TO %s…" % self.name

        return True
Esempio n. 3
0
 def post(self):
     if not self.has_permission:
         return
     user = self.current_user
     content = self.get_argument("content", None)
     if content and len(strip_tags(content)) >= 3:
         tweet = Tweet(content=strip_xss_tags(content), user_id=user.id).save()
         tweet.put_notifier()
         result = {
             "status": "success",
             "message": "推文创建成功",
             "content": tweet.content,
             "name": tweet.author.name,
             "nickname": tweet.author.nickname,
             "author_avatar": tweet.author.get_avatar(size=48),
             "author_url": tweet.author.url,
             "author_name": tweet.author.name,
             "author_nickname": tweet.author.nickname,
             "tweet_url": tweet.url,
             "created": tweet.created,
             "id": tweet.id,
         }
         if self.is_ajax:
             return self.write(result)
         self.flash_message(**result)
         return self.redirect("/timeline")
     result = {"status": "error", "message": "推文内容至少 3 字符"}
     if self.is_ajax:
         return self.write(result)
     self.flash_message(**result)
     return self.redirect("/timeline")
Esempio n. 4
0
 def post(self):
     if not self.has_permission:
         return
     user = self.current_user
     content = self.get_argument('content', None)
     if content and len(strip_tags(content)) >= 3:
         tweet = Tweet(content=strip_xss_tags(content), user_id=user.id).save()
         tweet.put_notifier()
         result = {
                     'status'          : 'success',
                     'message'         : '推文创建成功',
                     'content'         : tweet.content,
                     'name'            : tweet.author.name,
                     'nickname'        : tweet.author.nickname,
                     'author_avatar'   : tweet.author.get_avatar(size=48),
                     'author_url'      : tweet.author.url,
                     'author_name'     : tweet.author.name,
                     'author_nickname' : tweet.author.nickname,
                     'tweet_url'       : tweet.url,
                     'created'         : tweet.created,
                     'id'              : tweet.id
                 }
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect('/timeline')
     result = {
                 'status': 'error',
                 'message': '推文内容至少 3 字符'
             }
     if self.is_ajax:
         return self.write(result)
     self.flash_message(result)
     return self.redirect('/timeline')
Esempio n. 5
0
 def validate_content(self, field):
     """ 为了照顾一图流
     """
     if field.data.find('<img class="upload-topic-image"') == -1 and\
        field.data.find('<embed type="application') == -1:
         data = strip_tags(field.data)
         if len(data) < 3:
             raise ValidationError('内容至少 3 字符')
Esempio n. 6
0
 def validate_content(self, field):
     """ 为了照顾一图流
     """
     if field.data.find('<img class="upload-reply-image"') == -1 and\
         field.data.find('<embed type="application') == -1:
         data = strip_tags(field.data)
         if len(data) < 3:
             raise ValidationError('内容至少 3 字符')
Esempio n. 7
0
def handle_content(htmlstr):

    def rep_html(html,htmlstr):
        rep_html = get_rep_html(html)
        rep_endhtml = get_endrep_html(html)

        rex_html = "(<\s*{}[^>]*>)".format(html)
        compile_html = re.compile(rex_html, re.I)
        htmlstr = compile_html.sub(rep_html, htmlstr)

        rex_endhtml = "(<\s*/\s*{}\s*>)".format(html)
        compile_endhtml = re.compile(rex_endhtml, re.I)
        return compile_endhtml.sub(rep_endhtml, htmlstr)

    htmlstr = rep_html('p',htmlstr)
    htmlstr = rep_html('table',htmlstr)
    htmlstr = rep_html('tbody',htmlstr)
    htmlstr = rep_html('tr',htmlstr)
    htmlstr = rep_html('td',htmlstr)

    # 过滤
    htmlstr=htmlstr \
        .replace('\r', '') \
        .replace('\t', '') \
        .replace('\n', '') \
        .replace('𠴂', '口') \
        .replace('&#134402;', '口').strip()

    # 过滤空格
    re_stopwords=re.compile('\u3000', re.I)
    htmlstr=re_stopwords.sub('', htmlstr)
    re_stopwords2=re.compile('\xa0', re.I)
    htmlstr=re_stopwords2.sub('', htmlstr)
    # 过滤垃圾
    re_script=re.compile('<\s*script[^>]*>[^<]*<\s*/\s*script\s*>',
                         re.I)  # Script
    re_style=re.compile('<\s*style[^>]*>[^<]*<\s*/\s*style\s*>', re.I)  # style
    re_a=re.compile('<\s*a[^>]*>', re.I)  # a
    re_enda=re.compile('<\s*/\s*a\s*>', re.I)  # a


    htmlstr=re_script.sub('', htmlstr)
    htmlstr=re_style.sub('', htmlstr)
    htmlstr=re_a.sub('', htmlstr)
    htmlstr=re_enda.sub('', htmlstr)

    # 过滤HTML
    htmlstr=helpers.strip_tags(htmlstr)
    # 转译emoji
    htmlstr=emoji.demojize(htmlstr)
    # 遗漏的HTML转义
    htmlstr=html.unescape(htmlstr)
    htmlstr=html.escape(htmlstr)
    htmlstr=htmlstr.strip()
    return htmlstr
Esempio n. 8
0
 def post(self):
     if not self.has_permission:
         return
     user = self.current_user
     content = self.get_argument('content', None)
     image_ids = self.get_argument('image_ids', None)
     images = []
     if content and len(strip_tags(content)) >= 3:
         tweet = Tweet(content=strip_xss_tags(content), user_id=user.id).save()
         tweet.put_notifier()
         if image_ids:
             image_ids = image_ids.split(',')
             for image_id in image_ids:
                 image_id = int(image_id)
                 image = Image.get(id=image_id)
                 if image:
                     image.tweet_id = tweet.id
                     images.append({
                         'id': image.id,
                         'path': image.path,
                         'width': image.width,
                         'height': image.height,
                         })
         if images != []:
             tweet.has_img = 'true'
         result = {
                     'status'          : 'success',
                     'message'         : '推文创建成功',
                     'content'         : tweet.content,
                     'name'            : tweet.author.name,
                     'nickname'        : tweet.author.nickname,
                     'author_avatar'   : tweet.author.get_avatar(size=48),
                     'author_url'      : tweet.author.url,
                     'author_name'     : tweet.author.name,
                     'author_nickname' : tweet.author.nickname,
                     'tweet_url'       : tweet.url,
                     'created'         : tweet.created,
                     'id'              : tweet.id,
                     'images'          : images,
                 }
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect('/timeline')
     result = {
                 'status': 'error',
                 'message': '推文内容至少 3 字符'
             }
     if self.is_ajax:
         return self.write(result)
     self.flash_message(result)
     return self.redirect('/timeline')
Esempio n. 9
0
def get_question_response(intent, session):
    """ Finds the closes question, pulls the answer and reports back
    """
    card_title = intent['name']
    session_attributes = {}
    should_end_session = True
    speech_output = strings.FAILURE
    reprompt_text = strings.PROMPT_ASK
    logging.info(intent)
    if not 'question' in intent['slots']:
        speechlet_response = build_speechlet_response(card_title, speech_output, reprompt_text, should_end_session)
        return build_response(session_attributes, speechlet_response)

    encoded_question = urllib2.quote(intent['slots']['question']['value'])
    logging.info(encoded_question)
    url = settings.ASK_QUESTION_ENDPOINT.format(question=encoded_question)
    logging.info('Getting: ' + url)
    resp = requests.get(url).json()
    logging.info(resp)
    try:
        site_question = resp['items'][0]
    except (IndexError, KeyError):
        speech_output = strings.NO_QUESTIONS
        speechlet_response = build_speechlet_response(card_title, speech_output, reprompt_text, should_end_session)
        return build_response(session_attributes, speechlet_response)

    site_question_question_id = site_question['question_id']
    site_question_title = site_question['title']
    logging.warn(site_question_title)
    url = settings.GET_ANSWERS_ENDPOINT.format(question_id=site_question_question_id)
    resp = requests.get(url).json()
    try:
        site_answer = sorted(resp['items'][0]['answers'], key=lambda i: i['score'], reverse=True)[0]
    except (IndexError, KeyError) as e:

        speech_output = strings.NO_ANSWERS.format(question=encoded_question)
        speechlet_response = build_speechlet_response(card_title, speech_output, reprompt_text, should_end_session)
        return build_response(session_attributes, speechlet_response)

    site_answer_answerer = site_answer['owner']['display_name']
    site_answer_score = site_answer['score']
    site_answer_body = strip_tags(site_answer['body'])

    speech_output = strings.REPORT.format(
        question=site_question_title,
        answerer=site_answer_answerer,
        votes=site_answer_score,
        answer=site_answer_body
    )
    logging.info(speech_output)
    speechlet_response = build_speechlet_response(card_title, speech_output, reprompt_text, should_end_session)
    return build_response(session_attributes, speechlet_response)
Esempio n. 10
0
    def post(self):
        if not self.has_permission:
            return
        user = self.current_user
        name = self.get_argument('name', None)
        name = strip_tags(name)
        if not name:
            return self.send_error_result(msg=u'没有填写专辑名')

        if len(name) >= 10:
            return self.send_error_result(msg=u'专辑名不能超过 10 个字符')

        album = Album(name=name, user_id=user.id).save()
        return self.send_success_result(data=album.to_dict())
Esempio n. 11
0
 def update(self, data):
     if data.get('nickname') != self.nickname:
         self.edit_nickname_count -= 1
     if data.get('urlname') != self.urlname:
         self.edit_urlname_count -= 1
     for k, v in data.iteritems():
         if not v and k in ['address', 'website', 'description', 'style', 'site_style']:
             v = ''
         if v and k in ['style', 'site_style']:
             v = strip_tags(v)
         setattr(self, k, v)
     try:
         commit()
     except:
         pass
     return self
Esempio n. 12
0
 def update(self, data):
     if data.get('nickname') != self.nickname:
         self.edit_nickname_count -= 1
     if data.get('urlname') != self.urlname:
         self.edit_urlname_count -= 1
     for k, v in data.iteritems():
         if not v and (k == 'address' or k == 'website'
                       or k == 'description' or k == 'style'):
             v = ''
         if k == 'style' and v:
             v = strip_tags(v)
         setattr(self, k, v)
     try:
         commit()
     except:
         pass
     return self
Esempio n. 13
0
 def update(self, data):
     if data.get('nickname') != self.nickname:
         self.edit_nickname_count -= 1
     if data.get('urlname') != self.urlname:
         self.edit_urlname_count -= 1
     for k, v in data.iteritems():
         if not v and k in ['address', 'website', 'description', 'style',
                            'site_style']:
             v = ''
         if v and k in ['style', 'site_style']:
             v = strip_tags(v)
         setattr(self, k, v)
     try:
         orm.commit()
     except:
         pass
     return self
Esempio n. 14
0
def recent_comments():
    comments_q = meta.Session.query(model.Comment).filter(model.Comment.approved==True)
    comments_q = comments_q.order_by(model.comments_table.c.created_on.desc())
    recent_comments = comments_q.join(model.Post).limit(4)
    if recent_comments is None:
        return ''
    else:
        comments= []
        template = """
        <div id="wurdig-recent-comments" class="wurdig-sidebar-list">
            <h2>Newest Comments</h2>
            <ul>
                %s
            </ul>
        </div>
        """

        for comment in recent_comments:
            i = """
                <li class="%s">
                    <span class="lone">%s shared: </span>
                    <span>%s</span>
                    <span>Shared in: %s</span>
                </li>
            """
            name = comment.name
            if comment.url is not None:
                name = h.link_to(comment.name, comment.url)
            
            content = h.truncate(h.strip_tags(comment.content), 80)
                             
            link = h.link_to(
                comment.posts.title,
                h.url_for(
                    controller='post', 
                    action='view', 
                    year=comment.posts.posted_on.strftime('%Y'), 
                    month=comment.posts.posted_on.strftime('%m'), 
                    slug=comment.posts.slug,
                    anchor=u"comment-" + str(comment.id)
                )
            )
            comments.append(i % (comment.id, name, content, link))
        return template % '\n'.join(comments)
Esempio n. 15
0
    def save(self, category='create', user=None):
        now = int(time.time())

        if category == 'create':
            self.created_at = now

        if not user:
            user = self.author

        if self.description:
            self.summary = strip_tags(self.description)

        self.updated_at = now
        self.active = now

        if user:
            user.active = now

        return super(Node, self).save()
Esempio n. 16
0
 def post(self):
     user = self.current_user
     content = self.get_argument('content', None)
     image_ids = self.get_argument('image_ids', None)
     images = []
     if not (content and len(strip_tags(content)) >= 3):
         result = {'status': 'error', 'message': '推文内容至少 3 字符'}
         return self.send_result(result, '/timeline')
     tweet = Tweet(content=strip_xss_tags(content), user_id=user.id).save()
     tweet.put_notifier()
     if image_ids:
         image_ids = image_ids.split(',')
         for image_id in image_ids:
             image_id = int(image_id)
             image = Image.get(id=image_id)
             if not image:
                 continue
             image.tweet_id = tweet.id
             images.append({
                 'id': image.id,
                 'path': image.path,
                 'width': image.width,
                 'height': image.height,
             })
     if images:
         tweet.has_img = 'true'
     result = {
         'status': 'success',
         'message': '推文创建成功',
         'content': tweet.content,
         'name': tweet.author.name,
         'nickname': tweet.author.nickname,
         'author_avatar': tweet.author.get_avatar(size=48),
         'author_url': tweet.author.url,
         'author_name': tweet.author.name,
         'author_nickname': tweet.author.nickname,
         'tweet_url': tweet.url,
         'created': tweet.created,
         'id': tweet.id,
         'images': images,
     }
     return self.send_result(result, '/timeline')
Esempio n. 17
0
File: cron.py Progetto: txsl/MADMail
        send_to = []

        if email.email_parents:
            send_to = family_emails[parents]['Parents']
        if email.email_children:
            send_to = send_to + family_emails[parents]['Children']

        print send_to

        # Comment when deployed hashtag safetyfirst hashtag alwaysuseprotection
        send_to = ['*****@*****.**']

        # Time for templating
        template = env.get_template(TEMPLATE)
        output = template.render(content=Markup(merged_content), top_text=email.top_text)
        text_output = strip_tags(merged_content)


        mail.queue_mail(email.Subject, ("Mums and Dads", "*****@*****.**"),
                        send_to, html_body=output, text_body=text_output)

        # Comment when deployed hashtag safetyfirst hashtag alwaysuseprotection
        break

    mail.send_queue()


"""
The following tags will work:
!PARENTFIRSTNAMES!
!PARENTSFULLNAMES!
Esempio n. 18
0
 def format_content(self):
     return strip_tags(self.content)[0:40] + '...'