Пример #1
0
def is_spam(request):
    from pykismet3 import Akismet
    import os

    a = Akismet(blog_url="http://wiseinit.com",
                user_agent="WiseInit System/0.0.1")

    a.api_key = get_setting('akismet')

    check = {
        'user_ip': request.META['REMOTE_ADDR'],
        'user_agent': request.META['HTTP_USER_AGENT'],
        'referrer': request.META.get('HTTP_REFERER', 'unknown'),
        'comment_content': request.POST['comment'],
        'comment_author': request.POST['name'],
    }

    if request.POST['email'].strip():
        check['comment_author_email'] = request.POST['email']

    if request.POST['website'].strip():
        website = request.POST['website'].strip()
        if website and not re.match('https?://.+', website):
            website = 'http://' + website

        check['comment_author_url'] = website

    return a.check(check)
Пример #2
0
def mark_it_spam(comment_id):
    comment = Comment.query.filter_by(
                                id=comment_id, mark_for_delete=False).first()
    if comment is None:
        response = make_response(
            jsonify({'not found': 'No such comment'}), 404)
    else:
        a = Akismet(blog_url=comment.post_url,
                    user_agent=comment.user_agent)
        a.api_key = app.config['AKISMET_API_KEY']

        a.submit_spam({'user_ip': comment.user_ip,
            'user_agent': comment.user_agent,
            'referrer': comment.referrer,
            'comment_type': comment.comment_type,
            'comment_author': comment.comment_author,
            'comment_author_email': comment.comment_author_email,
            'comment_content': comment.comment_content,
            'website': comment.website
        })
        comment.mark_for_delete = True
        db.session.commit()
        app.logger.info("The comment was submitted as spam")
        response = make_response(
            jsonify({'success': 'The comment was submitted as spam'}), 200)

    return response
Пример #3
0
def mark_it_valid(comment_id):
    comment = Comment.query.filter_by(
                                id=comment_id, mark_for_delete=False).first()
    if comment is None:
        response = make_response(
            jsonify({'not found': 'No such comment'}), 404)
    else:
        a = Akismet(blog_url=comment.post_url,
                    user_agent=comment.user_agent)
        a.api_key = app.config['AKISMET_API_KEY']

        a.submit_ham({'user_ip': comment.user_ip,
            'user_agent': comment.user_agent,
            'referrer': comment.referrer,
            'comment_type': comment.comment_type,
            'comment_author': comment.comment_author,
            'comment_author_email': comment.comment_author_email,
            'comment_content': comment.comment_content,
            'website': comment.website
        })

        date_str = get_current_datetime_str(comment.submit_datetime)
        name = comment.comment_author
        email = comment.comment_author_email
        website_value = comment.website
        message = comment.comment_content
        slug = comment.slug

        github_token = app.config['GITHUB_TOKEN']
        github_username = app.config['GITHUB_USERNAME']
        github_repo_name = app.config['GITHUB_REPO_NAME']

        if not create_github_pull_request(github_token, github_username, \
            github_repo_name, slug, name, message, date_str, \
            email, website_value):
            app.logger.info("Problem encountered during creation of pull request")
            response = make_response(jsonify({'error': 'Internal Error'}), 500)
        else:
            app.logger.info("Pull request created successfully")
            comment.mark_for_delete = True
            db.session.commit()
            response = make_response(
                jsonify({'success': 'The comment was submitted as valid'}), 200)

    return response
Пример #4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from pykismet3 import Akismet

from config.db import Config

config = Config('akismet')

a = Akismet(blog_url="", user_agent="Testing/Testing")

a.api_key = config['api_key']

print(
    a.check({
        'user_ip': '127.0.0.1',
        'user_agent': 'Mozilla/Firefox',
        'referrer': 'unknown',
        'comment_content': """Batman V Superman : Dawn of Justice
http://sendalgiceng21.blogspot.com/2016/03/batman-v-superman-dawn-of-justice.html

Captain America Civil War
http://sendalgiceng21.blogspot.com/2016/03/captain-america-civil-war.html

XXX : The Return Of Xander Cage
http://sendalgiceng21.blogspot.com/2016/03/xxx-return-of-xander-cage.html

Deadpool
http://sendalgiceng21.blogspot.com/2016/03/ddeadpool.html
Пример #5
0
from pykismet3 import Akismet

# code is wrong

# defaultagent = 'akismettest python script from the Collective Intelligence book'
defaultagent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us) '
defaultagent += 'AppleWebKit/525.27.1 (KHTML, like Gecko) '
defaultagent += 'Version/3.2.1 Safari/525.27.1'

a = Akismet(blog_url='moneydboat.top', user_agent=defaultagent)
a.api_key = 'e467cda4de57'


def isspam(comment, author, ip, agent=defaultagent):
    try:
        result = a.check({
            'user_ip': ip,
            'user_agent': agent,
            'referrer': 'unknown',
            'comment_content': comment,
            'comment_author': author,
            'is_test': 1,
        })
        print(result)
    except Akismet.AkismetError as e:
        print(e.response, e.statuscode)
        return False