# coding: utf-8 # In[1]: from datetime import datetime from lxml import etree import sys, os # In[2]: def checkArgs(nbArgs, message): if len(sys.argv) != nbArgs: print(message) sys.exit(2) # In[3]: # CHECK ARGS checkArgs(6, 'Usage : python makeRequest.py (target) (tgt_vi) (sw_vi) (TaoStopTime) (SwStopTime)') prefix = sys.argv[1] tgtVI = sys.argv[2] plasmaVI = sys.argv[3] #missionStopTime = sys.argv[4] #omniStopTime = sys.argv[5] # In[4]: omniStopTime = datetime.strptime(sys.argv[5], '%Y-%m-%dT%H:%M:%S') print omniStopTime # In[5]: missionStopTime = datetime.strptime(sys.argv[4], '%Y-%m-%dT%H:%M:%S.000Z') print missionStopTime # In[6]: def writeXMLMission(XMLfilename,startTime,stopTime,plasmaVI,tgtVI,tgtRParam,tgtLonParam): with open(os.getenv('REQ')+'/'+XMLfilename, "w") as xml: xml.write('\n') xml.write('\n') xml.write('\t'+startTime+'\n') xml.write('\t'+stopTime+'\n') xml.write('\t'+plasmaVI+'\n') xml.write('\tearth_orb_all\n') xml.write('\tR\n') xml.write('\tLON_HCI\n') xml.write('\t'+tgtVI+'\n') xml.write('\t'+tgtRParam+'\n') xml.write('\t'+tgtLonParam+'\n') xml.write('') xml.close() # In[8]: tgtRParam = 'R' tgtLonParam = 'LON_HCI' newMissionStart = missionStopTime newMissionStop = omniStopTime print "New mission start : " + newMissionStart.isoformat() print "New mission stop : " + newMissionStop.isoformat() if newMissionStop <= newMissionStart: print "Database is on date" exit(0) else: print "Database has to be updated" if newMissionStart.year != newMissionStop.year: print "2 files will be producted" newMissionxml1Start = datetime(newMissionStart.year,1,1,0,0) newMissionxml1Stop = datetime(newMissionStop.year,1,1,0,0) newMissionxml2Start = datetime(newMissionStop.year,1,1,0,0) newMissionxml2Stop = newMissionStop print 'XML 1 Start : ' + newMissionxml1Start.isoformat() print 'XML 1 Stop : ' + newMissionxml1Stop.isoformat() print 'XML 2 Start : ' + newMissionxml2Start.isoformat() print 'XML 2 Stop : ' + newMissionxml2Stop.isoformat() XMLfilename = prefix+'_'+str(newMissionxml1Start.year)+'.xml' writeXMLMission(XMLfilename,newMissionxml1Start.isoformat(),newMissionxml1Stop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam) XMLfilename = prefix+'_'+str(newMissionxml2Start.year)+'.xml' writeXMLMission(XMLfilename,newMissionxml2Start.isoformat(),newMissionxml2Stop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam) else: print "1 file will be producted" newMissionxmlStart = datetime(newMissionStart.year,1,1,0,0) newMissionxmlStop = newMissionStop print 'XML Start : ' + newMissionxmlStart.isoformat() print 'XML Stop : ' + newMissionxmlStop.isoformat() XMLfilename = prefix+'_'+str(newMissionxmlStart.year)+'.xml' writeXMLMission(XMLfilename,newMissionxmlStart.isoformat(),newMissionxmlStop.isoformat(),plasmaVI,tgtVI,tgtRParam,tgtLonParam)