82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
|
from datetime import datetime
|
||
|
from os import scandir
|
||
|
from time import sleep
|
||
|
import numpy as np
|
||
|
import argparse
|
||
|
import cv2
|
||
|
from photoAnalysisUtils import *
|
||
|
from menuAnalysis import *
|
||
|
from mysqlConnect import *
|
||
|
|
||
|
|
||
|
def convert_date(timestamp):
|
||
|
d = datetime.utcfromtimestamp(timestamp)
|
||
|
formated_date = d.strftime('%d %b %Y %H:%M:%S"')
|
||
|
return formated_date
|
||
|
|
||
|
def get_files():
|
||
|
dir_entries = scandir('../orders/')
|
||
|
for entry in dir_entries:
|
||
|
if entry.is_file():
|
||
|
info = entry.stat()
|
||
|
#print(f'{entry.name}\t Created: {convert_date(info.st_ctime)}')
|
||
|
|
||
|
def compareNewest(newest_info):
|
||
|
dir_entries = scandir('orders/')
|
||
|
for entry in dir_entries:
|
||
|
if entry.is_file():
|
||
|
info = entry.stat()
|
||
|
info = info.st_ctime
|
||
|
if datetime.fromtimestamp(info) > datetime.fromtimestamp(newest_info):
|
||
|
return entry
|
||
|
return True
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
newest_file = 0
|
||
|
newest_info = 0
|
||
|
dir_entries = scandir('orders/')
|
||
|
for entry in dir_entries:
|
||
|
if entry.is_file():
|
||
|
info = entry.stat()
|
||
|
info = info.st_ctime
|
||
|
if newest_file == 0:
|
||
|
newest_file = entry
|
||
|
newest_info = newest_file.stat()
|
||
|
newest_info = newest_info.st_ctime
|
||
|
# print(convert_date(info.st_ctime))
|
||
|
#print(f'{newest_file.name}\t Przypisany: {convert_date(newest_info)}')
|
||
|
else:
|
||
|
if datetime.fromtimestamp(info) > datetime.fromtimestamp(newest_info):
|
||
|
#print(f'{entry.name}\t Nowszy: {convert_date(info)}')
|
||
|
#print(f'{newest_file.name}\t Starszy: {convert_date(newest_info)}')
|
||
|
newest_file = entry
|
||
|
newest_info = newest_file.stat()
|
||
|
newest_info = newest_info.st_ctime
|
||
|
|
||
|
|
||
|
try:
|
||
|
while True:
|
||
|
sleep(1)
|
||
|
if compareNewest(newest_info) != True:
|
||
|
# Sprawdzanie czy nowy plik
|
||
|
newest_file = compareNewest(newest_info)
|
||
|
newest_info = newest_file.stat()
|
||
|
newest_info = newest_info.st_ctime
|
||
|
print('Nowy plik to:')
|
||
|
print(datetime.fromtimestamp(newest_info))
|
||
|
print(f'{newest_file.name}\t Data: {newest_info}')
|
||
|
print(newest_file.name)
|
||
|
|
||
|
# URL Do analizy pliku
|
||
|
url = 'orders/'+ str(newest_file.name)
|
||
|
print(url)
|
||
|
img_tested = cv2.imread(url)
|
||
|
mySqlRecords(menuAnalyseIMG(img_tested))
|
||
|
|
||
|
|
||
|
|
||
|
except KeyboardInterrupt:
|
||
|
pass
|