-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.py
60 lines (43 loc) · 1.34 KB
/
utility.py
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
import os
import constants
import glob
import re
import time
from typing import List
# from PyPDF2 import PdfFileMerger
# returns true if line contains numeric digit
def num_there(line):
return any(i.isdigit() for i in line)
# find number at perticular location in given line
def find_num(line, location):
nums_match = re.findall(r'\d+', line)
if len(nums_match) >= location:
return nums_match[location-1]
return
def delete_files(directory):
files = glob.glob(directory+'*')
for f in files:
os.remove(f)
def get_time():
current_time = time.strftime("%H:%M:%S", time.localtime())
return current_time
def get_filename_from_path(filepath: str):
filename = filepath[filepath.rfind(os.path.sep)+1:-4]
return filename
def remove_empty_lines(lines: List[str]):
new_lines = []
for line in lines:
line = line.replace('\n', '')
if line.rstrip():
new_lines.append(line)
return new_lines
# def remove_permission_error(filename):
# merger = PdfFileMerger()
# tmp_filename = 'copyOfOriginal.pdf'
# file = open(filename, 'rb')
# merger.append(file)
# with open(tmp_filename, "wb") as fout:
# merger.write(fout)
# file.close()
# with open(filename, 'wb+') as output, open(tmp_filename, 'rb') as input:
# output.write(input.read())