<jupyter_start><jupyter_text>Reading File Metadata with Tika This activity demonstrates reading file data using Tika via python. The activity makes use of the Tika Python library (https://github.com/chrismattmann/tika-python).<jupyter_code>try:
    import tika
    from tika import parser
except:
    print('didnt see tika')
    
file = '../assets/Bundle-web-files-small/image/13080t.jpg'

parsed = parser.from_file(file)
print(parsed['metadata'])
print(parsed['metadata']['Content-Type'])
import os
from os.path import join

dir_to_search = '../assets/Bundle-web-files-small/image'

file_list = os.listdir(dir_to_search)
print(file_list)
for img in file_list:
    parsed = parser.from_file(join(dir_to_search,img))
    print(img,':',parsed['metadata'])<jupyter_output>1005107061.tif : {'Bits Per Sample': '1 bits/component/pixel', 'Compression': 'T6/Group 4 Fax', 'Content-Type': 'image/tiff', 'File Modified Date': 'Sun Mar 03 23:24:44 -05:00 2019', 'File Name': 'apache-tika-6585281737342450742.tmp', 'File Size': '395734 bytes', 'Fill Order': 'Normal', 'Image Height': '3296 pixels', 'Image Width': '2544 pixels', 'New Subfile Type': 'Full-resolution image', 'Photometric Interpretation': 'WhiteIsZero', 'Resolution Unit': 'Inch', 'Rows Per Strip': '3296 rows/strip', 'Samples Per Pixel': '1 samples/pixel', 'Strip Byte Counts': '395500 bytes', 'Strip Offsets': '234', 'Thresholding': 'No dithering or halftoning', 'Unknown tag (0x0124)': '0', 'Unknown tag (0x0125)': '0', 'X Resolution': '300 dots per inch', 'X-Parsed-By': ['org.apache.tika.parser.DefaultParser', 'org.apache.tika.parser.image.TiffParser'], 'X-TIKA:parse_time_millis': '34', 'Y Resolution': '300 dots per inch', 'resourceName': '1005107061.tif', 'tiff:BitsPerSample': '1', 'tiff:ImageLength': '32[...]
{'fraction_non_alphanumeric': 0.16798196166854565, 'fraction_numerical': 0.06426155580608793, 'mean_word_length': 5.93359375, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '19577', 'license': 'MIT', 'n_tokens_mistral': 678, 'n_tokens_neox': 601, 'n_words': 162, 'path': 'activities/Python 105b - File Metadata Extraction (Tika Python Test).ipynb', 'repo_name': 'morskyjezek/digcur', 'size': '1774'}