mirror of
https://github.com/ilri/dspace-statistics-api.git
synced 2024-11-21 22:05:02 +01:00
Correct issues highlighted by Flake8
Flake8 validates code style against PEP 8 in order to encourage the writing of idiomatic Python. For reference, I am currently ignoring errors about line length (E501) because I feel it makes code harder to read. This is the invocation I am using: $ flake8 --ignore E501 dspace_statistics_api
This commit is contained in:
parent
70dfcb93c5
commit
cc5ce3ab98
@ -4,6 +4,7 @@ import falcon
|
||||
db = database_connection()
|
||||
db.set_session(readonly=True)
|
||||
|
||||
|
||||
class RootResource:
|
||||
def on_get(self, req, resp):
|
||||
resp.status = falcon.HTTP_200
|
||||
@ -11,6 +12,7 @@ class RootResource:
|
||||
with open('dspace_statistics_api/docs/index.html', 'r') as f:
|
||||
resp.body = f.read()
|
||||
|
||||
|
||||
class AllItemsResource:
|
||||
def on_get(self, req, resp):
|
||||
"""Handles GET requests"""
|
||||
@ -46,6 +48,7 @@ class AllItemsResource:
|
||||
|
||||
resp.media = message
|
||||
|
||||
|
||||
class ItemResource:
|
||||
def on_get(self, req, resp, item_id):
|
||||
"""Handles GET requests"""
|
||||
@ -70,6 +73,7 @@ class ItemResource:
|
||||
|
||||
cursor.close()
|
||||
|
||||
|
||||
api = application = falcon.API()
|
||||
api.add_route('/', RootResource())
|
||||
api.add_route('/items', AllItemsResource())
|
||||
|
@ -3,7 +3,9 @@ from .config import DATABASE_USER
|
||||
from .config import DATABASE_PASS
|
||||
from .config import DATABASE_HOST
|
||||
from .config import DATABASE_PORT
|
||||
import psycopg2, psycopg2.extras
|
||||
import psycopg2
|
||||
import psycopg2.extras
|
||||
|
||||
|
||||
def database_connection():
|
||||
connection = psycopg2.connect("dbname={} user={} password={} host={} port={}".format(DATABASE_NAME, DATABASE_USER, DATABASE_PASS, DATABASE_HOST, DATABASE_PORT), cursor_factory=psycopg2.extras.DictCursor)
|
||||
|
@ -34,6 +34,7 @@ import json
|
||||
import psycopg2.extras
|
||||
from .solr import solr_connection
|
||||
|
||||
|
||||
def index_views():
|
||||
# get total number of distinct facets for items with a minimum of 1 view,
|
||||
# otherwise Solr returns all kinds of weird ids that are actually not in
|
||||
@ -98,6 +99,7 @@ def index_views():
|
||||
|
||||
cursor.close()
|
||||
|
||||
|
||||
def index_downloads():
|
||||
# get the total number of distinct facets for items with at least 1 download
|
||||
res = solr.query('statistics', {
|
||||
@ -157,6 +159,7 @@ def index_downloads():
|
||||
|
||||
cursor.close()
|
||||
|
||||
|
||||
db = database_connection()
|
||||
solr = solr_connection()
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
from .config import SOLR_SERVER
|
||||
from SolrClient import SolrClient
|
||||
|
||||
|
||||
def solr_connection():
|
||||
connection = SolrClient(SOLR_SERVER)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user