diff --git a/dspace_statistics_api/app.py b/dspace_statistics_api/app.py index a6e59a6..43e81c2 100644 --- a/dspace_statistics_api/app.py +++ b/dspace_statistics_api/app.py @@ -1,4 +1,5 @@ import falcon +import psycopg2.extras from .database import DatabaseManager from .items import get_downloads, get_views @@ -120,8 +121,6 @@ class ItemResource: def on_get(self, req, resp, item_id): """Handles GET requests""" - import psycopg2.extras - # Adapt Python’s uuid.UUID type to PostgreSQL’s uuid # See: https://www.psycopg.org/docs/extras.html psycopg2.extras.register_uuid() diff --git a/dspace_statistics_api/items.py b/dspace_statistics_api/items.py index 3501873..c35790d 100644 --- a/dspace_statistics_api/items.py +++ b/dspace_statistics_api/items.py @@ -1,6 +1,7 @@ import requests from .config import SOLR_SERVER +from .util import get_statistics_shards def get_views(solr_date_string: str, items: list): @@ -11,7 +12,6 @@ def get_views(solr_date_string: str, items: list): :parameter items (list): a list of item IDs :returns: A dict of item IDs and views """ - from .util import get_statistics_shards shards = get_statistics_shards() # Join the UUIDs with "OR" and escape the hyphens for Solr @@ -62,7 +62,6 @@ def get_downloads(solr_date_string: str, items: list): :parameter items (list): a list of item IDs :returns: A dict of item IDs and downloads """ - from .util import get_statistics_shards shards = get_statistics_shards() # Join the UUIDs with "OR" and escape the hyphens for Solr diff --git a/dspace_statistics_api/util.py b/dspace_statistics_api/util.py index 0ea099a..8c51ca5 100644 --- a/dspace_statistics_api/util.py +++ b/dspace_statistics_api/util.py @@ -1,4 +1,11 @@ +import datetime +import json +import re + import falcon +import requests + +from .config import SOLR_SERVER def get_statistics_shards(): @@ -8,11 +15,6 @@ def get_statistics_shards(): Returns: str:A list of Solr statistics shards separated by commas. """ - import re - - import requests - - from .config import SOLR_SERVER # Initialize an empty list for statistics core years statistics_core_years = [] @@ -58,7 +60,6 @@ def get_statistics_shards(): def is_valid_date(date): - import datetime try: # Solr date format is: 2020-01-01T00:00:00Z @@ -78,7 +79,6 @@ def validate_items_post_parameters(req, resp, resource, params): Meant to be used as a `before` hook. """ - import json # Only attempt to read the POSTed request if its length is not 0 (or # rather, in the Python sense, if length is not a False-y value).