Blame view

Bin.py/makeRequest.py 3.5 KB
90a0ee4e   Elena.Budnik   python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# 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
47081b7a   Elena.Budnik   work
22
checkArgs(5, 'Usage : python makeRequest.py (tgt_vi) (sw_vi) (TaoStopTime) (SwStopTime)')
90a0ee4e   Elena.Budnik   python
23

47081b7a   Elena.Budnik   work
24
25
26
prefix = sys.argv[1].split("_")[0] 
tgtVI = sys.argv[1]
plasmaVI = sys.argv[2] 
90a0ee4e   Elena.Budnik   python
27
28

# In[4]:
47081b7a   Elena.Budnik   work
29
omniStopTime = datetime.strptime(sys.argv[4], '%Y-%m-%dT%H:%M:%S.000Z')
90a0ee4e   Elena.Budnik   python
30
31
32
print  omniStopTime

# In[5]:
47081b7a   Elena.Budnik   work
33
missionStopTime = datetime.strptime(sys.argv[3], '%Y-%m-%dT%H:%M:%S.000Z')
90a0ee4e   Elena.Budnik   python
34
35
36
37
38
print  missionStopTime

# In[6]:

def writeXMLMission(XMLfilename,startTime,stopTime,plasmaVI,tgtVI,tgtRParam,tgtLonParam):
6ed9c6e8   Elena.Budnik   makedir if needed
39
40
41
    if not os.path.exists(os.getenv('REQ')):
	 os.makedirs(os.getenv('REQ'))
		    
90a0ee4e   Elena.Budnik   python
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
    with open(os.getenv('REQ')+'/'+XMLfilename, "w") as xml:
        xml.write('<?xml version="1.0" ?>\n')
        xml.write('<MISSION>\n')
        xml.write('\t<START>'+startTime+'</START>\n')
        xml.write('\t<STOP>'+stopTime+'</STOP>\n')
        xml.write('\t<PLASMA_VI>'+plasmaVI+'</PLASMA_VI>\n')
        xml.write('\t<SOURCE_VI>earth_orb_all</SOURCE_VI>\n')
        xml.write('\t<SOURCE_R_PARAM>R</SOURCE_R_PARAM>\n')
        xml.write('\t<SOURCE_LON_PARAM>LON_HCI</SOURCE_LON_PARAM>\n')
        xml.write('\t<TARGET_VI>'+tgtVI+'</TARGET_VI>\n')
        xml.write('\t<TARGET_R_PARAM>'+tgtRParam+'</TARGET_R_PARAM>\n')
        xml.write('\t<TARGET_LON_PARAM>'+tgtLonParam+'</TARGET_LON_PARAM>\n')
        xml.write('</MISSION>')
    xml.close()


# In[8]:

8bc6888e   Elena.Budnik   R variable name c...
60
61
62
tgtRParam = 'R_HCI'
if tgtVI == 'p67_orb_all':
	tgtRParam = 'R'
45252157   Elena.Budnik   work
63
	
90a0ee4e   Elena.Budnik   python
64
65
66
67
68
69
70
71
72
73
74
75
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"
    
47081b7a   Elena.Budnik   work
76
if newMissionStart.year != newMissionStop.year and plasmaVI != 'ace_swepam_real':
90a0ee4e   Elena.Budnik   python
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    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"
47081b7a   Elena.Budnik   work
92
93
94
95
    if plasmaVI == "ace_swepam_real":
	   newMissionxmlStart = datetime(newMissionStart.year,newMissionStart.month,newMissionStart.day,0,0)  	    
    else:	    
	   newMissionxmlStart = datetime(newMissionStart.year,1,1,0,0)
90a0ee4e   Elena.Budnik   python
96
97
98
99
100
    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)