Skip to content

Commit 9a1c1be

Browse files
committed
added Python-Eve nobel_viz/api
1 parent 633c782 commit 9a1c1be

File tree

9 files changed

+68
-1
lines changed

9 files changed

+68
-1
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The MIT License (MIT)
1+
jhe MIT License (MIT)
22

33
Copyright (c) 2016 Kyran Dale
44

api/.#seed_database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kyran@tweedledee.10344:1470234479

api/Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: python server_eve.py
2+
seed: python seed_database.py

api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

api/data/nobel_winners_biopic.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

api/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Eve==0.6.1

api/seed_database.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from __future__ import print_function
2+
import json
3+
from pymongo import MongoClient
4+
from settings import MONGO_URI
5+
6+
WINNERS = 'winners'
7+
8+
winners = json.load(open('data/nobel_winners_biopic.json'))
9+
mc = MongoClient(MONGO_URI)
10+
db = mc.get_default_database()
11+
12+
db[WINNERS].drop()
13+
db[WINNERS].insert(winners)
14+
15+
print('Seeded the database with %d Nobel winners'%db.winners.count())

api/server_eve.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from eve import Eve
2+
import os
3+
4+
# some heroku-specific options
5+
if 'PORT' in os.environ:
6+
port = int(os.environ.get('PORT'))
7+
# use '0.0.0.0' to ensure your REST API is reachable from all your
8+
# network (and not only your computer).
9+
host = '0.0.0.0'
10+
else:
11+
port = 5000
12+
host = '127.0.0.1'
13+
14+
app = Eve()
15+
16+
if __name__=='__main__':
17+
# port = int(os.environ.get('PORT', 5000))
18+
app.run(host=host, port=port, debug=True)

api/settings.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Let's just use the local mongod instance. Edit as needed.
2+
3+
# Please note that MONGO_HOST and MONGO_PORT could very well be left
4+
# out as they already default to a bare bones local 'mongod' instance.
5+
import os
6+
7+
# We want to seamlessy run our API both locally and on Heroku. If running on
8+
# Heroku, sensible DB connection settings are stored in environment variable MONGODB_URI
9+
MONGO_URI = os.environ.get('MONGODB_URI', 'mongodb://localhost:27017/nobel_prize')
10+
#MONGO_DBNAME = 'nobel_prize'
11+
X_DOMAINS = '*'
12+
HATEOAS = False
13+
PAGINATION = False
14+
15+
URL_PREFIX = 'api'
16+
DOMAIN = {'winners_full':{
17+
'item_title': 'winners',
18+
'schema':{
19+
'country':{'type':'string'},
20+
'category':{'type':'string'},
21+
'name':{'type':'string'},
22+
'year':{'type': 'integer'},
23+
'gender':{'type':'string'},
24+
'mini_bio':{'type':'string'},
25+
'bio_image':{'type':'string'}
26+
},
27+
'url':'winners'
28+
}}

0 commit comments

Comments
 (0)