"""
A script to be run from log's cron *before* the actual log
evaluation happens.  It produces logs as required by GAIA's central
log collectors.

Shut this off as soon as that insane endeavour is over.
"""

import os

from gavo import api
from gavo.formats import csvtable # for registration

dd = api.getRD("logs/logs").getById("make_gaia_log")
res = api.makeData(dd).getPrimaryTable()

# by gaialoggrammar, all rows have the same month and year (and day...)
forDate = res.rows[0]["for_date"]
destName = os.path.join(dd.rd.resdir, "logs_for_gaia",
	"ARI-%04d-%02d.csv"%(forDate.year, forDate.month))

with open(destName, "ab") as f:
	f.write(api.getFormatted("csv", res))
