Я новичок здесь и довольно плохо знаком с Python, поэтому любая помощь будет большой благодарностью.
Я пытаюсь сократить код, который я сделал, и автоматически проверять следующий файл в списке, который нужно распаковать и переместить, но мне трудно, так как я использую несколько аргументов.
Может кто-нибудь найти более простой / автоматический способ, поэтому мне не нужно обновлять код, если требуется дополнительный zip-файл.
mainapp.py
"""main program for selecting files from specific folder based on date criteria and extracting chosen file to another location for pickup by the database
"""
def main():
pass
"""
Library function imports
"""
import zipfile
import os, sys
import shutil
"""enter code here``
Clears old data from folder
"""
# List directory
path = "//var//www/html//"
dirs = os.listdir('folder with zips')
"""
This uses todays date as string, for use to find date in filename
"""
import datetime
now = datetime.datetime.now().isoformat().replace('-','')[:8]
"""
list that is converted into string for each file
"""
matching = [s for s in dirs if now and ".zip" in s]
import deflator
if __name__ == '__main__':
main()
enter code here
Вот в чем проблема, код работает нормально и как можно лучше, но проблема в том, что эти пути статичны ... мы можем проверить это, пока ничто не будет соответствовать критериям
deflator.py
def main():
pass
from mainapp import *
"""counts number of files in dir"""
dircount = len(dirs)
print
"""
date and file path name join
"""
static_path1 = full_path1 = os.path.join('folder join')
full_path1 = os.path.join(static_path1+matching[0])
full_path2 = os.path.join(static_path1+matching[1])
full_path3 = os.path.join(static_path1+matching[2])
full_path4 = os.path.join(static_path1+matching[3])
full_path5 = os.path.join(static_path1+matching[4])
full_path6 = os.path.join(static_path1+matching[5])
"""
Defines folder path, compression type, extract path
"""
static_path2 = ('output folder')
deflate_zip = (zipfile.ZIP_DEFLATED)
zip_ref1 = zipfile.ZipFile(full_path1,'r', deflate_zip)
zip_ref1.extractall(static_path2)
zip_ref2 = zipfile.ZipFile(full_path2,'r', deflate_zip)
zip_ref2.extractall(static_path2)
zip_ref3 = zipfile.ZipFile(full_path3,'r', deflate_zip)
zip_ref3.extractall(static_path2)
zip_ref4 = zipfile.ZipFile(full_path4,'r', deflate_zip)
zip_ref4.extractall(static_path2)
zip_ref5 = zipfile.ZipFile(full_path5,'r', deflate_zip)
zip_ref5.extractall(static_path2)
zip_ref6 = zipfile.ZipFile(full_path6,'r', deflate_zip)
zip_ref6.extractall(static_path2)
if __name__ == '__main__':
Спасибо за потраченное время, любая помощь будет отличной:)