Compare commits
No commits in common. "b56704e2343044b4986a30044a2a3f1e1837b354" and "1418e432b5772b4ddf72f2e71f50dc3aa5fdd4e3" have entirely different histories.
b56704e234
...
1418e432b5
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
./config.json
|
|
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"storePath": "./data/",
|
|
||||||
"apiURL": "https://data.sensor.community/airrohr/v1/sensor/35943/",
|
|
||||||
"interval": 150
|
|
||||||
}
|
|
@ -2,11 +2,14 @@ package sh.adb.sensorCommunityAPI;
|
|||||||
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
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.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
@ -14,7 +17,7 @@ import org.json.simple.parser.ParseException;
|
|||||||
|
|
||||||
public class APIParser {
|
public class APIParser {
|
||||||
String url;
|
String url;
|
||||||
public APIParser(String urlString) {
|
public APIParser(String urlString) throws MalformedURLException {
|
||||||
this.url = urlString;
|
this.url = urlString;
|
||||||
}
|
}
|
||||||
public JSONArray getJSONObject() throws IOException, ParseException {
|
public JSONArray getJSONObject() throws IOException, ParseException {
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package sh.adb.sensorCommunityAPI;
|
package sh.adb.sensorCommunityAPI;
|
||||||
|
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -11,25 +9,13 @@ public class DataStore {
|
|||||||
public boolean storeJSON(String path, JSONObject json) throws IOException {
|
public boolean storeJSON(String path, JSONObject json) throws IOException {
|
||||||
FileWriter fw = new FileWriter(path);
|
FileWriter fw = new FileWriter(path);
|
||||||
try {
|
try {
|
||||||
System.out.println("store data to: " + path + " => ");
|
|
||||||
System.out.println(json.toString());
|
System.out.println(json.toString());
|
||||||
fw.write(json.toString());
|
fw.write(json.toString());
|
||||||
fw.close();
|
fw.close();
|
||||||
return true;
|
return true;
|
||||||
}catch (IOException e){
|
}catch (IOException e){
|
||||||
System.out.println("error while soring data to: " + path);
|
System.out.println("error wile soring data to: " + path);
|
||||||
}
|
}
|
||||||
return false;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,23 +1,10 @@
|
|||||||
package sh.adb.sensorCommunityAPI;
|
package sh.adb.sensorCommunityAPI;
|
||||||
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
DataStore store = new DataStore();
|
DataStoreBot bot = new DataStoreBot("./data/", "https://data.sensor.community/airrohr/v1/sensor/35943/");
|
||||||
JSONObject config = store.readJSON("config.json");
|
bot.setInterval(150);
|
||||||
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()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user