forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiana-changes-updates
More file actions
executable file
·85 lines (63 loc) · 2.99 KB
/
iana-changes-updates
File metadata and controls
executable file
·85 lines (63 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# This script requires that the proper virtual python environment has been
# invoked before start
import datetime
import os
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"
import django
django.setup()
from django.conf import settings
from optparse import OptionParser
from zoneinfo import ZoneInfo
parser = OptionParser()
parser.add_option("-f", "--from", dest="start",
help="Start time, defaults to a little less than 23 hours ago", metavar="YYYY-MM-DD HH:MM:SS")
parser.add_option("-t", "--to", dest="end",
help="End time, defaults to 23 hours later than from", metavar="YYYY-MM-DD HH:MM:SS")
parser.add_option("", "--no-email", dest="send_email", default=True, action="store_false",
help="Skip sending emails")
options, args = parser.parse_args()
# compensate to avoid we ask for something that happened now and then
# don't get it back because our request interval is slightly off
CLOCK_SKEW_COMPENSATION = 5 # seconds
# actually the interface accepts 24 hours, but then we get into
# trouble with daylights savings - meh
MAX_INTERVAL_ACCEPTED_BY_IANA = datetime.timedelta(hours=23)
local_tzinfo = ZoneInfo(settings.TIME_ZONE)
start = datetime.datetime.now() - datetime.timedelta(hours=23) + datetime.timedelta(seconds=CLOCK_SKEW_COMPENSATION)
if options.start:
start = datetime.datetime.strptime(options.start, "%Y-%m-%d %H:%M:%S")
start = start.replace(tzinfo=local_tzinfo).astimezone(datetime.timezone.utc)
end = start + datetime.timedelta(hours=23)
if options.end:
end = datetime.datetime.strptime(options.end, "%Y-%m-%d %H:%M:%S").replace(tzinfo=local_tzinfo)
end = end.astimezone(datetime.timezone.utc)
syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER)
# ----------------------------------------------------------------------
from ietf.sync.iana import fetch_changes_json, parse_changes_json, update_history_with_changes
syslog.syslog(
"Updating history log with new changes from IANA from %s, period %s - %s" % (
settings.IANA_SYNC_CHANGES_URL,
start.astimezone(local_tzinfo),
end.astimezone(local_tzinfo),
)
)
t = start
while t < end:
# the IANA server doesn't allow us to fetch more than a certain
# period, so loop over the requested period and make multiple
# requests if necessary
text = fetch_changes_json(settings.IANA_SYNC_CHANGES_URL, t, min(end, t + MAX_INTERVAL_ACCEPTED_BY_IANA))
syslog.syslog("Retrieved the JSON: %s" % text)
changes = parse_changes_json(text)
added_events, warnings = update_history_with_changes(changes, send_email=options.send_email)
for e in added_events:
syslog.syslog("Added event for %s %s: %s (parsed json: %s)" % (e.doc_id, e.time, e.desc, e.json))
for w in warnings:
syslog.syslog("WARNING: %s" % w)
t += MAX_INTERVAL_ACCEPTED_BY_IANA