Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

bit.ly api key in separate file

Mike McGanna151c3b12a42
diff --git a/.gitignore b/.gitignore
index dcc60c6fe..614ac077b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,7 +3,8 @@ dist
node_modules
.project
.settings
-.pydevprioject
+.pydevproject
.DS_Store
+bitly_config.py*
*~
*.swp
diff --git a/conf/bitly_config.sample.py b/conf/bitly_config.sample.py
new file mode 100644
index 000000000..5b476d7bf
--- /dev/null
+++ b/conf/bitly_config.sample.py
@@ -0,0 +1,13 @@
+#
+# NASA Worldview
+#
+# This code was originally developed at NASA/Goddard Space Flight Center for
+# the Earth Science Data and Information System (ESDIS) project.
+#
+# Copyright (C) 2013 - 2014 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+#
+
+login = "username"
+api_key = "key"
diff --git a/src/service/wv.link/shorten.cgi b/src/service/wv.link/shorten.cgi
index c4c3d8be6..52c8ee69f 100755
--- a/src/service/wv.link/shorten.cgi
+++ b/src/service/wv.link/shorten.cgi
@@ -19,8 +19,6 @@ import sys
from urllib2 import Request, urlopen, HTTPError, quote
endpoint = "http://api.bit.ly/v3/shorten"
-login = "mikemcgann"
-api_key = "R_ec77065b0261e49752dcd6ca2f3ee1a2"
class RequestError(Exception):
@@ -96,9 +94,9 @@ def service_unavailable(options, info=None):
- info: Additional information to display to the user if options.error
is True
"""
+ print options
handle_error(503, "Service Unavailable", options, info)
-
def process_request(options):
fields = cgi.FieldStorage()
@@ -112,8 +110,8 @@ def process_request(options):
url = "".join([endpoint,
- "?login=" + login,
- "&apiKey=" + api_key,
+ "?login=" + bitly_config.login,
+ "&apiKey=" + bitly_config.api_key,
"&format=json",
"&longUrl=" + quote(fields["url"].value)])
@@ -161,7 +159,12 @@ if __name__ == '__main__':
"""
options = parse_options()
try:
+ sys.path.append(os.path.join("..", "..", "..", "conf"))
+ import bitly_config
process_request(options)
+ except ImportError:
+ options.error = True
+ service_unavailable(options, "No API key")
except RequestError as re:
bad_request(options, re)
except HTTPError as he: