-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform_adm.py
More file actions
66 lines (62 loc) · 1.87 KB
/
form_adm.py
File metadata and controls
66 lines (62 loc) · 1.87 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
59
60
61
62
63
64
65
66
import os
import re
import subprocess
import time
#put in a timestamp print here
import datetime
ts1 = time.time()
st1 = datetime.datetime.now().time()
fo = open("l4.json","r+")
strfile = fo.read()
fo.close()
print "ADM file creation started."
str2 = strfile.replace("[","{{")
str3 = str2.replace("]","}}")
str4 = str3.replace('"type":','"typee":')
str5 = str4.replace('s,"',',"')
print "Replacing analysed_sst"
str6 = str5.replace('}\n{"analysed_sst"',',"analysed_sst"')
print "Replacing analysed_error"
str7 = str6.replace('}\n{"analysis_error"',',"analysis_error"')
print "Replacing lat"
str8 = str7.replace('}\n{"lat"',',"lat"')
print "Replacing lon"
str9 = str8.replace('}\n{"lon"',',"lon"')
print "Replacing mask"
str10 = str9.replace('}\n{"mask"',',"mask"')
print "Replacing sea_ice_fraction"
str11 = str10.replace('}\n{"sea_ice_fraction"',',"sea_ice_fraction"')
print "Replacing time"
str12 = str11.replace('}\n{"time"',',"time"')
# check what we need to do for the closing braces of time
#str7 = str6.replace('}\n{"dimensions"','}}\n{"dimensions"') #this is to insert a closing brace for a record before the next dimension
print "uuid insertion underway"
sub = "{\"dimensions\":"
offset = 0
pos = str12.find(sub, offset)
while pos >= 0:
#generating uuid
p1 = subprocess.Popen(["uuidgen"], shell=False, stdout=subprocess.PIPE)
output1 = p1.stdout.read()
output1.replace('\n','')
#print "stored1:::"
#print output1
str12 = str12[:pos+1]+"\"fid\": \""+output1+"\","+str12[pos+1:]
pos = str12.find(sub, pos + 1)
#print pos
str13 = str12.replace('\n",','",')
#print str13
print "Writing to adm file"
fadm = open("newfile.adm", "w")
fadm.write(str13)
fadm.close()
print "Giving timestamps"
#put in ending timestamp here
st2 = datetime.datetime.now().time()
ts2 = time.time()
print "start time:"
print st1
print "end time:"
print st2
print "Time elapsed:"
print ts2 - ts1