Skip to content

Commit

Permalink
added filesize and date to content view #48
Browse files Browse the repository at this point in the history
  • Loading branch information
FlatErikk committed Apr 9, 2024
1 parent 06adccc commit 3643c5a
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions framework/climate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,30 @@
from .search_es import (ClimateCollectionSearch, ClimateDatasetsCollectionIndex, ClimateDatasetsIndex, ClimateIndicatorIndex, ClimateSearch, ClimateIndicatorSearch)
from .serializer import ClimateLayerSerializer

import xarray as xr
import cf_xarray as cfxr
from datetime import datetime

# import xarray as xr
# import cf_xarray as cfxr
import tarfile
import pwd
import grp

import xclim.indices
# import xclim.indices
from xclim import testing



#URLTXTFILES_DIR = os.path.join(settings.STATICFILES_DIRS[0], 'urltxtfiles')
# URLTXTFILES_DIR = os.path.join(settings.STATICFILES_DIRS[0], 'urltxtfiles')
URLTXTFILES_DIR = "/opt/rbis/www/tippecc_data/tmp/"
TESTCONTENT_DIR = "/opt/rbis/www/tippecc_data/tmp/water_budget"

GENERAL_API_URL = 'https://leutra.geogr.uni-jena.de/backend_geoportal/'
FORBIDDEN_CHARACTERS = ['/', '\\', '.', '-', ':', '@', '&', '^', '>', '<', '~', '$']
HASH_LENGTH = 32


# mainly for the wget request, returns a txt file with urls (to download) based on the
# request parameter 'hash'
# request parameter 'hash'
class TextFileView(APIView):
def get(self, request):
hash_param = request.GET.get('hash', default=None)
Expand Down Expand Up @@ -110,12 +113,29 @@ class ContentView(APIView):
def get(self, request):
foldercontent = os.listdir(TESTCONTENT_DIR)

# custom code to filter foldercontent (if really needed) --> here
# ...
dir_content = []

for i, f in enumerate(foldercontent):
full_filename = TESTCONTENT_DIR + '/' + f
file_stats = os.stat(full_filename)

dir_content_element = []
dir_content_element.append(f)
dir_content_element.append(str(file_stats.st_size / (1024 * 1024)) + " MB")
creation_date = None

try:
# other OS
creation_date = file_stats.st_birthtime
except AttributeError:
# We're probably on Linux. No easy way to get creation dates here,
# so we'll settle for when its content was last modified.
creation_date = datetime.fromtimestamp(file_stats.st_mtime).strftime('%Y-%m-%d %H:%M')

print(foldercontent)
dir_content_element.append(creation_date)
dir_content.append(dir_content_element)

response = JsonResponse({'content': foldercontent})
response = JsonResponse({'content': dir_content})
return response


Expand Down

0 comments on commit 3643c5a

Please sign in to comment.