gcal-bot: Get API key from ~/.humbug-api-key

(imported from commit 63d63ad0d299c300d28de61069ada8ea2c8eb839)
This commit is contained in:
Keegan McAllister 2012-11-07 11:50:29 -05:00
parent 11cdc959e6
commit e42097a723

View file

@ -1,6 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
import os
import sys import sys
import time import time
import errno
import datetime import datetime
import optparse import optparse
import urlparse import urlparse
@ -40,7 +42,7 @@ parser.add_option('--user',
parser.add_option('--api-key', parser.add_option('--api-key',
dest='api_key', dest='api_key',
action='store', action='store',
help='API key for that user') help='API key for that user [default: read ~/.humbug-api-key]')
parser.add_option('--calendar', parser.add_option('--calendar',
dest='calendar', dest='calendar',
action='store', action='store',
@ -62,6 +64,14 @@ parser.add_option('--interval',
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if not options.api_key:
try:
with open(path.join(os.environ['HOME'], '.humbug-api-key'), 'r') as f:
options.api_key = f.read().strip()
except IOError as e:
if e.errno != errno.ENOENT:
raise
if not (options.user and options.api_key and options.calendar): if not (options.user and options.api_key and options.calendar):
parser.error('You must specify --user, --api-key, and --calendar') parser.error('You must specify --user, --api-key, and --calendar')