mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
New improvements
This commit is contained in:
parent
7b13aefa44
commit
65bc0d9fd6
2
.gitignore
vendored
2
.gitignore
vendored
@ -10,3 +10,5 @@ starttime.txt
|
|||||||
overtime.txt
|
overtime.txt
|
||||||
highlighted
|
highlighted
|
||||||
proxy.txt
|
proxy.txt
|
||||||
|
out.txt
|
||||||
|
pocasi.txt
|
||||||
|
3
aaa
Normal file
3
aaa
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<html><head><meta charset="UTF-8"></head><body>/* !AMP */display:none}.ribbon-search-desktop .szn-input-with-suggest-list::-moz-placeholder{color:#757575;color:var(--ribbon-search-placeholder-color,#757575)}.ribbon-search-desktop .szn-input-with-suggest-list::placeholder{color:#757575;color:var(--ribbon-search-placeholder-color,#757575)}.ribbon-search-desktop .szn-suggest-list{font-family:Trivia Seznam,Helvetica,Arial,sans-serif}.szn-mobile-input-with-suggest-list--light{--color-button-primary:var(--ribbon-search-button-color,#c00)}.szn-mobile-input-with-suggest-list__button--icon-back{box-sizing:content-box;padding:0 10px;width:20px}.szn-mobile-input-with-suggest-list__button--icon-clear{box-sizing:content-box;padding:0 22px;width:12px}.szn-mobile-input-with-suggest-list__button--icon-search{box-sizing:content-box;padding:0 12px;width:20px}.szn-mobile-input-with-suggest-list__button--icon-back .ribbon-icon,.szn-mobile-input-with-suggest-list__button--icon-clear .ribbon-icon,.szn-mobile-input-with-suggest-list__button--icon-search .ribbon-icon{height:auto;width:100%}.szn-mobile-input-with-suggest-list__controlPanel__input-2,.szn-mobile-input-with-suggest-list__controlPanel__input-3{flex-grow:1;font-family:Arial,Helvetica,sans-serif;font-size:18px;width:auto}.ribbon-mobile-search__input{display:none}.ribbon-service{align-items:center;color:#000;color:var(--ribbon-service-color,#000);display:flex;flex-shrink:1;font-size:16px;height:32px}.ribbon-service,.ribbon-service:hover{text-decoration:none}.ribbon-service:hover,.ribbon-service:visited{color:#000;color:var(--ribbon-service-color,#000)}.ribbon-service__icon{display:none;height:32px;margin-right:8px;width:32px}.ribbon-service__icon-label{display:none;white-space:nowrap}.ribbon-service__logo{height:24px;max-height:32px;max-width:100%;min-height:24px;width:auto}.ribbon-service__logo--amp{max-width:160px}@media (min-width:600px){.ribbon-service__icon,.ribbon-service__icon-label{display:block}.ribbon-service__icon~.ribbon-service__logo{display:none}}.ribbon-seznam{align-items:center;color:#c00;color:var(--ribbon-seznam-color,#c00);display:flex;flex-shrink:0}.ribbon-seznam__link,.ribbon-seznam__link:hover,.ribbon-seznam__link:visited{color:#c00;color:var(--ribbon-seznam-color,#c00);text-decoration:none}.ribbon{background:#fff;background:var(--ribbon-background-color,#fff);box-shadow:0 0 2px 0 rgba(0,0,0,.1),0 8px 30px -12px rgba(0,0,0,.12);box-sizing:border-box;display:flex;height:56px;left:0;padding:0 16px;position:fixed;top:0;width:100%;z-index:9000}.ribbon--base{font-family:Trivia Seznam,Helvetica,Arial,sans-serif;font-size:14px}.ribbon--amp{box-shadow:none;overflow:hidden}.ribbon--blind{clip:rect(1px 1px 1px 1px);clip:rect(1px,1px,1px,1px);height:1px;overflow:hidden;width:1px}.ribbon--blind,.ribbon--unfixed{position:absolute}.ribbon--show-search:not(.ribbon--amp) .ribbon-seznam{visibility:hidden}@media (min-width:600px){.ribbon--show-search:not(.ribbon--amp) .ribbon-seznam{visibility:visible}}.ribbon__amp-search{background:#fff;background:var(--ribbon-background-color,#fff);box-shadow:0 0 2px 0 rgba(0,0,0,.1),0 8px 30px -12px rgba(0,0,0,.12);box-sizing:border-box;height:56px;left:0;padding:0 16px;position:fixed;top:0;width:100%;z-index:8999}.ribbon__menu-button{color:#909090;color:var(--ribbon-menu-button-color,#909090);margin-left:-8px;margin-right:8px}.ribbon__menu-button .ribbon-button__button{border-radius:4px;box-sizing:content-box;height:16px;padding:8px;width:16px}.ribbon__menu-button .ribbon-button__button:focus-visible{outline:2px solid #000}.ribbon__center,.ribbon__end,.ribbon__start{align-items:center;display:flex}.ribbon__center{flex-grow:1;min-width:0}.ribbon__end{flex-shrink:0;margin-left:16px}.ribbon__end--reversed{display:flex;flex-shrink:0}@media (min-width:600px){.ribbon:not(.ribbon--unfixed){padding-right:31px;width:100vw}.ribbon__end{margin-left:0}.ribbon__end--reversed{flex-direction:row-reverse}.ribbon__center{margin:0 16px}}.ribbon__end .ribbon-seznam{margin-right:16px}.ribbon__menu-button .ribbon-icon{height:12px}@media (min-width:600px){.ribbon .ribbon-seznam{margin-left:16px;margin-right:0}}</style><div <br>
|
||||||
|
|
||||||
|
</body></html>
|
@ -12,7 +12,7 @@ public class Main {
|
|||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
while (true) {
|
while (true) {
|
||||||
boolean test = false;
|
boolean test = true;
|
||||||
File starttimeTxt = new File("starttime.txt");
|
File starttimeTxt = new File("starttime.txt");
|
||||||
File overtimeTxt = new File("overtime.txt");
|
File overtimeTxt = new File("overtime.txt");
|
||||||
String lastStartTime = Utils.readTextFromFile(starttimeTxt);
|
String lastStartTime = Utils.readTextFromFile(starttimeTxt);
|
||||||
|
@ -78,6 +78,7 @@ public class TimeCalcWindow {
|
|||||||
JButton exitButton = new JButton("Exit");
|
JButton exitButton = new JButton("Exit");
|
||||||
|
|
||||||
//window.add(weatherButton);
|
//window.add(weatherButton);
|
||||||
|
|
||||||
window.add(jokeButton);
|
window.add(jokeButton);
|
||||||
window.add(restartButton);
|
window.add(restartButton);
|
||||||
window.add(exitButton);
|
window.add(exitButton);
|
||||||
|
@ -5,6 +5,7 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ public class Utils {
|
|||||||
//nothing to do
|
//nothing to do
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new String(Files.readAllBytes(file.toPath()));
|
return new String(Files.readAllBytes(file.toPath()), "UTF-8");
|
||||||
}
|
}
|
||||||
public static Color[] getRandomColors() {
|
public static Color[] getRandomColors() {
|
||||||
Color[] result = new Color[12];
|
Color[] result = new Color[12];
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
package rvc.timecalc;
|
package rvc.timecalc;
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import javax.swing.JEditorPane;
|
import javax.swing.JEditorPane;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.xml.transform.OutputKeys;
|
||||||
|
import javax.xml.transform.Source;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import javax.xml.transform.stream.StreamSource;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.StringReader;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.net.Authenticator;
|
import java.net.Authenticator;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.PasswordAuthentication;
|
import java.net.PasswordAuthentication;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -24,7 +28,7 @@ import java.net.URL;
|
|||||||
*/
|
*/
|
||||||
public class WeatherWindow extends JFrame {
|
public class WeatherWindow extends JFrame {
|
||||||
public WeatherWindow() {
|
public WeatherWindow() {
|
||||||
this.setSize(800, 600);
|
this.setSize(400, 300);
|
||||||
|
|
||||||
JEditorPane jep = new JEditorPane();
|
JEditorPane jep = new JEditorPane();
|
||||||
jep.setEditable(false);
|
jep.setEditable(false);
|
||||||
@ -32,107 +36,115 @@ public class WeatherWindow extends JFrame {
|
|||||||
scrollPane.setBounds(10, 10, 750, 550);
|
scrollPane.setBounds(10, 10, 750, 550);
|
||||||
getContentPane().add(scrollPane);
|
getContentPane().add(scrollPane);
|
||||||
|
|
||||||
File proxyTxt = new File("proxy.txt");
|
// File proxyTxt = new File("proxy.txt");
|
||||||
if(!proxyTxt.exists()) {
|
// if (!proxyTxt.exists()) {
|
||||||
jep.setText("Sorry, file proxy.txt was not found.");
|
// jep.setText("Sorry, file proxy.txt was not found.");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
final HttpProxy httpProxy;
|
// final HttpProxy httpProxy;
|
||||||
|
// try {
|
||||||
|
// httpProxy = new HttpProxy(proxyTxt);
|
||||||
|
// } catch (RuntimeException e) {
|
||||||
|
// jep.setContentType("text/html");
|
||||||
|
// jep.setText(e.getMessage());
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
httpProxy = new HttpProxy(proxyTxt);
|
String pocasiHtml = null;
|
||||||
} catch(RuntimeException e) {
|
File pocasiHtmlFile = new File("pocasi.html");
|
||||||
|
try {
|
||||||
|
pocasiHtml = downloadFile("https://pocasi.seznam.cz/praha");
|
||||||
|
pocasiHtml = prettyFormatXml(pocasiHtml, 4);
|
||||||
|
Utils.writeTextToFile(pocasiHtmlFile, pocasiHtml);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
pocasiHtml = pocasiHtmlFile.exists() ? Utils.readTextFromFile(pocasiHtmlFile) : "Sorry, pocasi.html was not found.";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
boolean ogm_detailed_forecast_Started = false;
|
||||||
|
for(String line:pocasiHtml.split("\\r?\\n|\\r")) {
|
||||||
|
|
||||||
|
if(line.contains("ogm-detailed-forecast")) {
|
||||||
|
ogm_detailed_forecast_Started = true;
|
||||||
|
}
|
||||||
|
if(ogm_detailed_forecast_Started && line.contains("<button aria-label=")) {
|
||||||
|
String l = line
|
||||||
|
.trim()
|
||||||
|
.replace("<button aria-label=\"","").split("class")[0];
|
||||||
|
sb.append(l);
|
||||||
|
sb.append("<br>\n\n");
|
||||||
|
System.out.println("Found another line");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pocasiHtml = sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
jep.setContentType("text/html");
|
jep.setContentType("text/html");
|
||||||
jep.setText(e.getMessage());
|
jep.setText("<html><head><meta charset=\"UTF-8\"></head><body>" + pocasiHtml + "</body></html>");
|
||||||
return;
|
Utils.writeTextToFile(new File("aaa"),"<html><head><meta charset=\"UTF-8\"></head><body>" + pocasiHtml + "</body></html>");
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
jep.setText(downloadFile3("https://pocasi.seznam.cz/praha",
|
|
||||||
httpProxy));
|
|
||||||
}catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
jep.setContentType("text/html");
|
jep.setContentType("text/html");
|
||||||
jep.setText("<html>Could not load " + e.getMessage() + "</html>");
|
jep.setText("<html>Could not load " + e.getMessage() + "</html>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String downloadFile2(String s, HttpProxy httpProxy) throws IOException {
|
public String downloadFile(String urlString)
|
||||||
|
|
||||||
Authenticator.setDefault(new Authenticator() {
|
|
||||||
protected PasswordAuthentication getPasswordAuthentication() {
|
|
||||||
return new PasswordAuthentication(httpProxy.getUser(),
|
|
||||||
httpProxy.getPassword().toCharArray());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Proxy proxy = new Proxy(
|
|
||||||
Proxy.Type.HTTP, new InetSocketAddress(httpProxy.getUrl(), Integer.valueOf(httpProxy.getPort())));
|
|
||||||
|
|
||||||
URL url = new URL(s);
|
|
||||||
System.getProperties().put( "proxySet", "true" );
|
|
||||||
|
|
||||||
System.setProperty("http.proxyHost", httpProxy.getUrl());
|
|
||||||
System.setProperty("http.proxyPort", httpProxy.getPort());
|
|
||||||
|
|
||||||
System.setProperty("http.proxyUser", httpProxy.getUser());
|
|
||||||
System.setProperty("http.proxyPassword", httpProxy.getPassword());
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
||||||
connection.setRequestMethod("GET");
|
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(
|
|
||||||
new InputStreamReader(connection.getInputStream()))) {
|
|
||||||
StringBuilder responseBuilder = new StringBuilder();
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
responseBuilder.append(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBuilder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public String downloadFile3(String s, HttpProxy httpProxy)
|
|
||||||
throws IOException {
|
throws IOException {
|
||||||
System.getProperties().put( "proxySet", "true" );
|
|
||||||
|
|
||||||
System.setProperty("http.proxyHost", httpProxy.getUrl());
|
URL url = new URL(urlString);
|
||||||
System.setProperty("http.proxyPort", httpProxy.getPort());
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.connect();
|
||||||
System.setProperty("http.proxyUser", httpProxy.getUser());
|
BufferedReader br = null;
|
||||||
System.setProperty("http.proxyPassword", httpProxy.getPassword());
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (conn.getResponseCode() == 200) {
|
||||||
String uri = s;
|
br = new BufferedReader(
|
||||||
URL url = new URL(uri);
|
new InputStreamReader(conn.getInputStream()));
|
||||||
|
String strCurrentLine;
|
||||||
Authenticator.setDefault(new Authenticator() {
|
while ((strCurrentLine = br.readLine()) != null) {
|
||||||
@Override
|
sb.append(strCurrentLine).append("\n");
|
||||||
public PasswordAuthentication getPasswordAuthentication() {
|
}
|
||||||
return new PasswordAuthentication(httpProxy.getUser(),
|
} else {
|
||||||
httpProxy.getPassword().toCharArray());
|
br = new BufferedReader(
|
||||||
}});
|
new InputStreamReader(conn.getErrorStream()));
|
||||||
|
String strCurrentLine;
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
while ((strCurrentLine = br.readLine()) != null) {
|
||||||
|
sb.append(strCurrentLine).append("\n");
|
||||||
//connection.setDoOutput(true);
|
}
|
||||||
connection.setRequestMethod("GET");
|
|
||||||
connection.setRequestProperty("Content-Type", "text/html");
|
|
||||||
connection.setRequestProperty("Accept", "text/html");
|
|
||||||
connection.setRequestProperty("Method", "GET");
|
|
||||||
connection.setRequestProperty("Encoding", "UTF-8");
|
|
||||||
connection.setReadTimeout(60000);
|
|
||||||
|
|
||||||
InputStream stream = connection.getInputStream();
|
|
||||||
|
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(stream);
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
|
||||||
StringBuilder content = new StringBuilder();
|
|
||||||
String line;
|
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
|
||||||
content.append(line + "\n");
|
|
||||||
}
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
bufferedReader.close();
|
private static String prettyFormatXml(final String input, final int indent) {
|
||||||
return content.toString();
|
try {
|
||||||
|
Source xmlInput = new StreamSource(new StringReader(input));
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
StreamResult xmlOutput = new StreamResult(stringWriter);
|
||||||
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
|
|
||||||
|
transformerFactory.setAttribute("indent-number", indent);
|
||||||
|
|
||||||
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||||
|
transformer.transform(xmlInput, xmlOutput);
|
||||||
|
return xmlOutput.getWriter().toString();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
try {
|
||||||
|
Source xmlInput = new StreamSource(new StringReader(input));
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
StreamResult xmlOutput = new StreamResult(stringWriter);
|
||||||
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||||
|
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));
|
||||||
|
transformer.transform(xmlInput, xmlOutput);
|
||||||
|
return xmlOutput.getWriter().toString();
|
||||||
|
} catch (Throwable t) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user