56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
""" Author: Hendrik Schutter, mail@hendrikschutter.com
|
|
"""
|
|
|
|
import config
|
|
import glob
|
|
import os
|
|
import time
|
|
import shutil
|
|
|
|
def copy_image(src):
|
|
shutil.copy(src, config.destination_image_full_path)
|
|
os.chmod(config.destination_image_full_path, 644)
|
|
|
|
def main():
|
|
print("starting ...")
|
|
|
|
newest_file_path = ""
|
|
newest_file_size = 0
|
|
|
|
while True:
|
|
|
|
while True:
|
|
try:
|
|
# print(config.image_search_path)
|
|
list_of_files = glob.glob(config.image_search_path+"/**/*.jpg", recursive=True)
|
|
# print(list_of_files)
|
|
newest_file_path_tmp = max(list_of_files, key=os.path.getctime)
|
|
newest_file_size_tmp = os.stat(newest_file_path_tmp).st_size
|
|
|
|
if (newest_file_path_tmp == newest_file_path) and (newest_file_size_tmp == newest_file_size):
|
|
# already found the newest file
|
|
print("no newer file found")
|
|
break
|
|
|
|
time.sleep(1) # wait 1sec to see if the upload is still in progress
|
|
|
|
list_of_files = glob.glob(config.image_search_path+"/**/*.jpg", recursive=True)
|
|
newest_file_path = max(list_of_files, key=os.path.getctime)
|
|
newest_file_size = os.stat(newest_file_path).st_size
|
|
|
|
if (newest_file_path_tmp == newest_file_path) and (newest_file_size_tmp == newest_file_size):
|
|
print("Found new file:")
|
|
print("Name: "+str(newest_file_path))
|
|
print("Size: " + str(newest_file_size))
|
|
copy_image(newest_file_path)
|
|
break
|
|
except Exception as e:
|
|
print(e)
|
|
#break
|
|
time.sleep(config.update_interval)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|