...
HTML |
---|
<script type="text/javascript" src="js/jquery.ajax-cross-origin.min.js"></script> <script type="text/javascript"> var urlApiKey = 'https://api.ecmwf.int/v1/key/'; var API_FILENAME = '.ecmwfapirc'; $(function() { getApiInfo(function(apiInfo){ AJS.$('#apiKey').append('<h4> 1. (Recommended) Save your API key credentials into a file</h4>' + apiInfo.apiKey + '<br \>'); AJS.$('#envVars').append(typeof apiInfo.envVars=='undefined' ? '' : ' 2. Environment variables' + apiInfo.envVars + '<br \>'); AJS.$('#objServer').append(typeof apiInfo.objServer=='undefined' ? '' : ' 3. Include this information in your Python script when creating the ECMWFDataServer/ECMWFService Object' + apiInfo.objServer); }); }); function getApiInfo(obj) { AJS.$.ajax({ crossOrigin: true, url: urlApiKey, data: {format: 'json'}, method: 'get', xhrFields: { withCredentials: true } }).done(function(json){ obj({ 'apiKey':'<p>Copy / paste the text below into a blank text file and save it to your $HOME directory as <b>' + API_FILENAME + '</b> (If you use Windows, you have to put the file in C:\\Users\\<USERNAME>\\.ecmwfapirc ; see <a href="https://gist.github.com/ozh/4131243">how to create a file with a leading dot</a>.)</p><pre><code>' + JSON.stringify(json, null, ' ') + '</code></pre>', 'envVars':'<p>Set these environment variables before executing the Python script:</p><pre><code>export ECMWF_API_URL="' + json.url + '"\nexport ECMWF_API_KEY="' + json.key + '"\nexport ECMWF_API_EMAIL="' + json.email + '"</code></pre>', 'objServer':'<pre><code>server = ECMWFDataServer(url="' + json.url + '",key="' + json.key + '",email="' + json.email + '")\n#or\nserver = ECMWFService("mars", url="' + json.url + '",key="' + json.key + '",email="' + json.email + '")</code></pre>' }); }).fail(function(jqXHR, textStatus){ console.error('Request failed: ' + textStatus); obj({ 'apiKey':'<p style="color:red"><b>Your API key information is not available.</b></p><ul><li>If you are not logged in, please log in to <a href="https://www.ecmwf.int">www.ecmwf.int</a> first.</li><li>If you are logged in, please <a href="https://www.ecmwf.int/en/about/contact-us">let our Service Desk know</a> that ' + window.location.href + ' is not working as expected. Please provide us with your username and screenshots or error messages if possible so that we can investigate and fix the problem.</li></ul><p>We apologise for any inconvenience.</p>' }); //TODO: could send back empty string for envVars and objServer? }); } </script> <style> pre { background-color: #eff0f1; padding: 1em; } </style> <br /> <div id="apiKey"></div> <div id="envVars"></div> <div id="objServer"></div> |
...