Skip to content

Instantly share code, notes, and snippets.

@pato
Created April 14, 2016 04:58
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 pato/f6ffbf999447abf342d3ce138fd46ece to your computer and use it in GitHub Desktop.
Save pato/f6ffbf999447abf342d3ce138fd46ece to your computer and use it in GitHub Desktop.
Script to be run whenever USB recorder is plugged in, copy the files, encrypt them using GPG, and shred the plain file
#!/usr/bin/python
from os import listdir, system
from os.path import isfile, join, getmtime
from shutil import move
from datetime import date
from subprocess import call
encryptEmail = "youremail@here.com"
src = "/media/RECORD/RECORD/VOICE"
dst = "/home/pi/meetings"
dryrun = False
files = [f for f in listdir(src) if isfile(join(src, f))]
for i,file in enumerate(files):
srcFile = join(src, file)
modify = date.fromtimestamp(getmtime(srcFile))
base = str(modify) if i == 0 else (str(modify) + "_" + str(i))
dstFile = base + ".WAV"
dstEnc = base + ".GPG"
dstPlain = join(dst, dstFile)
dstEncrypted = join(dst,dstEnc)
# move the file
if dryrun:
print "copy(%s, %s)" % (srcFile, dstPlain)
else:
move(srcFile, dstPlain)
print "moved"
# encrypt the file
encryptCmd = "gpg --output %s --encrypt --recipient %s %s" % (dstEncrypted, encryptEmail, dstPlain)
if dryrun:
print encryptCmd
else:
system(encryptCmd)
print "encrypted"
# shred the plaintext
shredCmd = "/usr/bin/shred -uz %s" % (dstPlain)
if dryrun:
print shredCmd
else:
system(shredCmd)
print "shredded unencrypted version"
print "Done! (%d/%d)" % (i+1, len(files))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment