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.
45 lines
1.6 KiB
Java
45 lines
1.6 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;
|
|
|
|
//Informieren Sie sich über die bereitgestellten Links (oder eigene Recherche) zu folgenden Themen:
|
|
//JSON
|
|
//URL-Abruf mit Java
|
|
//JSON-Verarbeitung mit Java
|
|
//Dateiverarbeitung mit Java
|
|
//Suchen Sie sich von der Seite http://deutschland.maps.sensor.community/ einen Sensor aus
|
|
//Rufen Sie alle 2,5 Minuten mit Java die Sensordaten "ihres" Sensors ab
|
|
//Speichern Sie nur die aktuelle Messung aus der Abfrage in einer Datei mit dem Namen <Land>-<SensorID>-<timestamp>.json
|
|
//Wählen Sie einen objektorientierten Ansatz für die Umsetzung.
|
|
|
|
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);
|
|
}
|
|
}
|