# script to work out the actions from the previous night

import pymysql 

# connect to database
conn=pymysql.connect(host='ds',db='ngts_ops')
cur=conn.cursor()

qry="SELECT * FROM action_list WHERE schedule_start_utc BETWEEN date_sub(now(), INTERVAL 1 DAY) AND now()"
cur.execute(qry)

cams={801:[],
	802:[],
	803:[],
	804:[],
	805:[],
	806:[],
	807:[],
	808:[],
	809:[],
	810:[],
	811:[],
	812:[]}


for row in cur:
	cams[row[1]].append("%s_%s" % (row[0],row[4]))
	

@@ -54,24 +54,238 @@
 ght%0A
-%0Aimport pymysql 
+# movies and pngs should go in /ngts/staging/movies/%0A# ./create_images.py -d /path/to/png_directory %60ls /ngts/dasXX/actionYYYY_ZZZZZ/*IMAGE*.fits%60 %0A%0Aimport pymysql %0Aimport logging%0A# from create_images import create_images as cimgs
 %0A%0A# 
@@ -369,16 +369,49 @@
 rsor()%0A%0A
+# get the actions from yesterday%0A
 qry=%22SEL
@@ -527,16 +527,67 @@
 e(qry)%0A%0A
+# empty dictionary for the actions for each camera%0A
 cams=%7B80
@@ -693,11 +693,313 @@
 2:%5B%5D
-%7D%0A%0A
+,%0A%09899:%5B%5D%7D%0A%0A# remove the roof entry, not needed%0Adel cams%5B899%5D%0A%0A# set the key to the das machines for each camera%0Adas=%7B801:None,%0A%09802:das06,%0A%09803:das09,%0A%09804:das04,%0A%09805:None,%0A%09806:None,%0A%09807:None,%0A%09808:None,%0A%09809:None,%0A%09810:None,%0A%09811:None,%0A%09812:None%7D%0A%0A%0A# get the action ids for each camera (and dome 899)
 %0Afor
@@ -1033,16 +1033,22 @@
 append(%22
+action
 %25s_%25s%22 %25
@@ -1065,10 +1065,243 @@
 ow%5B4%5D))%0A
+%0A%0A# now we have the action ids go through and create the images for each %0Afor i in cams:%0A%09if len(cams%5Bi%5D) %3E 0:%0A%09%09for j in cams%5Bi%5D:%0A%09%09%09print %22/ngts/%25d/%25s/*.fits%22 %25 (das%5Bi%5D,j)%0A%09%09%09t=g.glob('/ngts/%25s/%25s/*.fits' %25 (das%5Bi%5D,j))%0A%09%09%09%0A%09%09%09%0A%09%09%09%0A
 %09%0A

Version ready for testing on AUX01