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:
parent
5b5cab8b34
commit
06ab254017
12
app.py
12
app.py
@ -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)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user