-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimagery_auto.py
More file actions
114 lines (83 loc) · 3.78 KB
/
Copy pathimagery_auto.py
File metadata and controls
114 lines (83 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#importing the required modules
import datetime
from zipfile import ZipFile
import os
#function to get a list of the tiles from the text file
def getTiles(textfilename):
f=open(textfilename)
lines=f.readlines()
tiles=list()
for x in lines:
tiles.append(x.split()[0])
tiles.pop(0)
f.close()
return tiles
#function to get a list of the files in the zip folder
def getFiles(folder_path):
zip=ZipFile(folder_path, "r")
files=zip.namelist()
return files
#funtion to get the list of the tiles not present in the zip folder
def find(files, tiles):
TilesNotFound=list()
for tile in tiles:
flag=False
for file in files:
if tile in file:
flag=True
if flag==False:
TilesNotFound.append(tile)
return TilesNotFound
#function to log into a textfile
def logit(tiles_nf,file_count,tiles):
f=open("FilesNF_log.txt","a") #open FilesNF_log.txt in append mode
d=datetime.datetime.now() #get the current date
f.write("\n"+d.strftime("%c"))
f.write("\ntext file used: "+textfile_path)
f.write("\nfolder used: "+folder_path)
f.write("\ntiles not found:\n")
for t in tiles_nf:
f.write(t+"\n")
f.write("\nthe number of files found for each tilename as following:\n")
for i in range(len(tiles)):
f.write(tiles[i] + ": " + str(file_count[i]) + "\n")
f.close()
#function to count the number of files found in the zip folder for each tile number in the text file
def fileCount(tiles, files):
count=list()
for tile in tiles:
c=0
for file in files:
if tile in file:
c+=1
count.append(c)
return count
while True:
folder_path=input("please enter full path of the zip folder:") #get full path of the zip folder from user
#if not folder_path.endswith(".zip"):
#folder_path=folder_path+".zip"
#break
if not os.path.isfile(folder_path): #check if the folder exists
print("The zip folder does not exist. Please check the filename entered and make sure to add the correct file extension")
else:
break
while True:
textfile_path=input("please enter the full path of the text file:") #get full path of the text file from user
#if not textfile_path.endswith(".txt"):
#textfile_path=textfile_path+".txt"
#break
if not os.path.isfile(textfile_path): #check if the file exists
print("The file does not exist. Please check the filename entered and make sure to add the correct file extension.")
else:
break
try:
filelist=getFiles(folder_path) #call get files function
tilelist=getTiles(textfile_path) #call get tiles function
tiles_not_found=find(filelist,tilelist) #call find function
countlist=fileCount(tilelist,filelist) #call fileCount function
logit(tiles_not_found,countlist,tilelist) #call logit function
except:
print("Oops!Something went wrong. Please check the file names entered and re run the program") #if there is a problem with execution, throw error message
else:
print("Program executed successfully! please check the log file")
input("press enter to exit")