-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_jpeg_to_wobble_classifier.py
More file actions
executable file
·58 lines (43 loc) · 1.48 KB
/
send_jpeg_to_wobble_classifier.py
File metadata and controls
executable file
·58 lines (43 loc) · 1.48 KB
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
54
55
56
57
58
import os, sys, socket, argparse
# Exit codes
allgood = 0
filenotfound = 1
fileioerror = 2
noreply = 3
noconnection = 4
HOST = "150.204.240.157" # ltvmhost5
PORT = 8225
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Run M1 wobble classifier on one image')
parser.add_argument('infile', action='store', help='JPG icreated by fits2grey, mandatory')
#parser.add_argument('-v', dest='verbose', action='store_true', help='Turn on verbose mode (default: Off)')
#parser.add_argument('-t', dest='timing', action='store_true', help='Turn on timing reports (default: Off)')
# -h is always added automatically by argparse1
args = parser.parse_args()
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
try:
with open(args.infile, "rb") as f:
image_data = f.read()
except FileNotFoundError:
print("Error: File not found.")
sys.exit(filenotfound)
except IOError as e:
print("Error: IO error: ",e)
sys.exit(fileioerror)
# Send file size
file_size = len(image_data)
file_size_bytes = file_size.to_bytes(8, 'big')
s.sendall(file_size_bytes)
# Send image data
s.sendall(image_data)
reply = s.recv(1024) # Receive up to 1024 bytes
if not reply:
print("Error: No reply.")
sys.exit(noreply)
except Exception as e:
print("Error: No connection to remote socket", e)
sys.exit(noconnection)
print(reply.decode())
sys.exit(allgood)