long time no commit
This commit is contained in:
19
conn_test.py
19
conn_test.py
@@ -1,19 +0,0 @@
|
|||||||
import os
|
|
||||||
from signal import signal, SIGINT
|
|
||||||
from goprocam import GoProCamera, constants
|
|
||||||
|
|
||||||
seconds = 4
|
|
||||||
|
|
||||||
# helps with video recording
|
|
||||||
def handler(s, f):
|
|
||||||
gopro.stopWebcam()
|
|
||||||
quit()
|
|
||||||
|
|
||||||
def takeVideo(time):
|
|
||||||
signal(SIGINT, handler)
|
|
||||||
gopro = GoProCamera.GoPro()
|
|
||||||
gopro.shoot_video(time)
|
|
||||||
gopro.downloadLastMedia(custom_filename=(location+"plaintext/" + numFiles() + ".mp4"))
|
|
||||||
gopro.delete("last")
|
|
||||||
|
|
||||||
takeVideo(seconds)
|
|
||||||
59
cronjob.py
59
cronjob.py
@@ -16,9 +16,11 @@ import os
|
|||||||
import glob
|
import glob
|
||||||
from signal import signal, SIGINT
|
from signal import signal, SIGINT
|
||||||
from goprocam import GoProCamera, constants
|
from goprocam import GoProCamera, constants
|
||||||
|
import time
|
||||||
|
import shutil
|
||||||
|
|
||||||
# global vars
|
# global vars
|
||||||
location = "/home/pi/final/videos/" # location of video files, subfolders "plaintext" and "encrypted" assumed to exist
|
location = os.getcwd() + "/videos/" # location of video files, subfolders "plaintext" and "encrypted" assumed to exist
|
||||||
locpt = location + "plaintext/"
|
locpt = location + "plaintext/"
|
||||||
locec = location + "encrypted/"
|
locec = location + "encrypted/"
|
||||||
seconds = int(open("interval", "r").read()) # seconds to record video for
|
seconds = int(open("interval", "r").read()) # seconds to record video for
|
||||||
@@ -30,7 +32,7 @@ def handler(s, f):
|
|||||||
|
|
||||||
# returns the current file number for naming convention
|
# returns the current file number for naming convention
|
||||||
def numFiles():
|
def numFiles():
|
||||||
return str(len([item for item in os.listdir(location+"encrypted/") if os.path.isfile(os.path.join(location+"encrypted/", item))]))
|
return str(len([item for item in os.listdir(locec) if os.path.isfile(os.path.join(locec, item))]))
|
||||||
|
|
||||||
# compresses a given file, new file is named same filename with .zip at end
|
# compresses a given file, new file is named same filename with .zip at end
|
||||||
# returns name of new file
|
# returns name of new file
|
||||||
@@ -44,7 +46,7 @@ def compress(filename):
|
|||||||
def takeVideo(time):
|
def takeVideo(time):
|
||||||
signal(SIGINT, handler)
|
signal(SIGINT, handler)
|
||||||
gopro = GoProCamera.GoPro(ip_address=GoProCamera.GoPro.getWebcamIP())
|
gopro = GoProCamera.GoPro(ip_address=GoProCamera.GoPro.getWebcamIP())
|
||||||
gopro.video_settings("720p", fps='30')
|
gopro.video_settings("480p", fps='30')
|
||||||
gopro.shoot_video(time)
|
gopro.shoot_video(time)
|
||||||
gopro.downloadLowRes(custom_filename=(location+"plaintext/" + numFiles() + ".mp4"))
|
gopro.downloadLowRes(custom_filename=(location+"plaintext/" + numFiles() + ".mp4"))
|
||||||
gopro.delete("last")
|
gopro.delete("last")
|
||||||
@@ -74,13 +76,15 @@ def encryptVideo(file):
|
|||||||
cipher = AES.new(key, AES.MODE_EAX)
|
cipher = AES.new(key, AES.MODE_EAX)
|
||||||
ciphertext, tag = cipher.encrypt_and_digest(message)
|
ciphertext, tag = cipher.encrypt_and_digest(message)
|
||||||
# save encrypted file
|
# save encrypted file
|
||||||
file_out = open(location + "encrypted/" + numFiles() + ".mpc", "wb")
|
file_out = open(locec + numFiles() + ".mpc", "wb")
|
||||||
[ file_out.write(x) for x in (cipher.nonce, tag, ciphertext) ]
|
[ file_out.write(x) for x in (cipher.nonce, tag, ciphertext) ]
|
||||||
file_out.close()
|
file_out.close()
|
||||||
# save the encrypted key
|
# save the encrypted key
|
||||||
with open("keys/" + str(int(numFiles()) - 1) + ".asc", "wb+") as keyf:
|
with open("keys/" + str(int(numFiles()) - 1) + ".asc", "wb+") as keyf:
|
||||||
keyf.write(PKEncrypt(key))
|
keyf.write(PKEncrypt(key))
|
||||||
|
|
||||||
|
# OLD METHOD
|
||||||
|
''''''
|
||||||
# record the video and store in file location
|
# record the video and store in file location
|
||||||
takeVideo(seconds)
|
takeVideo(seconds)
|
||||||
|
|
||||||
@@ -90,11 +94,52 @@ fileset = [file for file in glob.glob(location + "plaintext/*.mp4", recursive=Fa
|
|||||||
with open("numFiles.txt", "w+") as numf:
|
with open("numFiles.txt", "w+") as numf:
|
||||||
numf.write(numFiles())
|
numf.write(numFiles())
|
||||||
|
|
||||||
# compress
|
# compress and encrypt
|
||||||
i = 1
|
|
||||||
for file in fileset:
|
for file in fileset:
|
||||||
newf = compress(file)
|
newf = compress(file)
|
||||||
encryptVideo(newf)
|
encryptVideo(newf)
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
os.remove(newf)
|
os.remove(newf)
|
||||||
|
''''''
|
||||||
|
|
||||||
|
# FORK
|
||||||
|
def child():
|
||||||
|
# child compresses and encrypts
|
||||||
|
fileset = [file for file in glob.glob(locpt + "*.mp4", recursive=False)]
|
||||||
|
if(len(fileset) == 0):
|
||||||
|
os._exit(0)
|
||||||
|
# prevents double encryption
|
||||||
|
folder = locpt + str(int(time.time()))
|
||||||
|
os.mkdir(folder)
|
||||||
|
for file in fileset:
|
||||||
|
shutil.move(file, folder)
|
||||||
|
fileset = [file for file in glob.glob(folder + "/*.mp4", recursive=False)]
|
||||||
|
for file in fileset:
|
||||||
|
print("Encrypting file " + file)
|
||||||
|
newf = compress(file)
|
||||||
|
encryptVideo(newf)
|
||||||
|
os.remove(file)
|
||||||
|
os.remove(newf)
|
||||||
|
shutil.rmtree(folder)
|
||||||
|
with open("numFiles.txt", "w+") as numf:
|
||||||
|
numf.write(numFiles())
|
||||||
|
os._exit(0)
|
||||||
|
|
||||||
|
def parent():
|
||||||
|
# parent records, child does everything else
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
newpid = os.fork()
|
||||||
|
if newpid == 0:
|
||||||
|
child()
|
||||||
|
else:
|
||||||
|
takeVideo(seconds)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('Interrupted')
|
||||||
|
try:
|
||||||
|
#child()
|
||||||
|
os._exit(0)
|
||||||
|
except SystemExit:
|
||||||
|
os._exit(0)
|
||||||
|
#parent()
|
||||||
|
|
||||||
|
|||||||
21
fork_test.py
Normal file
21
fork_test.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
def child():
|
||||||
|
print('\nA new child ', os.getpid())
|
||||||
|
os._exit(0)
|
||||||
|
|
||||||
|
def parent():
|
||||||
|
while True:
|
||||||
|
newpid = os.fork()
|
||||||
|
if newpid == 0:
|
||||||
|
child()
|
||||||
|
else:
|
||||||
|
pids = (os.getpid(), newpid)
|
||||||
|
print("parent: %d, child: %d\n" % pids)
|
||||||
|
reply = input("q for quit / c for new fork")
|
||||||
|
if reply == 'c':
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
parent()
|
||||||
@@ -1 +1 @@
|
|||||||
1
|
2
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
import http.server
|
import http.server
|
||||||
import socketserver
|
import socketserver
|
||||||
|
import socket
|
||||||
|
|
||||||
PORT = 63654
|
PORT = 63654
|
||||||
Handler = http.server.SimpleHTTPRequestHandler
|
Handler = http.server.SimpleHTTPRequestHandler
|
||||||
|
h_name = socket.gethostname()
|
||||||
|
IPaddr = str(socket.gethostbyname(h_name))
|
||||||
|
|
||||||
with socketserver.TCPServer(("", PORT), Handler) as httpd:
|
with socketserver.TCPServer(("", PORT), Handler) as httpd:
|
||||||
print("Serving at port", PORT)
|
print("Serving at " + IPaddr + ":" + str(PORT))
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|||||||
14
zip_test.py
14
zip_test.py
@@ -1,14 +0,0 @@
|
|||||||
import zipfile
|
|
||||||
|
|
||||||
w = zipfile.ZipFile("NewZipfile.zip", mode='w', compression=zipfile.ZIP_DEFLATED)
|
|
||||||
|
|
||||||
# Write to zip file
|
|
||||||
w.write("test.txt")
|
|
||||||
w.close()
|
|
||||||
|
|
||||||
r = zipfile.ZipFile("NewZipfile.zip", mode='r', compression=zipfile.ZIP_DEFLATED)
|
|
||||||
|
|
||||||
# Reading Zip File
|
|
||||||
print("\n", r.read('test.txt'))
|
|
||||||
|
|
||||||
r.close()
|
|
||||||
Reference in New Issue
Block a user