#!/usr/bin/env python # This script requires that the proper virtual python environment has been # invoked before start import datetime import os import requests import sys import syslog # boilerplate basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) sys.path = [ basedir ] + sys.path os.environ["DJANGO_SETTINGS_MODULE"] = "ietf.settings" syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER) import django django.setup() from django.conf import settings from ietf.sync.iana import parse_protocol_page, update_rfc_log_from_protocol_page def chunks(l, n): """Split list l up in chunks of max size n.""" return (l[i:i+n] for i in range(0, len(l), n)) syslog.syslog("Updating history log with new RFC entries from IANA protocols page %s" % settings.IANA_SYNC_PROTOCOLS_URL) # FIXME: this needs to be the date where this tool is first deployed rfc_must_published_later_than = datetime.datetime(2012, 11, 26, 0, 0, 0) text = requests.get(settings.IANA_SYNC_PROTOCOLS_URL).text rfc_numbers = parse_protocol_page(text) for chunk in chunks(rfc_numbers, 100): updated = update_rfc_log_from_protocol_page(chunk, rfc_must_published_later_than) for d in updated: syslog.syslog("Added history entry for %s" % d.display_name())