<jupyter_start><jupyter_text>PostImages UploaderThis notebook provide an easy way to upload your images to [postimages.org](https://postimages.org).  How to use:- Modify the **configurations** if needed.- At menu bar, select Run > Run All Cells.- Scroll to the end of this notebook for outputs.  Configurations ---Path to a directory which contains your images you want to upload.> Only files in top level directory will be uploaded.  > Limit: 24 MiB per file or image dimension of 2508 squared pixels.<jupyter_code>INPUT_DIR = '../outputs/images'<jupyter_output><empty_output><jupyter_text>---Path to a file which will contain a list of uploaded image urls used for updating metadata database file.> Append if exists.<jupyter_code>URLS_PATH = '../outputs/urls.txt'<jupyter_output><empty_output><jupyter_text>---  Import<jupyter_code>import os
import sys

from modules.PostImages import PostImages<jupyter_output><empty_output><jupyter_text>Basic Configuration Validation<jupyter_code>assert os.path.isdir(INPUT_DIR), 'INPUT_DIR must exist and be a directory.'
assert any(x.is_file() for x in os.scandir(INPUT_DIR)), 'INPUT_DIR top level directory must have at least one file.'
assert not os.path.exists(URLS_PATH) or os.path.isfile(URLS_PATH), 'URLS_PATH must be a file if it exists.'<jupyter_output><empty_output><jupyter_text>Upload<jupyter_code>uploader = PostImages()

extras = []
try:
    with open(URLS_PATH, 'a') as f_urls:
        for entry in os.scandir(INPUT_DIR):
            if entry.is_file():
                image_url, extra = uploader.upload_file(entry.path)
                extras.append(extra)

                print(entry.name, image_url, '', sep='\n', file=f_urls)
                print(entry.name, image_url, extra)

    print('DONE!')
except KeyboardInterrupt:
    print('\nStopped!')<jupyter_output><empty_output><jupyter_text>------ Delete Uploaded Images [EXTRA]> Change below cell to code mode to run the cell.<jupyter_code>for extra in extras:
    result = uploader.delete(extra['private_url'])
    print(result)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1067632850241546, 'fraction_numerical': 0.002898550724637681, 'mean_word_length': 4.507978723404255, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 30, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '630063', 'license': 'MIT', 'n_tokens_mistral': 663, 'n_tokens_neox': 646, 'n_words': 191, 'path': 'notebooks/uploader/postimages.ipynb', 'repo_name': 'AsdertyTreds/PngBin', 'size': '2070'}