示例#1
0
文件: logs.py 项目: ragnarokatz/wp1
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()
示例#2
0
def update_project_by_name(project_name, track_progress=False):
    wp10db = wp10_connect()
    wikidb = wiki_connect()
    redis = redis_connect()

    logging.basicConfig(level=logging.INFO)
    logging.getLogger('mwclient').setLevel(logging.CRITICAL)
    logging.getLogger('urllib3').setLevel(logging.CRITICAL)
    logging.getLogger('requests_oauthlib').setLevel(logging.CRITICAL)
    logging.getLogger('oauthlib').setLevel(logging.CRITICAL)

    try:
        project = get_project_by_name(wp10db, project_name)
        if not project:
            project = Project(p_project=project_name,
                              p_timestamp=GLOBAL_TIMESTAMP_WIKI)
        update_project(wikidb,
                       wp10db,
                       project,
                       redis=redis,
                       track_progress=track_progress)

        if track_progress:
            redis.expire(_project_progress_key(project_name), 600)
    finally:
        wp10db.close()
        wikidb.close()
示例#3
0
def main():
  wikidb = wiki_connect()
  wp10db = wp10_connect()

  logging.basicConfig(level=logging.INFO)

  for project_name in logic_project.project_names_to_update(wikidb):
    logic_project.update_global_articles_for_project_name(wp10db, project_name)
示例#4
0
文件: project.py 项目: adityavs/wp1
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()
示例#5
0
文件: tables.py 项目: 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()
示例#6
0
文件: tables.py 项目: 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()
示例#7
0
文件: project.py 项目: adityavs/wp1
def update_project_by_name(project_name):
    wp10db = wp10_connect()
    wikidb = wiki_connect()

    logging.basicConfig(level=logging.INFO)
    logging.getLogger('mwclient').setLevel(logging.CRITICAL)
    logging.getLogger('urllib3').setLevel(logging.CRITICAL)
    logging.getLogger('requests_oauthlib').setLevel(logging.CRITICAL)
    logging.getLogger('oauthlib').setLevel(logging.CRITICAL)

    try:
        project = get_project_by_name(wp10db, project_name)
        if not project:
            logger.error('No project with name: %s', project_name)
            return
        update_project(wikidb, wp10db, project)
    finally:
        wp10db.close()
        wikidb.close()