Skip to content

Instantly share code, notes, and snippets.

@ryonagana
Last active December 31, 2024 15:04
Show Gist options
  • Save ryonagana/b256d8b22e9d8b3139980f815535e74f to your computer and use it in GitHub Desktop.
Save ryonagana/b256d8b22e9d8b3139980f815535e74f to your computer and use it in GitHub Desktop.
import os
import sys
import base64
from stat import S_ISREG
import itertools
if __name__ == "__main__":
if len(sys.argv) < 3:
print("Erro paramentos Incorretos")
sys.exit(1)
try:
arquivo=sys.argv[1]
except IndexError as ie:
print("Arquivo nao Encontrado")
sys.exit(1)
try:
mode = os.lstat(arquivo).st_mode
if not S_ISREG(mode):
print("Nao e um Arquivo!")
sys.exit(1)
except FileNotFoundError as ex:
print(ex)
exit(1)
try:
linhas=int(sys.argv[2])
except IndexError as ie:
print("Linhas nao definidas!")
sys.exit(1)
try:
saida=str(sys.argv[3])
except IndexError as ie:
print("Saida nao definidas!")
sys.exit(1)
with open(arquivo,"r") as f:
out = open(saida,"wb")
for line in itertools.islice(f,linhas,None):
if not line:
break
out.write(base64.b64decode(line))
out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment