gcal-bot: Get API key from ~/.humbug-api-key
(imported from commit 63d63ad0d299c300d28de61069ada8ea2c8eb839)
This commit is contained in:
parent
11cdc959e6
commit
e42097a723
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import errno
|
||||
import datetime
|
||||
import optparse
|
||||
import urlparse
|
||||
|
@ -40,7 +42,7 @@ parser.add_option('--user',
|
|||
parser.add_option('--api-key',
|
||||
dest='api_key',
|
||||
action='store',
|
||||
help='API key for that user')
|
||||
help='API key for that user [default: read ~/.humbug-api-key]')
|
||||
parser.add_option('--calendar',
|
||||
dest='calendar',
|
||||
action='store',
|
||||
|
@ -62,6 +64,14 @@ parser.add_option('--interval',
|
|||
|
||||
(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):
|
||||
parser.error('You must specify --user, --api-key, and --calendar')
|
||||
|
||||
|
|
Loading…
Reference in a new issue