-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46f6cb6
commit b194b0a
Showing
15 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.pyc | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from getenv import env | ||
import drest | ||
|
||
class MetpetAPI(): | ||
def __init__(self, user, api): | ||
self.username = user | ||
self.api_key = api | ||
self.api = drest.api.TastyPieAPI('{0}/api/v1/'.format(env('API_HOST'))) | ||
if self.username: | ||
self.api.auth(user, api) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,54 @@ | ||
from flask import Flask | ||
import ast | ||
import urllib | ||
import json | ||
from flask import Flask, request, render_template, url_for | ||
import dotenv | ||
import drest | ||
|
||
from api import MetpetAPI | ||
from utilities import paginate_model | ||
|
||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/') | ||
def index(): | ||
return render_template('index.html') | ||
|
||
@app.route('/samples') | ||
def samples(): | ||
api = MetpetAPI(None, None).api | ||
|
||
filters = ast.literal_eval(json.dumps(request.args)) | ||
offset = request.args.get('offset', 0) | ||
filters['offset'] = offset | ||
data = api.sample.get(params=filters) | ||
|
||
next, previous, last, total_count = paginate_model('samples', data, filters) | ||
|
||
samples = data.data['objects'] | ||
for sample in samples: | ||
mineral_names = [mineral['name'] for mineral in sample['minerals']] | ||
sample['mineral_list'] = (', ').join(mineral_names) | ||
|
||
first_page_filters = filters | ||
del first_page_filters['offset'] | ||
|
||
if filters: | ||
first_page_url = url_for('samples') + '?' + urllib.urlencode(first_page_filters) | ||
else: | ||
first_page_url = url_for('samples') + urllib.urlencode(first_page_filters) | ||
|
||
return render_template('samples.html', | ||
samples=samples, | ||
next_url=next, | ||
prev_url=previous, | ||
total=total_count, | ||
first_page=first_page_url, | ||
last_page=last) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
dotenv.read_dotenv('../app_variables.env') | ||
app.run(debug=True) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.