-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
45 lines (40 loc) · 1.69 KB
/
Copy pathMain.py
File metadata and controls
45 lines (40 loc) · 1.69 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
import sys
from Encode import EncodeHuffman
from Decode import DecodeHuffman
def error():
print("")
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print(">> É necessario executar o script com 2 paramentros. Ex: <<")
print(">> <<")
print(">> python3 Main.py encode texto.txt <<")
print(">> ou <<")
print(">> python3 Main.py decode texto.txt <<")
print(">> <<")
print(">> Tente novamente. <<")
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print("")
if __name__ == '__main__':
if(len(sys.argv)==3):
if sys.argv[1] == "encode":
string = ''
try:
f = open(sys.argv[2], 'r')
for line in f:
string += line+'\n'
f.close()
EncodeHuffman(string, sys.argv[2])
except:
print("Arquivo não encontrado, tente novamente")
elif sys.argv[1] == "decode":
print("Tentando decodificar o arquivo: "+sys.argv[2])
f = open(sys.argv[2],'r')
argumentos = {}
count = 0
for line in f:
argumentos[count] = line
count +=1
DecodeHuffman(argumentos[0],argumentos[1],sys.argv[2])
else:
error()
else:
error()