def __init__(self, key=None, secret=None): # Initializes an urthecastAPI caller based on a user's passed secrets # or secrets stored in private dev.json and prod.json files self.data = None self.error_message = None self.key = key or runtime_config.get("urthecast_key") self.secret = secret or runtime_config.get("urthecast_secret")
def test___init__(self): self.uc = urthecast.Urthecast('fake_key','fake_secret') self.assertEqual(self.uc.key,'fake_key') self.assertEqual(self.uc.secret,'fake_secret') self.uc = urthecast.Urthecast() self.assertIsNone(self.uc.data) self.assertIsNone(self.uc.error_message) self.assertEqual(self.uc.key,runtime_config.get("urthecast_key")) self.assertEqual(self.uc.secret,runtime_config.get("urthecast_secret"))
def test___init__(self): self.uc = urthecast.Urthecast('fake_key', 'fake_secret') self.assertEqual(self.uc.key, 'fake_key') self.assertEqual(self.uc.secret, 'fake_secret') self.uc = urthecast.Urthecast() self.assertIsNone(self.uc.data) self.assertIsNone(self.uc.error_message) self.assertEqual(self.uc.key, runtime_config.get("urthecast_key")) self.assertEqual(self.uc.secret, runtime_config.get("urthecast_secret"))
def send(self): story_url = gfw_url('stories/%s' % self.story['id'], {}) response = sparkpost.transmissions.send( recipients=runtime_config.get('wri_emails_stories'), template='new-story-wri', substitution_data={'story_url': story_url}) logging.info("Send Story WRI Email Result: %s" % response)
def gfw_url(path, params={}): base_url = runtime_config.get('GFW_BASE_URL') url_parts = list(urlparse.urlparse(base_url)) url_parts[2] = urlparse.urljoin(url_parts[2], path) query = dict(urlparse.parse_qsl(url_parts[4])) query.update(params) url_parts[4] = urllib.urlencode(query) return urlparse.urlunparse(url_parts)
def execute(query, params={}, auth=False): """Exectues supplied query on CartoDB and returns response body as JSON.""" #import logging #logging.info(query) rpc = urlfetch.create_rpc(deadline=50) payload = get_body(query, params, auth=auth) if runtime_config.get('IS_DEV'): logging.info(query) logging.info(payload) urlfetch.make_fetch_call(rpc, ENDPOINT, method='POST', payload=payload) return rpc.get_result()
def execute(query, params={}, auth=False): """Exectues supplied query on CartoDB and returns response body as JSON.""" #import logging #logging.info(query) rpc = urlfetch.create_rpc(deadline=50) payload = get_body(query, params, auth=auth) if runtime_config.get('IS_DEV'): logging.info(query) logging.info(payload) urlfetch.make_fetch_call(rpc, ENDPOINT, method='POST', payload=payload) return rpc.get_result()
def gfw_url(path, params={}): base_url = runtime_config.get('GFW_BASE_URL') url_parts = list(urlparse.urlparse(base_url)) url_parts[2] = urlparse.urljoin(url_parts[2], path) query = dict(urlparse.parse_qsl(url_parts[4])) query.update(params) url_parts[4] = urllib.urlencode(query) return urlparse.urlunparse(url_parts)
def _send_new_story_emails(self): story = self._get_params() # Email WRI: subject = 'A new story has been registered with Global Forest Watch' sender = \ 'Global Forest Watch Stories <*****@*****.**>' to = runtime_config.get('wri_emails_stories') story_url = '%s/stories/%s' % (runtime_config.get('GFW_BASE_URL'), story['id']) api_url = '%s/stories/%s' % (runtime_config.get('APP_BASE_URL'), story['id']) token = story['token'] body = 'Story URL: %s\nStory API: %s\nStory token: %s' % \ (story_url, api_url, token) mail.send_mail(sender=sender, to=to, subject=subject, body=body) # Email user: subject = 'Your story has been registered with Global Forest Watch!' to = '%s <%s>' % (story['name'], story['email']) body = 'Here is your story: %s' % story_url mail.send_mail(sender=sender, to=to, subject=subject, body=body)
def send(self): story_url = gfw_url('stories/%s' % self.story['id'], {}) response = sparkpost.transmissions.send( recipients=runtime_config.get('wri_emails_stories'), template='new-story-wri', substitution_data={ 'story_url': story_url } ) logging.info("Send Story WRI Email Result: %s" % response)
def _send_new_story_emails(self): story = self._get_params() # Email WRI: subject = 'A new story has been registered with Global Forest Watch' sender = \ 'Global Forest Watch Stories <*****@*****.**>' to = runtime_config.get('wri_emails_stories') story_url = '%s/stories/%s' % (runtime_config.get('GFW_BASE_URL'), story['id']) api_url = '%s/stories/%s' % (runtime_config.get('APP_BASE_URL'), story['id']) token = story['token'] body = 'Story URL: %s\nStory API: %s\nStory token: %s' % \ (story_url, api_url, token) mail.send_mail(sender=sender, to=to, subject=subject, body=body) # Email user: subject = 'Your story has been registered with Global Forest Watch!' to = '%s <%s>' % (story['name'], story['email']) body = 'Here is your story: %s' % story_url mail.send_mail(sender=sender, to=to, subject=subject, body=body)
def dispatch(self): basic_auth = self.request.headers.get('Authorization') if not basic_auth: logging.debug("Request does not carry auth.") self.response.set_status(401, 'Unauthorised') self.response.headers['WWW-Authenticate'] = 'Basic realm="secure"' return self.response.out.write('Unauthorised') try: user_info = base64.decodestring(basic_auth[6:]) username, password = user_info.split(':') if username == config.get('migration_user') and \ password == config.get('migration_password'): return webapp2.RequestHandler.dispatch(self) else: return self.write_error(401, 'Unauthorised') except Exception as e: print "error" print e return self.write_error(401, 'Unauthorised')
def site(self): try: params = self._get_params() rid = self._get_id(params) entry = Entry.get_by_id(rid) if not entry or params.get('bust') or runtime_config.get('IS_DEV'): site = wdpa.get_site(params) if site: entry = Entry(id=rid, value=json.dumps(site)) entry.put() self._send_response(entry.value if entry else None) except Exception, e: name = e.__class__.__name__ msg = 'Error: WPDA API (%s)' % name monitor.log(self.request.url, msg, error=e, headers=self.request.headers)
def site(self): try: params = self._get_params() rid = self._get_id(params) entry = Entry.get_by_id(rid) if not entry or params.get('bust') or runtime_config.get('IS_DEV'): site = wdpa.get_site(params) if site: entry = Entry(id=rid, value=json.dumps(site)) entry.put() self._send_response(entry.value if entry else None) except Exception, e: name = e.__class__.__name__ msg = 'Error: WPDA API (%s)' % name monitor.log(self.request.url, msg, error=e, headers=self.request.headers)
def get(self): try: params = self._get_params() rid = self._get_id(params) if 'interval' not in params: params['interval'] = '12 MONTHS' entry = Entry.get_by_id(rid) if not entry or params.get('bust') or runtime_config.get('IS_DEV'): result = countries.get(params) if result: entry = Entry(id=rid, value=json.dumps(result)) entry.put() self._send_response(entry.value if entry else None) except Exception, e: name = e.__class__.__name__ msg = 'Error: Countries API (%s)' % name monitor.log(self.request.url, msg, error=e, headers=self.request.headers)
def get_url(query, params, auth=False): """Return CartoDB query URL for supplied params.""" params = copy.copy(params) params['q'] = query if auth: params['api_key'] = _get_api_key() clean_params = {} for key, value in params.iteritems(): if key in ['api_key', 'format', 'q', 'version']: clean_params[key] = value url = '%s?%s' % (ENDPOINT, urllib.urlencode(clean_params)) # TODO: Hack if 'version' in clean_params: url = url.replace('v2', clean_params['version']) if runtime_config.get('IS_DEV'): logging.info(url) return str(url)
def get_url(query, params, auth=False): """Return CartoDB query URL for supplied params.""" params = copy.copy(params) params['q'] = query if auth: params['api_key'] = _get_api_key() clean_params = {} for key, value in params.iteritems(): if key in ['api_key', 'format', 'q', 'version']: clean_params[key] = value url = '%s?%s' % (ENDPOINT, urllib.urlencode(clean_params)) # TODO: Hack if 'version' in clean_params: url = url.replace('v2', clean_params['version']) if runtime_config.get('IS_DEV'): logging.info(url) return str(url)
def get(self): try: params = self._get_params() rid = self._get_id(params) if 'interval' not in params: params['interval'] = '12 MONTHS' entry = Entry.get_by_id(rid) if not entry or params.get('bust') or runtime_config.get('IS_DEV'): result = countries.get(params) if result: entry = Entry(id=rid, value=json.dumps(result)) entry.put() self._send_response(entry.value if entry else None) except Exception, error: name = error.__class__.__name__ trace = traceback.format_exc() msg = 'Publish failure: %s: %s' % \ (name, error) monitor.log(self.request.url, msg, error=trace, headers=self.request.headers)
def update_subscriptions(self, user): for i, subscription_key in enumerate(self.subscriptions): subscription = subscription_key.get() if subscription.topic in IGNORED_TOPICS: continue subscription.user_id = user.key subscription.confirmed = True if subscription.topic not in ALLOWED_TOPICS: subscription.topic = 'alerts/treeloss' subscription.params['topic'] = 'alerts/treeloss' subscription.params = subscription.params or {} subscription.params['tab'] = 'analysis-tab' subscription.url = runtime_config.get('GFW_BASE_URL') + \ gfw_map_url(subscription.params) subscription.put()
def get(self): try: params = self._get_params() rid = self._get_id(params) if 'interval' not in params: params['interval'] = '12 MONTHS' entry = Entry.get_by_id(rid) if not entry or params.get('bust') or runtime_config.get('IS_DEV'): result = countries.get(params) if result: entry = Entry(id=rid, value=json.dumps(result)) entry.put() self._send_response(entry.value if entry else None) except Exception, error: name = error.__class__.__name__ trace = traceback.format_exc() msg = 'Publish failure: %s: %s' % \ (name, error) monitor.log(self.request.url, msg, error=trace, headers=self.request.headers)
def update_subscriptions(self, user): for i, subscription_key in enumerate(self.subscriptions): subscription = subscription_key.get() if subscription.topic in IGNORED_TOPICS: continue subscription.user_id = user.key subscription.confirmed = True if subscription.topic not in ALLOWED_TOPICS: subscription.topic = 'alerts/treeloss' subscription.params['topic'] = 'alerts/treeloss' subscription.params = subscription.params or {} subscription.params['tab'] = 'analysis-tab' subscription.url = runtime_config.get('GFW_BASE_URL') + \ gfw_map_url(subscription.params) subscription.put()
def send_migration_email(migration): print "#####" print "Sending migration {0} for {1}".format(migration.key.urlsafe(), migration.email) migration_url = '%s/v2/migrations/%s/migrate' % \ (runtime_config['APP_BASE_URL'], str(migration.key.urlsafe())) template_content = [] message = { 'global_merge_vars': [{ 'content': migration_url, 'name': 'migration_link' }], 'to': [{ 'email': migration.email, 'name': migration.email, 'type': 'to' }], 'track_clicks': True, 'merge_language': 'handlebars', 'track_opens': True } mandrill_key = runtime_config.get('mandrill_api_key') mandrill_url = "https://mandrillapp.com/api/1.0/messages/send-template.json" payload = { "template_content": [], "template_name": 'subscription-migration', "message": message, "key": mandrill_key, "async": "false" } result = urlfetch.fetch(mandrill_url, payload=json.dumps(payload), method=urlfetch.POST, headers={'Content-Type': 'application/json'}) print "Sent!" print result
# # SHARED CONSTANTS/TEMPLATES # ALLOWED_DOMAINS = [ 'api-gateway-staging.globalforestwatch.org', 'www.globalforestwatch.org', 'globalforestwatch.org', 'staging.globalforestwatch.org', 'localhost:5000' 'fires.globalforestwatch.org', 'www.fires.globalforestwatch.org', 'commodities.globalforestwatch.org', 'www.commodities.globalforestwatch.org' 'climate.globalforestwatch.org', 'www.climate.globalforestwatch.org', 'data.globalforestwatch.org', 'www.data.globalforestwatch.org', 'developers.globalforestwatch.org', 'www.developers.globalforestwatch.org', 'blog.globalforestwatch.org', 'www.blog.globalforestwatch.org' ] APP_VERSION = runtime_config.get('APP_VERSION') APP_BASE_URL = runtime_config.get('APP_BASE_URL') IS_DEV = runtime_config.get('IS_DEV') CONTENT_TYPES = { 'shp': 'application/octet-stream', 'kml': 'application/vnd.google-earth.kmz', 'svg': 'image/svg+xml', 'csv': 'application/csv', 'geojson': 'application/json', 'json': 'application/json' } GCS_URL_TMPL = 'http://storage.googleapis.com/gfw-apis-analysis%s.%s' def gfw_url(path, params={}): base_url = runtime_config.get('GFW_BASE_URL')
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import logging from appengine_config import runtime_config from sparkpost import SparkPost sparkpost = SparkPost(runtime_config.get('sparkpost_api_key') or 'sparkpostapikey') class ContactFormMailer: def __init__(self, email): self.email = email def send(self): if self.email.opt_in == True: opt_in = 'Yes' else: opt_in = 'No' response = sparkpost.transmissions.send( recipients=[{'address': self.email.email_for_topic()}], template='contact-form', substitution_data={
from appengine_config import runtime_config def _load_asset_ids(): """Return private EE asset ids as dictionary.""" path = os.path.join(os.path.abspath( os.path.dirname(__file__)), 'ee_asset_ids.json') try: return json.loads(open(path, "r").read()) except: return {} # The URL of the Earth Engine API. EE_URL = 'https://earthengine.googleapis.com' # The service account email address authorized by your Google contact. EE_ACCOUNT = runtime_config.get('EE_ACCOUNT') #'*****@*****.**' # The private key associated with your service account in Privacy Enhanced # Email format (.pem suffix). To convert a private key from the RSA format # (.p12 suffix) to .pem, run the openssl command like this: # openssl pkcs12 -in downloaded-privatekey.p12 -nodes -nocerts > privatekey.pem EE_PRIVATE_KEY_FILE = 'privatekey.pem' # DEBUG_MODE will be True if running in a local development environment. DEBUG_MODE = ('SERVER_SOFTWARE' in os.environ and os.environ['SERVER_SOFTWARE'].startswith('Dev')) # Set up the appropriate credentials depending on where we're running. if DEBUG_MODE: EE_CREDENTIALS = ee.ServiceAccountCredentials(
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """This module supports stories.""" import json from appengine_config import runtime_config from gfw import cdb import datetime TABLE = 'stories_dev_copy' if runtime_config.get('IS_DEV') else 'community_stories' INSERT = """INSERT INTO {table} (details, email, name, title, token, visible, date, location, the_geom, media) VALUES ('{details}', '{email}', '{name}', '{title}', '{token}', {visible}::boolean, '{date}'::date, '{location}', ST_SetSRID(ST_GeomFromGeoJSON('{geom}'), 4326), '{media}') RETURNING details, email, name, title, visible, date, location, cartodb_id as id, media, ST_AsGeoJSON(the_geom) as the_geom""" LIST = """SELECT details, email, name, title, visible, date, location, cartodb_id as id, ST_Y(the_geom) AS lat, ST_X(the_geom) AS lng,
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """This module supports executing CartoDB queries.""" import urllib from appengine_config import runtime_config from google.appengine.api import urlfetch # CartoDB endpoint: if runtime_config.get('cdb_endpoint'): ENDPOINT = runtime_config.get('cdb_endpoint') else: ENDPOINT = 'http://wri-01.cartodb.com/api/v2/sql' def _get_api_key(): """Return CartoDB API key stored in cdb.txt file.""" return runtime_config.get('cdb_api_key') def get_format(media_type): """Return CartoDB format for supplied GFW custorm media type.""" tokens = media_type.split('.') if len(tokens) == 2: return ''
except Exception, e: error = e name = error.__class__.__name__ trace = traceback.format_exc() if dataset == 'umd': msg = 'Earth Engine analysis failure: %s: %s' % \ (name, error) else: msg = 'CartoDB %s analysis failure: %s: %s' % \ (dataset, name, error) monitor.log(self.request.url, msg, error=trace, headers=self.request.headers) self._send_error() return if dataset == 'umd': value = json.dumps(response) AnalysisEntry(id=rid, value=value).put() self._send_response(value) else: result = _parse_analysis(dataset, response.content) value = json.dumps(result) AnalysisEntry(id=rid, value=value).put() self._send_response(value) routes = [webapp2.Route(_ROUTE, handler=Analysis)] handlers = webapp2.WSGIApplication(routes, debug=runtime_config.get('IS_DEV'))
import datetime # API import webapp2 import re import hashlib import base64 import monitor import random import traceback import copy from google.appengine.api import mail from google.appengine.api import taskqueue TABLE = 'stories_dev_copy' if runtime_config.get('IS_DEV') else 'community_stories' INSERT = """INSERT INTO {table} (details, email, name, title, token, visible, date, location, the_geom, media) VALUES ('{details}', '{email}', '{name}', '{title}', '{token}', {visible}::boolean, '{date}'::date, '{location}', ST_SetSRID(ST_GeomFromGeoJSON('{geom}'), 4326), '{media}') RETURNING details, email, name, title, visible, date, location, cartodb_id as id, media, ST_AsGeoJSON(the_geom) as the_geom""" LIST = """SELECT details, email, created_at, name, title, visible, date, location, cartodb_id as id, ST_Y(the_geom) AS lat, ST_X(the_geom) AS lng,
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """This module supports executing CartoDB queries.""" import copy import urllib import logging from appengine_config import runtime_config from google.appengine.api import urlfetch # CartoDB endpoint: if runtime_config.get('cdb_endpoint'): ENDPOINT = runtime_config.get('cdb_endpoint') else: ENDPOINT = 'http://wri-01.cartodb.com/api/v2/sql' def _get_api_key(): """Return CartoDB API key stored in cdb.txt file.""" return runtime_config.get('cdb_api_key') def get_format(media_type): """Return CartoDB format for supplied GFW custorm media type.""" tokens = media_type.split('.') if len(tokens) == 2: return ''
# # SHARED CONSTANTS/TEMPLATES # ALLOWED_DOMAINS = [ 'api-gateway-staging.globalforestwatch.org', 'www.globalforestwatch.org', 'globalforestwatch.org', 'staging.globalforestwatch.org', 'localhost:5000' 'fires.globalforestwatch.org', 'www.fires.globalforestwatch.org', 'commodities.globalforestwatch.org', 'www.commodities.globalforestwatch.org' 'climate.globalforestwatch.org', 'www.climate.globalforestwatch.org', 'data.globalforestwatch.org', 'www.data.globalforestwatch.org', 'developers.globalforestwatch.org', 'www.developers.globalforestwatch.org', 'blog.globalforestwatch.org', 'www.blog.globalforestwatch.org' ] APP_VERSION = runtime_config.get('APP_VERSION') APP_BASE_URL = runtime_config.get('APP_BASE_URL') IS_DEV = runtime_config.get('IS_DEV') CONTENT_TYPES = { 'shp': 'application/octet-stream', 'kml': 'application/vnd.google-earth.kmz', 'svg': 'image/svg+xml', 'csv': 'application/csv', 'geojson': 'application/json', 'json': 'application/json' } GCS_URL_TMPL = 'http://storage.googleapis.com/gfw-apis-analysis%s.%s' def gfw_url(path, params={}): base_url = runtime_config.get('GFW_BASE_URL')
def _get_api_key(): """Return CartoDB API key stored in cdb.txt file.""" return runtime_config.get('cdb_api_key')
class Monitor(webapp2.RequestHandler): def post(self): params = ['url', 'msg', 'error', 'headers'] url, msg, error, headers = map(self.request.get, params) headers = json.loads(headers) loc = headers.get('X-Appengine-Citylatlong', '0,0') vals = dict( url=url, msg=msg.replace("'", ''), country=headers.get('X-Appengine-Country'), region=headers.get('X-Appengine-Region'), city=headers.get('X-Appengine-City'), loc=loc) vals = json.dumps(vals, sort_keys=True, indent=4, separators=(',', ': ')) if error: logging.error('MONITOR: %s' % error) mail.send_mail( sender='*****@*****.**', to='*****@*****.**', subject='[GFW API ERROR] %s' % msg, body='Error: %s\n\n%s' % (error, vals)) else: logging.info('MONITOR: %s' % vals) routes = [webapp2.Route(r'/monitor', handler=Monitor, methods=['POST'])] handlers = webapp2.WSGIApplication(routes, debug=runtime_config.get('IS_DEV'))
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import urllib import json from gfw.models.topic import Topic from appengine_config import runtime_config BASE_PATH = '/map' BASE_URL = runtime_config.get('GFW_BASE_URL') ALLOWED_PARAMS = [ 'tab', 'geojson', 'geostore', 'wdpaid', 'begin', 'end', 'threshold', 'dont_analyze', 'hresolution', 'tour', 'subscribe', 'use', 'useid', 'fit_to_geom' ] def iso(params): iso = 'ALL' if params.get('iso'): iso = params.get('iso') if params.get('id1'): iso += '-' + str(params.get('id1'))
# API import webapp2 import re import hashlib import base64 import monitor import random import traceback import copy from google.appengine.api import mail from google.appengine.api import taskqueue from gfw.mailers.story import NewStoryWriMailer, NewStoryMailer TABLE = 'stories_dev_copy' if runtime_config.get( 'IS_DEV') else 'community_stories' INSERT = """INSERT INTO {table} (details, email, name, title, token, visible, date, location, the_geom, media) VALUES ('{details}', '{email}', '{name}', '{title}', '{token}', {visible}::boolean, '{date}'::date, '{location}', ST_SetSRID(ST_GeomFromGeoJSON('{geom}'), 4326), '{media}') RETURNING details, email, name, title, visible, date, location, cartodb_id as id, media, ST_AsGeoJSON(the_geom) as the_geom""" LIST = """SELECT details, email, created_at, name, title, visible, date, location, cartodb_id as id, ST_Y(the_geom) AS lat, ST_X(the_geom) AS lng, media FROM {table}
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import copy import json import datetime import logging from google.appengine.api import urlfetch from appengine_config import runtime_config from gfw.common import gfw_url from gfw.models.topic import Topic from gfw.lib.urls import map_url from sparkpost import SparkPost sparkpost = SparkPost(runtime_config.get('sparkpost_api_key') or 'sparkpostapikey') def summary_for_topic(topic): meta = topic.metadata lower_first = func = lambda s: s[:1].lower() + s[1:] if s else '' return meta['description'] + " at a " + meta['resolution'] + " resolution." \ " Coverage of " + meta['coverage'] + \ ". Source is " + meta['source'] + \ ". Available data from " + meta['timescale'] + ", updated " + \ lower_first(meta['updates']) def template_for_topic(topic): if topic.id == 'alerts/viirs': return 'fires-notification' else: return 'forest-change-notification'
self.redirect(data) elif action == "error": self.write_error(400, data.get("message") or data) else: self.write_error(400, "Unknown action %s" % action) def get_id(self, params): whitespace = re.compile(r"\s+") params = re.sub(whitespace, "", json.dumps(params, sort_keys=True)) return "/".join([self.request.path.lower(), md5(params).hexdigest()]) # # SHARED CONSTANTS/TEMPLATES # APP_VERSION = runtime_config.get("APP_VERSION") APP_BASE_URL = runtime_config.get("APP_BASE_URL") IS_DEV = runtime_config.get("IS_DEV") CONTENT_TYPES = { "shp": "application/octet-stream", "kml": "application/vnd.google-earth.kmz", "svg": "image/svg+xml", "csv": "application/csv", "geojson": "application/json", "json": "application/json", } GCS_URL_TMPL = "http://storage.googleapis.com/gfw-apis-analysis%s.%s" # # Helper Methods
def _get_api_key(): """Return CartoDB API key stored in cdb.txt file.""" return runtime_config.get('cdb_api_key')
def _load_asset_ids(): """Return private EE asset ids as dictionary.""" path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'ee_asset_ids.json') try: return json.loads(open(path, "r").read()) except: return {} # The URL of the Earth Engine API. EE_URL = 'https://earthengine.googleapis.com' # The service account email address authorized by your Google contact. EE_ACCOUNT = runtime_config.get('EE_ACCOUNT') #'*****@*****.**' # The private key associated with your service account in Privacy Enhanced # Email format (.pem suffix). To convert a private key from the RSA format # (.p12 suffix) to .pem, run the openssl command like this: # openssl pkcs12 -in downloaded-privatekey.p12 -nodes -nocerts > privatekey.pem EE_PRIVATE_KEY_FILE = 'privatekey.pem' # DEBUG_MODE will be True if running in a local development environment. DEBUG_MODE = ('SERVER_SOFTWARE' in os.environ and os.environ['SERVER_SOFTWARE'].startswith('Dev')) # Set up the appropriate credentials depending on where we're running. if DEBUG_MODE: EE_CREDENTIALS = ee.ServiceAccountCredentials(EE_ACCOUNT,