Repository navigation
Expand file tree
/
Copy pathHomeWorkSeperator.py
More file actions
138 lines (117 loc) · 4.32 KB
/
Copy pathHomeWorkSeperator.py
File metadata and controls
138 lines (117 loc) · 4.32 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Written by Daniel Demidovski to separate all homework from single file to files
import sys
import keyboard
from colored import bg
import os
def welcome_text():
print(" _____ __________ ___ ____ ___ ____ ____ \n \
/ ___// ____/ __ \/ | / __ \/ | / __ \/ __ \ \n \
\__ \/ __/ / /_/ / /| | / /_/ / /| | / / / / / / / \n \
___/ / /___/ ____/ ___ |/ _, _/ ___ |/ /_/ / /_/ / \n \
/____/_____/_/ /_/ |_/_/ |_/_/ |_/_____/\____/ \n \
\n \
if u lazy like me, welcome to the club XD \n \
----------------------------------------- ")
def cmdLineCleaner():
keyboard.press('ESC')
keyboard.release('ESC')
def slicer(file_path, start, end):
file = open(file_path, 'r')
all_lines = file.readlines()
file.close()
return all_lines[start-1:end]
def slicer_full(file_path):
file = open(file_path, 'r')
all_lines = file.readlines()
file.close()
return all_lines
def create_file(name, context):
formated_context = ''
for i in context:
formated_context += i
file = open(name, 'x')
file.write(str(formated_context))
file.close()
def chose_file():
path_to_file = str(sys.argv[1])
return path_to_file
def repeater():
cmdLineCleaner()
path_to_file = None
while True:
if path_to_file is None:
path_to_file = chose_file()
start_line = int(input(" Please type first line: "))
end_line = int(input(" Please type closing line: "))
result = slicer(path_to_file, start_line, end_line)
print(type(result))
f_name = input(" Please type desired file name: ")
create_file(f_name + ".py", result)
print(f"File saved! {f_name}.py")
quit()
def indexes(iterable, obj):
return (index for index, elem in enumerate(iterable) if elem == obj)
def se_repeater():
cmdLineCleaner()
path_to_file = None
start_line = None
end_line = None
counter = 0
code_list = []
indx = 0
while True:
if path_to_file is None:
path_to_file = chose_file()
result = slicer_full(path_to_file)
#print(result)
#print(''.join(result))
for i in result:
if i.startswith("#$"):
if ( i[2:5] != "end"):
#print(i)
f_name = i[2:]
start_line = result.index(i)
if ( i[2:5] == "end" ):
#print(i)
end_line = list(indexes(result, i))
print(f"Code start at {start_line} and end at {end_line[indx]}")
y = 0
for x in end_line:
#print(indx)
while start_line <= end_line[indx]:
#print(end_line[indx])
# print(result[start_line].strip())
code_list.append(result[start_line])
start_line += 1
# print(code_list)
indx += 1
create_file(f_name[:-1] + ".py", code_list)
code_list.clear()
print(f"File saved! {f_name[:-1]}.py")
#
quit()
def main():
welcome_text()
options_list = ['Please press the corresponding number',
'1 | Select start and end line method',
'2 | Whole file separated with special char']
option_selected = ["1", "2"]
print('\n'.join(options_list))
while True:
if keyboard.is_pressed("1"):
option_selected = 1
repeater()
cmdLineCleaner()
break
elif keyboard.is_pressed("2"):
option_selected = 2
se_repeater()
cmdLineCleaner()
break
elif keyboard.read_key() not in option_selected:
cmdLineCleaner()
os.system('cls')
print((bg('red')) + f"\nSELECT ONLY NUMBERS FROM THE LIST. {keyboard.read_key()} is not in the list.\n" + (bg('black')))
return main()
# programStartHere
main()