Compare commits

..

No commits in common. "b56704e2343044b4986a30044a2a3f1e1837b354" and "1418e432b5772b4ddf72f2e71f50dc3aa5fdd4e3" have entirely different histories.

5 changed files with 7 additions and 37 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
./config.json

View File

@ -1,5 +0,0 @@
{
"storePath": "./data/",
"apiURL": "https://data.sensor.community/airrohr/v1/sensor/35943/",
"interval": 150
}

View File

@ -2,11 +2,14 @@ package sh.adb.sensorCommunityAPI;
import org.apache.http.client.methods.HttpGet;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.IOException;
import java.net.MalformedURLException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
@ -14,7 +17,7 @@ import org.json.simple.parser.ParseException;
public class APIParser {
String url;
public APIParser(String urlString) {
public APIParser(String urlString) throws MalformedURLException {
this.url = urlString;
}
public JSONArray getJSONObject() throws IOException, ParseException {

View File

@ -1,9 +1,7 @@
package sh.adb.sensorCommunityAPI;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
@ -11,25 +9,13 @@ public class DataStore {
public boolean storeJSON(String path, JSONObject json) throws IOException {
FileWriter fw = new FileWriter(path);
try {
System.out.println("store data to: " + path + " => ");
System.out.println(json.toString());
fw.write(json.toString());
fw.close();
return true;
}catch (IOException e){
System.out.println("error while soring data to: " + path);
System.out.println("error wile soring data to: " + path);
}
return false;
}
public JSONObject readJSON(String path){
JSONParser parser = new JSONParser();
try {
System.out.println("reading file: " + path);
return (JSONObject) parser.parse(new FileReader(path));
} catch (Exception e) {
System.out.println("error while reading file: " + path);
}
return null;
}
}

View File

@ -1,23 +1,10 @@
package sh.adb.sensorCommunityAPI;
import org.json.simple.JSONObject;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
DataStore store = new DataStore();
JSONObject config = store.readJSON("config.json");
if (config == null){
config = store.readJSON("example.config.json");
}
DataStoreBot bot = new DataStoreBot(
config.get("storePath").toString(),
config.get("apiURL").toString()
);
bot.setInterval(Integer.parseInt(
config.get("interval").toString()
));
DataStoreBot bot = new DataStoreBot("./data/", "https://data.sensor.community/airrohr/v1/sensor/35943/");
bot.setInterval(150);
}
}