示例#1
0
文件: app.py 项目: dissemin/oabot
def get_proposed_edits(page_name, force, follow_redirects=True):
    # Get the page
    text = main.get_page_over_api(page_name)

    # See if it's a redirect
    redir = redirect_re.match(text)
    if redir:
        return get_proposed_edits(redir.group(1), force, False)

    # See if we already have it cached
    cache_fname = "cache/"+to_cache_name(page_name)
    if not force and os.path.isfile(cache_fname):
        with open(cache_fname, 'r') as f:
            return json.load(f)

    # Otherwise, process it
    all_templates = main.add_oa_links_in_references(text, page_name)
    filtered = list(filter(lambda e: e.proposed_change, all_templates))
    context = {
    'proposed_edits': [change.json() for change in filtered],
    'page_name' : page_name,
        'utcnow': unicode(datetime.datetime.utcnow()),
    }

    if filtered:
        # Cache the result
        with open(cache_fname, 'w') as f:
            json.dump(context, f)
    elif os.path.isfile(cache_fname):
        os.remove(cache_fname)

    return context
示例#2
0
def perform_edit():
    data = flask.request.form

    # Check we are logged in
    access_token = flask.session.get('access_token', None)
    if not access_token:
        return flask.redirect(flask.url_for('login'))

    page_name = data.get('name')
    summary = data.get('summary')
    if not summary:
        raise InvalidUsage('No edit summary provided')

    # Get the page
    text = main.get_page_over_api(page_name)

    # Perform each edit
    new_text, change_made = make_new_wikicode(text, data, page_name)

    # Remove the cache
    cache_fname = "cache/" + to_cache_name(page_name)
    if os.path.isfile(cache_fname):
        os.remove(cache_fname)

    # Save the page
    if change_made:
        access_token = flask.session.get('access_token', None)
        edit_wiki_page(page_name, new_text, access_token, summary)
        UserStats.increment_user('en', flask.session.get('username', None), 1,
                                 1)

        return flask.redirect(flask.url_for('get_random_edit'))
    else:
        return flask.redirect(flask.url_for('index', success='nothing'))
示例#3
0
def get_proposed_edits(page_name,
                       force,
                       follow_redirects=True,
                       only_doi=False):
    # Get the page
    text = main.get_page_over_api(page_name)

    # See if it's a redirect
    redir = redirect_re.match(text)
    if redir:
        return get_proposed_edits(redir.group(1), force, False, only_doi)

    # See if we already have it cached
    cache_fname = "cache/" + to_cache_name(page_name)
    if not force and os.path.isfile(cache_fname):
        with open(cache_fname, 'r') as f:
            return json.load(f)

    # Otherwise, process it
    all_templates = main.add_oa_links_in_references(text, page_name, only_doi)
    filtered = list(filter(lambda e: e.proposed_change, all_templates))
    context = {
        'proposed_edits': [change.json() for change in filtered],
        'page_name': page_name,
        'utcnow': unicode(datetime.datetime.utcnow()),
    }

    if filtered:
        # Cache the result
        with open(cache_fname, 'w') as f:
            json.dump(context, f)
    elif os.path.isfile(cache_fname):
        os.remove(cache_fname)

    return context
示例#4
0
文件: app.py 项目: dissemin/oabot
def preview_edit():
    data = flask.request.form

    page_name = data.get('name')
    summary = data.get('summary')
    if not summary:
        raise InvalidUsage('No edit summary provided')

    # Get the page
    text = main.get_page_over_api(page_name)

    # Perform each edit
    new_text, change_made = make_new_wikicode(text, data, page_name)

    diff = make_diff(text, new_text)
    return '<div class="diffcontainer">'+diff+'</div>'
示例#5
0
def preview_edit():
    data = flask.request.form

    page_name = data.get('name')
    summary = data.get('summary')
    if not summary:
        raise InvalidUsage('No edit summary provided')

    # Get the page
    text = main.get_page_over_api(page_name)

    # Perform each edit
    new_text, change_made = make_new_wikicode(text, data, page_name)

    diff = make_diff(text, new_text)
    return '<div class="diffcontainer">' + diff + '</div>'
示例#6
0
文件: app.py 项目: dissemin/oabot
def perform_edit():
    data = flask.request.form

    # Check we are logged in
    access_token =flask.session.get('access_token', None)
    if not access_token:
        return flask.redirect(flask.url_for('login'))

    page_name = data.get('name')
    summary = data.get('summary')
    if not summary:
        raise InvalidUsage('No edit summary provided')

    # Get the page
    text = main.get_page_over_api(page_name)

    # Perform each edit
    new_text, change_made = make_new_wikicode(text, data, page_name)

    # Save the page
    if change_made:
        access_token = flask.session.get('access_token', None)
        edit_wiki_page(page_name, new_text, access_token, summary)
        UserStats.increment_user(
            'en',
            flask.session.get('username', None),
            1, 1)

        # Remove the cache
        cache_fname = "cache/"+to_cache_name(page_name)
        if os.path.isfile(cache_fname):
            os.remove(cache_fname)

        return flask.redirect(flask.url_for('get_random_edit'))
    else:
        return flask.redirect(flask.url_for('index', success='nothing'))