-
Notifications
You must be signed in to change notification settings - Fork 0
/
s123_functions.js
126 lines (98 loc) · 3.42 KB
/
s123_functions.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//Functions to return air temperature, weather condition, water temperature, and tide level to Survey123 form
/////////////////////
//WEATHER FUNCTIONS//
/////////////////////
function runWeatherCalcs(key) {
//if (location===""){
// return "";
// }
var xmlhttp = new XMLHttpRequest();
var url = "https://api.openweathermap.org/data/2.5/weather?lat=32.8474&lon=-117.2786&units=imperial&apikey=" + key;
console.log(key);
console.log(url);
xmlhttp.open("GET", url, false);
xmlhttp.send();
if (xmlhttp.status != 200) {
return "Error1"
} else {
var responseJSON = JSON.parse(xmlhttp.responseText)
if (responseJSON.error) {
return responseJSON.error;
} else {
if (responseJSON) {
var city = responseJSON.name
var weather = responseJSON.weather[0].main
var wx_description = responseJSON.weather[0].description
var weatherCode = responseJSON.weather[0].id
var temperature = responseJSON.main.temp
var min = responseJSON.main.temp_min
var max = responseJSON.main.temp_max
var humidity = responseJSON.main.humidity
var pressure = responseJSON.main.pressure
var windSpeed = responseJSON.wind.speed
var windDegrees = responseJSON.wind.deg
var windGust = responseJSON.wind.gust
console.log(responseJSON.name)
//console.log("JSON data:", responseJSON.stringify(json, undefined, 2));
return responseJSON;
}
else {
return "";
}
}
}
}
//////////////
//WATER TEMP//
//////////////
function runWaterTemp() {
//var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xmlhttp = new XMLHttpRequest();
var url = "https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?date=latest&station=9410230&product=water_temperature&datum=MSL&time_zone=lst_ldt&units=english&format=json";
console.log(url);
xmlhttp.open("GET", url, false);
xmlhttp.send();
if (xmlhttp.status != 200) {
return "Error1"
} else {
var responseJSON = JSON.parse(xmlhttp.responseText)
if (responseJSON.error) {
return responseJSON.error;
} else {
if (responseJSON) {
var waterTemp = responseJSON.data[0].v;
return waterTemp;
}
else {
return "";
}
}
}
}
///////////////
//WATER LEVEL//
///////////////
function runWaterLevel() {
//var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xmlhttp = new XMLHttpRequest();
var url = "https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?date=latest&station=9410230&product=water_level&datum=MSL&time_zone=lst_ldt&units=english&format=json";
console.log(url);
xmlhttp.open("GET", url, false);
xmlhttp.send();
if (xmlhttp.status != 200) {
return "Error1"
} else {
var responseJSON = JSON.parse(xmlhttp.responseText)
if (responseJSON.error) {
return responseJSON.error;
} else {
if (responseJSON) {
var waterLevel = responseJSON.data[0].v;
return waterLevel;
}
else {
return "";
}
}
}
}