From a6227e2c86763109694c82c79662244160cf9a42 Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Wed, 13 Apr 2022 23:14:59 -0400 Subject: Initial Commit --- .DS_Store | Bin 0 -> 6148 bytes .idea/.gitignore | 3 + .idea/artifacts/cfetch_jar.xml | 9 +++ .idea/libraries/json_java.xml | 9 +++ .idea/misc.xml | 6 ++ .idea/modules.xml | 8 ++ .idea/uiDesigner.xml | 124 +++++++++++++++++++++++++++++ README.md | 22 +++++ cfetch.iml | 12 +++ json-java.jar | Bin 0 -> 59893 bytes out/artifacts/cfetch_jar/cfetch.jar | Bin 0 -> 62049 bytes out/production/cfetch/META-INF/MANIFEST.MF | 3 + out/production/cfetch/cfetch/main.class | Bin 0 -> 3832 bytes src/META-INF/MANIFEST.MF | 3 + src/cfetch/main.java | 59 ++++++++++++++ 15 files changed, 258 insertions(+) create mode 100644 .DS_Store create mode 100644 .idea/.gitignore create mode 100644 .idea/artifacts/cfetch_jar.xml create mode 100644 .idea/libraries/json_java.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 README.md create mode 100644 cfetch.iml create mode 100644 json-java.jar create mode 100644 out/artifacts/cfetch_jar/cfetch.jar create mode 100644 out/production/cfetch/META-INF/MANIFEST.MF create mode 100644 out/production/cfetch/cfetch/main.class create mode 100644 src/META-INF/MANIFEST.MF create mode 100644 src/cfetch/main.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..d70f00f Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/artifacts/cfetch_jar.xml b/.idea/artifacts/cfetch_jar.xml new file mode 100644 index 0000000..ff7007a --- /dev/null +++ b/.idea/artifacts/cfetch_jar.xml @@ -0,0 +1,9 @@ + + + $PROJECT_DIR$/out/artifacts/cfetch_jar + + + + + + \ No newline at end of file diff --git a/.idea/libraries/json_java.xml b/.idea/libraries/json_java.xml new file mode 100644 index 0000000..e7c7445 --- /dev/null +++ b/.idea/libraries/json_java.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..122ead2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..77bb558 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# cfetch +This is a small program written in java to get the current liturgical day for the +Catholic liturgical calendar. + +The program is reliant on the api [liturgical Calendar](http://calapi.inadiutorium.cz/). The program implements the [JSON-java](https://github.com/stleary/JSON-java) library to parse the JSON output. + +## Building + +Cfetch is written in IntelliJ IDEA and thus should be built using it. To build a jar file, in IDEA click on the build menu and click on build artifacts. + +## Running + +To run cfetch, run the following command or put it in a shell script: +``` +java -jar cfetch.jar +``` + +To run with a different day than today, run: +``` +java -jar cfetch.jar 2022/12/01 +``` +The date must be formatted as YYYY/MM/DD. \ No newline at end of file diff --git a/cfetch.iml b/cfetch.iml new file mode 100644 index 0000000..73a1956 --- /dev/null +++ b/cfetch.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/json-java.jar b/json-java.jar new file mode 100644 index 0000000..6b5b777 Binary files /dev/null and b/json-java.jar differ diff --git a/out/artifacts/cfetch_jar/cfetch.jar b/out/artifacts/cfetch_jar/cfetch.jar new file mode 100644 index 0000000..d4e4063 Binary files /dev/null and b/out/artifacts/cfetch_jar/cfetch.jar differ diff --git a/out/production/cfetch/META-INF/MANIFEST.MF b/out/production/cfetch/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8d55dcf --- /dev/null +++ b/out/production/cfetch/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: cfetch.main + diff --git a/out/production/cfetch/cfetch/main.class b/out/production/cfetch/cfetch/main.class new file mode 100644 index 0000000..5283284 Binary files /dev/null and b/out/production/cfetch/cfetch/main.class differ diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8d55dcf --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: cfetch.main + diff --git a/src/cfetch/main.java b/src/cfetch/main.java new file mode 100644 index 0000000..fccb005 --- /dev/null +++ b/src/cfetch/main.java @@ -0,0 +1,59 @@ +package cfetch; + +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import org.json.*; + +public class main { + public static void main(String[] args) throws IOException, InterruptedException { + /* System date is required to make the API call use local date not server date */ + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + LocalDateTime now = LocalDateTime.now(); + JSONObject obj; + + if (args.length > 0) { + obj = request("http://calapi.inadiutorium.cz/api/v0/en/calendars/general-en/" + + args[0]); + } else { + obj = request("http://calapi.inadiutorium.cz/api/v0/en/calendars/general-en/" + + dtf.format(now)); + } + + JSONArray arr = obj.getJSONArray("celebrations"); + + String date, season, title, color, celebration, output; + + date = obj.getString("date"); + season = obj.getString("season"); + title = arr.getJSONObject(0).getString("title"); + color = arr.getJSONObject(0).getString("colour"); + + output = date + "\nToday: " + title + "\nSeason: " + season + "\nColor: " + color; + + if (arr.length() > 1) { + celebration = arr.getJSONObject(1).getString("title"); + output += "\nCelebration: " + celebration; + } + + System.out.println(output); + } + + private static JSONObject request(String url) throws IOException, InterruptedException { + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(url)) + .build(); + + HttpResponse response = client.send(request, + HttpResponse.BodyHandlers.ofString()); + + String jsonString = response.body(); + return new JSONObject(jsonString); + } +} \ No newline at end of file -- cgit v1.2.3