Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
Co-Authored-By: Jacob <net.jacobb@protonmail.com>
  • Loading branch information
BoyBACKS and jacobbvfx committed Sep 26, 2022
0 parents commit 71828e9
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
target
quote.json
quotes.txt
config.properties
dependency-reduced-pom.xml
74 changes: 74 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.boybacks</groupId>
<artifactId>MotenoServer</artifactId>
<version>1.0</version>

<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}-${project.version}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>net.boybacks.main.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
</build>
</project>
118 changes: 118 additions & 0 deletions src/main/java/net/boybacks/main/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package net.boybacks.main;

import org.json.simple.JSONObject;

import java.io.*;
import java.util.*;

public class Main {

static File quotes = new File("quotes.txt");
static List<String> quotesList = new ArrayList<String>();
static int quoteCount = 0;

public static void main(String[] args) throws IOException {
saveQuoteCount();
quoteManager();
quoteReset();
}


public static void quoteManager() throws IOException {
FileInputStream fstream_school = new FileInputStream(quotes);
DataInputStream data_input = new DataInputStream(fstream_school);
BufferedReader buffer = new BufferedReader(new InputStreamReader(data_input));

String str_line;

while ((str_line = buffer.readLine()) != null) {
str_line = str_line.trim();
if ((str_line.length() != 0)) {
quotesList.add(str_line);
}
}
}

static Properties prop = new Properties();

public static void saveQuoteCount() {
File f = new File("config.properties");
if(!f.exists() && !f.isDirectory()) {
System.out.println("[Test Log (File Creation)] File is already been created!");
saveManager();
}
Properties properties = new Properties();
InputStream input = null;
try {
input = new FileInputStream("config.properties");
} catch (FileNotFoundException e) {
System.out.println("[Test Log (File Read)] Ooooooooooops Error there is no such file config.properties...");
e.printStackTrace();
}
try {
properties.load(input);
} catch (IOException e) {
System.out.println("[Test Log (File Read)] Ooooooooooops Error with input...");
e.printStackTrace();
}
quoteCount = Integer.parseInt((String) properties.get("quoteCount"));
}

public static void JSONQuoteSaver() {
String quote = quotesList.get(quoteCount);
String[] text = quote.split(" = ");
String path = "quote.json";

JSONObject json = new JSONObject();
json.put("quote", text[0]);
json.put("author", text[1]);

try (FileWriter file = new FileWriter(path)) {
file.write(json.toJSONString());
} catch (IOException e) {
e.printStackTrace();
}

System.out.println(text[0]);
System.out.println(text[1]);
}

public static void saveManager() {
try {
prop.setProperty("quoteCount", String.valueOf(quoteCount));

prop.store(new FileOutputStream("config.properties"), null);
System.out.println("[Test Log (File Creation)] Quotes score has been saved!");

} catch (IOException ex) {
System.out.println("[Test Log (File Creation)] Ooooooooooops Error...");
ex.printStackTrace();
}
}

public static void quoteReset() {
TimerTask task = new TimerTask() {
@Override
public void run() {
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
//int second = calendar.get(Calendar.SECOND);
if (hour == 0 && minute == 1) {
System.out.println("Reset dziennego cytatu!");
JSONQuoteSaver();
quoteCount++;
saveManager();
}
else {
System.out.println("Nie ma odpowiedniego czasu!");
}
}
};

Timer timer = new Timer();

timer.schedule(task, 1000, 60*1000);

}
}

0 comments on commit 71828e9

Please sign in to comment.