1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2024-12-22 12:42:19 +01:00

Refactor configuration into separate module

There is a good example of this in the Project Weekend GitHub profile.

See: https://github.com/projectweekend/Falcon-PostgreSQL-API-Seed
This commit is contained in:
Alan Orth 2018-09-18 16:59:28 +03:00
parent 5b5cab8b34
commit 06ab254017
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9
2 changed files with 10 additions and 7 deletions

12
app.py
View File

@ -2,13 +2,11 @@
# See DSpace Solr docs for tips about parameters
# https://wiki.duraspace.org/display/DSPACE/Solr
from config import SOLR_SERVER
from config import SOLR_CORE
import falcon
import os
from SolrClient import SolrClient
# Check if Solr connection information was provided in the environment
solr_server = os.environ.get('SOLR_SERVER', 'http://localhost:8080/solr')
solr_core = os.environ.get('SOLR_CORE', 'statistics')
class ItemResource:
def on_get(self, req, resp):
@ -16,10 +14,10 @@ class ItemResource:
# Return HTTPBadRequest if id parameter is not present and valid
item_id = req.get_param_as_int("id", required=True, min=0)
solr = SolrClient(solr_server)
solr = SolrClient(SOLR_SERVER)
# Get views
res = solr.query(solr_core, {
res = solr.query(SOLR_CORE, {
'q':'type:0',
'fq':'owningItem:{0} AND isBot:false AND statistics_type:view AND -bundleName:ORIGINAL'.format(item_id)
})
@ -27,7 +25,7 @@ class ItemResource:
views = res.get_num_found()
# Get downloads
res = solr.query(solr_core, {
res = solr.query(SOLR_CORE, {
'q':'type:0',
'fq':'owningItem:{0} AND isBot:false AND statistics_type:view AND -(bundleName:[* TO *] -bundleName:ORIGINAL)'.format(item_id)
})

5
config.py Normal file
View File

@ -0,0 +1,5 @@
import os
# Check if Solr connection information was provided in the environment
SOLR_SERVER = os.environ.get('SOLR_SERVER', 'http://localhost:8080/solr')
SOLR_CORE = os.environ.get('SOLR_CORE', 'statistics')