Initial release

This commit is contained in:
anon74133 2025-07-18 18:48:25 +03:00
parent b281adffc5
commit 7c4e1628b6
Signed by: Anon74123
GPG key ID: FA392911B1E88411
5 changed files with 274 additions and 0 deletions

View file

@ -0,0 +1,70 @@
import PyPDF2
import re
import fitz
import os
import webbrowser
from tkinter import *
from tkinter import ttk
from tkinter.messagebox import showerror
def config():
if not os.path.exists("Settings.conf"):
f = open("Settings.conf", "w")
f.write("DeleteOld=0")
f.close()
f = open("Settings.conf", "r")
settings = f.read().split('\n')
global Deleteold
Deleteold = int(settings[0][-1])
def sign(path_pdf,output):
image = "sign.png"
# old params 402 17 565 230
position = fitz.Rect(432,24,500,230)
file_handle = fitz.open(path_pdf)
first_page = file_handle[0]
first_page.insert_image(position, filename=image)
file_handle.save(output)
def work(path_pdf):
data = extractData(path_pdf)
if not os.path.exists(data[0] + ' ' + 'SN ' + data[1] + ' ' + data[2] + '.pdf'):
sign(path_pdf, data[0] + ' ' + 'SN ' + data[1] + ' ' + data[2] + '.pdf')
if Deleteold:
os.remove(path_pdf)
return 1
return 0
def extractData(path_pdf):
pdf = open(path_pdf, 'rb')
read = PyPDF2.PdfReader(pdf)
page = read.pages[0]
all_text = page.extract_text()
#print(all_text)
if all_text == '':
showerror(title="Ошибка", message=f'Файл {path_pdf} является картинкой, уберите его и перезапустите программу')
return 1
data = []
if len(re.findall('ЦБ-\\d{9}', all_text)) != 0:
data.append(re.findall('ЦБ-\\d{9}', all_text)[0])
else:
data.append('ЗН ' + re.findall('Заказ-наряд \\d{12}', all_text)[0][11:])
if len(re.findall('\\b\\d{6}\\b', all_text.split('SN')[1].split('Дата')[0])) != 0:
data.append(re.findall('\\b\\d{6}\\b', all_text.split('SN')[1].split('Дата')[0])[0])
else:
data.append(re.findall('\\b\\d{5}\\b', all_text.split('SN')[1].split('Дата')[0])[0])
data.append(re.findall('\\d\\d\\.\\d\\d\\.\\d{4}', all_text.split('Дата')[1])[0].replace('.', ''))
pdf.close()
return data
def get_pdf():
filenames = os.listdir('.')
return filenames
def main():
config()
for i in get_pdf():
if i[-3:] == 'pdf':
work(os.path.abspath(i))
for i in get_pdf():
if i[-3:] == 'pdf' and i[0:2] == 'ЦБ':
webbrowser.open_new_tab(os.path.abspath(i))
main()

View file

@ -0,0 +1 @@
DeleteOld=0