Skip to content
Snippets Groups Projects
Commit 44b99489 authored by Daniel Neuwirth's avatar Daniel Neuwirth
Browse files

bugfix tools

parent eacfec42
No related branches found
No related tags found
No related merge requests found
...@@ -13,20 +13,31 @@ def add_attributes_resources(context, resource): ...@@ -13,20 +13,31 @@ def add_attributes_resources(context, resource):
for item in resources: for item in resources:
if item.get('id') == resource.get('id'): if item.get('id') == resource.get('id'):
path = get_filepath_to_resource(resource) path = get_filepath_to_resource(resource)
if os.path.exists(path):
with open(path, 'rb') as file: with open(path, 'rb') as file:
#size
if not item.get('size'): if not item.get('size'):
resource_size = os.path.getsize(path) resource_size = os.path.getsize(path)
item.update({'size': resource_size}) item.update({'size': resource_size})
#hash
file.seek(0) file.seek(0)
hash = calculate_hash(file) hash = calculate_hash(file)
item.update({'hash':hash}) item.update({'hash':hash})
#hash algorithm
item.update({'hash_algorithm': 'http://dcat-ap.de/def/hashAlgorithms/md/5'})
#number of pages
file_type = magic.from_file(path, mime = True) file_type = magic.from_file(path, mime = True)
if file_type == 'application/pdf': if file_type == 'application/pdf':
file.seek(0) file.seek(0)
pdf = pdftotext.PDF(file) pdf = pdftotext.PDF(file)
number_of_pages = len(pdf) number_of_pages = len(pdf)
item.update({'number_of_pages':number_of_pages}) item.update({'number_of_pages':number_of_pages})
item.update({'hash_algorithm': 'http://dcat-ap.de/def/hashAlgorithms/md/5'})
resources[i] = item resources[i] = item
break break
i = i + 1 i = i + 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment