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()
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()
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()
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()