diff options
| -rw-r--r-- | .DS_Store | bin | 0 -> 6148 bytes | |||
| -rw-r--r-- | .idea/.gitignore | 3 | ||||
| -rw-r--r-- | .idea/artifacts/cfetch_jar.xml | 9 | ||||
| -rw-r--r-- | .idea/libraries/json_java.xml | 9 | ||||
| -rw-r--r-- | .idea/misc.xml | 6 | ||||
| -rw-r--r-- | .idea/modules.xml | 8 | ||||
| -rw-r--r-- | .idea/uiDesigner.xml | 124 | ||||
| -rw-r--r-- | README.md | 22 | ||||
| -rw-r--r-- | cfetch.iml | 12 | ||||
| -rw-r--r-- | json-java.jar | bin | 0 -> 59893 bytes | |||
| -rw-r--r-- | out/artifacts/cfetch_jar/cfetch.jar | bin | 0 -> 62049 bytes | |||
| -rw-r--r-- | out/production/cfetch/META-INF/MANIFEST.MF | 3 | ||||
| -rw-r--r-- | out/production/cfetch/cfetch/main.class | bin | 0 -> 3832 bytes | |||
| -rw-r--r-- | src/META-INF/MANIFEST.MF | 3 | ||||
| -rw-r--r-- | src/cfetch/main.java | 59 |
15 files changed, 258 insertions, 0 deletions
diff --git a/.DS_Store b/.DS_Store Binary files differnew file mode 100644 index 0000000..d70f00f --- /dev/null +++ b/.DS_Store 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 @@ +<component name="ArtifactManager"> + <artifact type="jar" name="cfetch:jar"> + <output-path>$PROJECT_DIR$/out/artifacts/cfetch_jar</output-path> + <root id="archive" name="cfetch.jar"> + <element id="module-output" name="cfetch" /> + <element id="extracted-dir" path="$PROJECT_DIR$/json-java.jar" path-in-jar="/" /> + </root> + </artifact> +</component>
\ 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 @@ +<component name="libraryTable"> + <library name="json-java"> + <CLASSES> + <root url="jar://$PROJECT_DIR$/json-java.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> +</component>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/out" /> + </component> +</project>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/cfetch.iml" filepath="$PROJECT_DIR$/cfetch.iml" /> + </modules> + </component> +</project>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Palette2"> + <group name="Swing"> + <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> + </item> + <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> + <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> + <initial-values> + <property name="text" value="Button" /> + </initial-values> + </item> + <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="RadioButton" /> + </initial-values> + </item> + <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="CheckBox" /> + </initial-values> + </item> + <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="Label" /> + </initial-values> + </item> + <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> + <preferred-size width="-1" height="20" /> + </default-constraints> + </item> + <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> + </item> + </group> + </component> +</project>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="library" name="json-java" level="project" /> + </component> +</module>
\ No newline at end of file diff --git a/json-java.jar b/json-java.jar Binary files differnew file mode 100644 index 0000000..6b5b777 --- /dev/null +++ b/json-java.jar diff --git a/out/artifacts/cfetch_jar/cfetch.jar b/out/artifacts/cfetch_jar/cfetch.jar Binary files differnew file mode 100644 index 0000000..d4e4063 --- /dev/null +++ b/out/artifacts/cfetch_jar/cfetch.jar 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 Binary files differnew file mode 100644 index 0000000..5283284 --- /dev/null +++ b/out/production/cfetch/cfetch/main.class 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<String> response = client.send(request, + HttpResponse.BodyHandlers.ofString()); + + String jsonString = response.body(); + return new JSONObject(jsonString); + } +}
\ No newline at end of file |
