Skip to content

Instantly share code, notes, and snippets.

@ubershmekel
Created June 22, 2017 00:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ubershmekel/f7a0b8f85d2335df7a324ef5e3cf4294 to your computer and use it in GitHub Desktop.
Save ubershmekel/f7a0b8f85d2335df7a324ef5e3cf4294 to your computer and use it in GitHub Desktop.
How to open .sgn file types from Israeli Courts
#!/usr/bin/python
"""
court.gov.il for some reason send out these signed files with the "sgn" file extension.
They're xml files with base64 encoded contents, this is how you can get them out.
open_sgn.py myfile.sgn
"""
import base64
import xml.etree.ElementTree as ET
import sys
if len(sys.argv) < 2:
print("Usage: %s file_to_extract.sgn" % __file__)
exit(1)
fpath = sys.argv[1]
tree = ET.parse(fpath)
root = tree.getroot()
extension = list(root.iter('DocumentExtension'))[0].text
text = list(root.iter('DocumentContent'))[0].text
decoded = base64.decodestring(text)
dst = fpath + '.' + extension
print("Saving results to '%s'" % dst)
open(dst, 'wb').write(decoded)
@nivs
Copy link

nivs commented Jun 26, 2018

🤦‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment