Skip to content

Instantly share code, notes, and snippets.

@corei8
Last active June 27, 2024 17:08
Show Gist options
  • Save corei8/1ef1631291c8363b9c142e8bf551f293 to your computer and use it in GitHub Desktop.
Save corei8/1ef1631291c8363b9c142e8bf551f293 to your computer and use it in GitHub Desktop.
Do something to new files in a directory
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