You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
Java
35 lines
1.1 KiB
Java
package sh.adb.sensorCommunityAPI;
|
|
|
|
import org.json.simple.JSONArray;
|
|
import org.json.simple.JSONObject;
|
|
import org.json.simple.parser.ParseException;
|
|
|
|
import java.io.IOException;
|
|
|
|
public class Main {
|
|
public static void main(String[] args) throws IOException, ParseException {
|
|
String basePath = "./data";
|
|
|
|
APIPaser api = new APIPaser("https://data.sensor.community/airrohr/v1/sensor/35943/");
|
|
JSONArray APIData = api.getJSONObject();
|
|
JSONObject entry = (JSONObject) APIData.get(0);
|
|
System.out.println("entry => ");
|
|
System.out.println(entry);
|
|
|
|
//get country
|
|
String country = ((JSONObject) entry.get("location")).get("country").toString();
|
|
|
|
//get sensorID
|
|
String sensorID = String.valueOf(
|
|
((JSONObject) entry.get("sensor")).get("id")
|
|
);
|
|
|
|
//get timestamp
|
|
String timestamp = (String) entry.get("timestamp");
|
|
|
|
String path = basePath + country + "-" + sensorID + "-" + timestamp + ".json";
|
|
DataStore store = new DataStore();
|
|
store.storeJSON(path, entry);
|
|
}
|
|
}
|