2018-09-18 13:03:15 +02:00
|
|
|
# Tested with Python 3.6
|
|
|
|
# See DSpace Solr docs for tips about parameters
|
|
|
|
# https://wiki.duraspace.org/display/DSPACE/Solr
|
|
|
|
|
2018-09-23 23:00:05 +02:00
|
|
|
from database import database_connection_ro
|
2018-09-18 13:03:15 +02:00
|
|
|
import falcon
|
2018-09-23 12:24:30 +02:00
|
|
|
from solr import solr_connection
|
2018-09-18 13:03:15 +02:00
|
|
|
|
2018-09-23 23:00:05 +02:00
|
|
|
db = database_connection_ro()
|
2018-09-23 15:47:00 +02:00
|
|
|
solr = solr_connection()
|
2018-09-18 13:03:15 +02:00
|
|
|
|
|
|
|
class ItemResource:
|
2018-09-23 15:23:33 +02:00
|
|
|
def on_get(self, req, resp, item_id):
|
2018-09-18 13:03:15 +02:00
|
|
|
"""Handles GET requests"""
|
|
|
|
|
2018-09-23 15:47:00 +02:00
|
|
|
cursor = db.cursor()
|
2018-09-24 13:28:00 +02:00
|
|
|
cursor.execute('SELECT views, downloads FROM items WHERE id={0}'.format(item_id))
|
|
|
|
results = cursor.fetchone()
|
2018-09-23 15:47:00 +02:00
|
|
|
cursor.close()
|
2018-09-18 13:03:15 +02:00
|
|
|
|
|
|
|
statistics = {
|
|
|
|
'id': item_id,
|
2018-09-24 13:28:00 +02:00
|
|
|
'views': results['views'],
|
|
|
|
'downloads': results['downloads']
|
2018-09-18 13:03:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resp.media = statistics
|
|
|
|
|
|
|
|
api = falcon.API()
|
2018-09-23 15:23:33 +02:00
|
|
|
api.add_route('/item/{item_id:int}', ItemResource())
|
2018-09-23 10:33:26 +02:00
|
|
|
|
|
|
|
# vim: set sw=4 ts=4 expandtab:
|