-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_movement_data.py
53 lines (45 loc) · 1.68 KB
/
send_movement_data.py
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
46
47
48
49
50
51
52
53
# this script sends the movement data to central computer
import argparse
import os
import numpy as np
# We will use this helper function to get the full path of the video files
def listdir_fullpath(root_dir, file_pattern=None, file_extension=None, exclude_dir = True):
# Get everything
if file_extension is None:
file_list = [os.path.join(root_dir, files) for files in os.listdir(root_dir)]
else:
file_list = [os.path.join(root_dir, files) for files in os.listdir(root_dir) if files.endswith(file_extension)]
if file_pattern is not None:
file_list = [file for file in file_list if file_pattern in file]
if len(file_list) > 0:
if exclude_dir:
files_to_keep = np.bitwise_not(list(map(os.path.isdir, file_list)))
file_list = np.array(file_list)[files_to_keep]
file_list = file_list.tolist()
return sorted(file_list)
def send_data(date):
# get mac address
# caution this only works for raspberry PIs on WiFI
mac = open('/sys/class/net/wlan0/address').readline()
# replace "\n" coming from readline()
mac = mac.replace("\n", "")
# figure out date
# ls all files with the particular date
files = listdir_fullpath("/home/pi/homecage_quantification/",
file_pattern=date,
file_extension=".csv")
if len(files) > 0:
for file in files:
print(file)
cmd_command = "scp " + file + " [email protected]:~/raspberry_IP/" + mac
os.system(cmd_command)
else:
# some sort of warning here
return()
if __name__ == '__main__':
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-date", "--date", required=True,
help="date to match against all the movement files")
args = vars(ap.parse_args())
send_data(date = args["date"])