Ejemplo n.º 1
0
def update_log_page_for_project(project_name):
  wikidb = wiki_connect()
  wp10db = wp10_connect()
  try:
    log_map = calculate_logs_to_update(wikidb, wp10db, project_name)
    edits = generate_log_edits(wikidb, wp10db, project_name, log_map)

    p = api.get_page(log_page_name(project_name))

    header = ('{{Log}}\n'
              '<noinclude>[[Category:%s articles by quality]]</noinclude>\n' %
              project_name.decode('utf-8').replace('_', ' '))

    if len(edits) == 0:
      today = get_current_datetime()
      from_dt = get_current_datetime() - timedelta(days=7)
      update = ("%s'''There were no logs for this project from %s - %s.'''" %
                (header, from_dt.strftime(LOG_DATE_FORMAT),
                 today.strftime(LOG_DATE_FORMAT)))
    else:
      update = header + '\n'.join(edits)
      i = 1
      while len(update) > 2048 * 1024:
        update = header + '\n'.join(edits[:-1 * i])
        i += 1
        if i == len(edits):
          update = (header + 'Sorry, all of the logs for this date were too '
                    'large to upload.')

    api.save_page(p, update, 'Update logs for past 7 days')
  finally:
    if wikidb:
      wikidb.close()
    if wp10db:
      wp10db.close()
Ejemplo n.º 2
0
def redirect(name, timestamp):
  page = get_page(name)
  revid = get_revision_id_by_timestamp(page, timestamp)

  if revid:
    return flask.redirect('%sindex.php?title=%s&oldid=%s' %
                          (FRONTEND_WIKI_BASE, name, revid))

  return flask.abort(404)
Ejemplo n.º 3
0
def update_global_project_count():
    wp10db = wp10_connect()
    try:
        logger.info('Querying for number of projects')

        count = count_projects(wp10db)

        logger.info('Found %s projects, updating wiki', count)
        page = api.get_page('User:WP 1.0 bot/Data/Count')
        api.save_page(page, '%s\n' % count,
                      'Updating count: %s projects' % count)
    finally:
        wp10db.close()
Ejemplo n.º 4
0
Archivo: tables.py Proyecto: jcrben/wp1
def upload_global_table():
    logging.basicConfig(level=logging.INFO)
    wp10db = wp10_connect()

    try:
        logger.info('Getting table data for: global table')
        table_data = generate_global_table_data(wp10db)
        wikicode = create_wikicode(table_data)
        page_name = 'User:WP 1.0 bot/Tables/OverallArticles'
        logger.info('Uploading wikicode to Wikipedia: global table')
        page = api.get_page(page_name)
        api.save_page(page, wikicode, 'Copying assessment table to wiki.')
    finally:
        if wp10db is not None:
            wp10db.close()
Ejemplo n.º 5
0
Archivo: tables.py Proyecto: jcrben/wp1
def upload_project_table(project_name):
    logging.basicConfig(level=logging.INFO)
    wp10db = wp10_connect()

    try:
        logger.info('Getting table data for project: %s',
                    project_name.decode('utf-8'))
        table_data = generate_project_table_data(wp10db, project_name)
        wikicode = create_wikicode(table_data)
        page_name = ('User:WP 1.0 bot/Tables/Project/%s' %
                     project_name.decode('utf-8'))
        page = api.get_page(page_name)
        logger.info('Uploading wikicode to Wikipedia: %s',
                    project_name.decode('utf-8'))
        api.save_page(page, wikicode, 'Copying assessment table to wiki.')
    finally:
        if wp10db is not None:
            wp10db.close()
Ejemplo n.º 6
0
def get_extra_assessments(project_name):
    ans = {'extra': {}}
    page_name = logic_util.category_for_project_by_kind(
        project_name, AssessmentKind.QUALITY).decode('utf-8')
    logging.debug('Retrieving page %s from API', page_name)
    page = api.get_page(page_name)
    if page is None:
        return ans

    text = page.text(section=0)
    wikicode = mwparserfromhell.parse(text)

    template = None
    for candidate_template in wikicode.filter_templates():
        if candidate_template.name.strip() == 'ReleaseVersionParameters':
            template = candidate_template
            break

    if template is None:
        return ans

    for key in ('parent', 'shortname', 'homepage'):
        if template.has(key):
            ans[key] = template.get(key).value.strip()

    extra = defaultdict(dict)
    for param in template.params:
        md = RE_EXTRA.match(param.name.strip())
        if md:
            extra[md.group(1)][md.group(2)] = (template.get(
                param.name).value.strip())

    for num_str, params in extra.items():
        if ('title' not in params or 'type' not in params
                or 'category' not in params or 'ranking' not in params):
            continue

        category = params['category'].replace('%s:' % CATEGORY_NS_STR,
                                              '').replace(' ', '_')
        params['category'] = category
        ans['extra'][category] = params

    return ans