36 lines
777 B
Python
36 lines
777 B
Python
import json
|
|
import logging as logger
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import file_renamer
|
|
|
|
logger.basicConfig(
|
|
format=f"%(asctime)s {logger.BASIC_FORMAT}",
|
|
level=logger.DEBUG,
|
|
handlers=[
|
|
logger.FileHandler(Path(__file__).with_name("jd2_hook.log"), mode="a"),
|
|
logger.StreamHandler(),
|
|
],
|
|
)
|
|
|
|
|
|
def main():
|
|
try:
|
|
payload = json.loads(sys.argv[1])
|
|
except (IndexError, ValueError):
|
|
logger.error("Expected JSON as first argument")
|
|
return 1
|
|
|
|
for link in payload["links"]:
|
|
path = link["download_path"]
|
|
f = Path(path)
|
|
logger.info("")
|
|
if f.is_file():
|
|
file_renamer.fix_dates([f])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
logger.debug(f"Got called with: {sys.argv}")
|
|
exit(main())
|