Last active
February 8, 2016 13:07
-
-
Save kubek2k/393c872fb85521ccedc5 to your computer and use it in GitHub Desktop.
Gets on call calendar from PagerDuty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import urllib | |
import sys | |
import os | |
import json | |
import datetime | |
from pytz import timezone | |
FROM_FORMAT = "%Y-%m-%dT%H:%M:%SZ" | |
TO_FORMAT = "%Y-%m-%d %H:%M" | |
params = urllib.urlencode({ | |
'since': sys.argv[1], | |
'until': sys.argv[2]}) | |
token = os.environ['PAGERDUTY_TOKEN'] | |
request = urllib2.Request('https://plan3.pagerduty.com/api/v1/schedules/P2MDTFE/entries?' + params, | |
None, | |
{ | |
'Authorization': 'Token token=' + token | |
}) | |
response = urllib2.urlopen(request) | |
data = json.loads(response.read()) | |
stockholm = timezone("Europe/Stockholm") | |
utc = timezone("UTC") | |
for entry in data['entries']: | |
start = utc.localize(datetime.datetime.strptime(entry['start'], FROM_FORMAT)) | |
end = utc.localize(datetime.datetime.strptime(entry['end'], FROM_FORMAT)) | |
print entry['user']['name'] + "\t\t: from " + start.astimezone(stockholm).strftime(TO_FORMAT) + "\t to " + end.astimezone(stockholm).strftime(TO_FORMAT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment