-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBurnDayStatus.gs
96 lines (76 loc) · 2.53 KB
/
BurnDayStatus.gs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Read values coming from the form
*/
function BurnDayStatusEdit(e) {
Logger.log("my edit");
var ss = SpreadsheetApp.getActiveSheet();
if (ss.getName().equals("Morning Report")) {
<<<<<<< HEAD
// get range of values that contain string from admin report
=======
>>>>>>> bac1fe6903aee073640145fdf0aff7144a3cb085
var coastalBurnStatusRange = ss.getRange("AC5:AG5");
var inlandBurnStatusRange = ss.getRange("AC6:AG6");
var d = new Date();
<<<<<<< HEAD
postToCartoDB(coastalBurnStatusRange.getValue(), inlandBurnStatusRange.getValue(), d.toLocaleDateString());
=======
postToCartoDB(coastalBurnStatusRange.getValue(), inlandBurnStatusRange.getValue(), d.toLocaleString());
>>>>>>> bac1fe6903aee073640145fdf0aff7144a3cb085
}
}
/**
* Insert color into CartoDB using sql http
*/
function postToCartoDB(coastal, inland, timestamp) {
Logger.log("posting to CartoDB");
/**
* Keep your key private!
*/
var cartodb_host = "slu.cartodb.com"; //Your CartoDB domain
var cartodb_api_key = ""; //Your CartoDB API KEY
Logger.log("coastal: " + coastal);
Logger.log("inland: " + inland);
var inlandStatus
var coastalStatus
if (inland == "PERMISSIVE")
inlandStatus = "TRUE"
else if (inland == "NEGATIVE")
inlandStatus = "FALSE"
else
inlandStatus = "UNKNOWN"
if (coastal == "PERMISSIVE")
coastalStatus = "TRUE"
else if (coastal == "NEGATIVE")
coastalStatus = "FALSE"
else
coastalStatus = "UNKNOWN"
var timeStamp = timestamp.replace("'","''");
/**
* Here is the INSERT statement
*/
var query = "UPDATE inland SET burn_status='"+inlandStatus+"', burn_status_timestamp='" + timeStamp +"'";
var query2 = "UPDATE coastal SET burn_status='"+coastalStatus+"', burn_status_timestamp='" + timeStamp +"'";
Logger.log("SQL: "+query);
Logger.log("SQL: "+query2);
/**
* Assemble the POST parameters
*/
var options = {
"method" : "post",
"payload" : {q:query,api_key:cartodb_api_key}
};
var options2 = {
"method" : "post",
"payload" : {q:query2,api_key:cartodb_api_key}
};
/**
* Ship It
*/
var response=UrlFetchApp.fetch("https://"+cartodb_host+"/api/v1/sql", options);
var respObj=Utilities.jsonParse(response.getContentText());
Logger.log("CDB call result: "+response.getContentText());
var response2 = UrlFetchApp.fetch("https://"+cartodb_host+"/api/v1/sql", options2);
var respObj2=Utilities.jsonParse(response2.getContentText());
Logger.log("CDB call result: "+response2.getContentText());
}