Last active
June 27, 2024 17:08
-
-
Save ordotools/1ef1631291c8363b9c142e8bf551f293 to your computer and use it in GitHub Desktop.
Do something to new files in a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def article_data() -> dict: | |
""" | |
json file keeps the record of the "age" of the newest file in the directory. | |
""" | |
with open('./last_ocr_file.json', 'r') as database: | |
return json.load(database) | |
def check_ocred(file: str, directory: str) -> bool: | |
""" | |
Check each file for age. | |
""" | |
data = article_data() | |
html, md = filename_html(file), filename_md(file) | |
path_md = MKDN_PATH+directory+'/'+md | |
path_html = HTML_PATH+directory+'/'+html | |
if not os.path.isfile(path_html): | |
if not os.path.isfile(path_md): | |
# TODO adjust this so that page is fetched form here. | |
return 404 | |
else: | |
build_article(file=file, directory=directory) | |
else: | |
data = article_data() | |
info = os.stat(path_html) | |
try: | |
if info.st_mtime == data[directory][file]['mod']: | |
return False | |
else: | |
return True | |
except KeyError: | |
build_article(file=file, directory=directory) | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment