From 8d53c94fc093343f3e50036773d1081480f75904 Mon Sep 17 00:00:00 2001 From: Random Email Date: Sun, 27 Nov 2016 17:39:12 +0000 Subject: [PATCH] OKOKKOKOKO --- pom.xml | 2 +- src/main/java/domain/tld/App.java | 103 ++++++++--------------------- src/main/java/domain/tld/Calendar.java | 91 +++++++++++++++++++++++++ src/main/java/domain/tld/Commands.java | 84 +++++++++++++++++++++++ src/main/java/domain/tld/Curl.java | 106 ------------------------------ src/main/java/domain/tld/CurlWrapper.java | 36 ---------- 6 files changed, 203 insertions(+), 219 deletions(-) rewrite src/main/java/domain/tld/App.java (89%) create mode 100644 src/main/java/domain/tld/Calendar.java create mode 100644 src/main/java/domain/tld/Commands.java delete mode 100644 src/main/java/domain/tld/Curl.java delete mode 100644 src/main/java/domain/tld/CurlWrapper.java diff --git a/pom.xml b/pom.xml index d5035f6..2dd98b7 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ test - oopdp.igg.biz + biz.igg.oopdp ff-tools 1.0-SNAPSHOT jar diff --git a/src/main/java/domain/tld/App.java b/src/main/java/domain/tld/App.java dissimilarity index 89% index 200283a..fcfcece 100644 --- a/src/main/java/domain/tld/App.java +++ b/src/main/java/domain/tld/App.java @@ -1,76 +1,27 @@ -package domain.tld; - -import java.io.IOException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.net.MalformedURLException; - -/** - * Hello world! - * - */ -public class App -{ - - public static String torUrl = "https://check.torproject.org"; - - public static void main( String[] args ) - { - try { - System.out.println(torStatus(get(torUrl))); - } - catch(Exception e){ - - } - } - - public static String get(String url) throws MalformedURLException, IOException - { - return CurlWrapper.getWithProxy(torUrl); - } - - public static String checkTorUsage(String output) { - String ext = ""; - Pattern pattern = Pattern.compile("\\s+(.+?)\\s+"); - Matcher matcher = pattern.matcher(output); - matcher.find(); - int m = matcher.groupCount(); - if(m == 1){ - ext = matcher.group(1).trim(); - } - return ext; - } - - public static String getTor() { - String output = ""; - try { - output = CurlWrapper.get(torUrl); - } - catch (IOException ex) { - System.out.println(ex); - System.exit(-1); - } - return output; - } - - public static String checkTorIp(String output) { - String ext = ""; - Pattern pattern = Pattern.compile("

.*(.+?)

"); - Matcher matcher = pattern.matcher(output); - matcher.find(); - int m = matcher.groupCount(); - if(m == 1){ - ext = matcher.group(1).trim(); - } - return ext; - } - - public static String torStatus() { - String output = getTor(); - return torStatus(output); - } - - public static String torStatus(String output){ - return checkTorIp(output)+" - "+checkTorUsage(output); - } -} +package domain.tld; + +/** + * Hello world! + * + */ +public class App +{ + + public static void main( String[] args ) + { + String start = "2016-11-27"; + String end = "2016-11-30"; + String period = "3"; + if(args.length == 3){ + start = args[0]; + end = args[1]; + period = args[2]; + } + try { + System.out.println(Calendar.getCalendar(start, end, period)); + } + catch(Exception e){ + + } + } +} diff --git a/src/main/java/domain/tld/Calendar.java b/src/main/java/domain/tld/Calendar.java new file mode 100644 index 0000000..523cec4 --- /dev/null +++ b/src/main/java/domain/tld/Calendar.java @@ -0,0 +1,91 @@ +package domain.tld; + + +import biz.igg.oopdp.ff.tools.curl.KeyValueList; +import biz.igg.oopdp.ff.tools.curl.KeyValue; +import java.io.IOException; +import biz.igg.oopdp.ff.tools.calendar.CalendarMap; +import biz.igg.oopdp.ff.tools.calendar.MyFxBook; +import biz.igg.oopdp.ff.tools.curl.CurlWrapper; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Random; + +public class Calendar { + + + public static String randIntSequence(int min, int max, int size) { + + String ret = "0."; + Random rand = new Random(); + int randomNum; + for(int i = 0; i < size; i++) + { + randomNum = rand.nextInt((max - min) + 1) + min; + ret += Integer.toString(randomNum); + } + return ret; + } + + public static KeyValueList calParams(String start, String end, String period) + { + start += "%2000:00"; + end += "%2000:00"; + KeyValueList params = new KeyValueList(); + params.add(new KeyValue("min", "")); + params.add(new KeyValue("start", start)); + params.add(new KeyValue("end", end)); + params.add(new KeyValue("filter", "0-1-2-3_PEI-CNY-JPY-CZK-MXN-CAD-ZAR-AUD-NZD-CLP-GBP-NOK-ISK-CHF-RUB-ANG-ARS-INR-EEK-IDR-TRY-ROL-SGD-QAR-HKD-COP-DKK-SEK-BRL-EUR-HUF-PLN-USD-KRW-KPW")); + params.add(new KeyValue("show", "show")); + params.add(new KeyValue("type", "cal")); + params.add(new KeyValue("bubble", "true")); + params.add(new KeyValue("calPeriod", period)); + params.add(new KeyValue("rand", randIntSequence(0,9,17))); + return params; + } + + private static CalendarMap parseOutput(String content) throws IOException + { + MyFxBook fx = new MyFxBook(content); + content = fx.cleanse(content); + content = fx.extractCalendar(content); + content = fx.fixSelfClosingTags(content); + fx.parse(content); + CalendarMap cm = fx.getCalendarMap(); + return cm; + } + + + public static String getQuery(KeyValueList kvl) throws UnsupportedEncodingException + { + StringBuilder result = new StringBuilder(); + boolean first = true; + for (KeyValue pair : kvl) + { + if (first) + first = false; + else + result.append("&"); + + result.append(pair.key); + result.append("="); + result.append(pair.value); + } + return result.toString(); + } + public static CalendarMap getCalendar(String start, String end, String period) throws Exception + { + KeyValueList kv = calParams(start, end, period); + System.out.println(start+"|"+end+"|"+period); + String params = getQuery(kv); + String serviceUrl = "http://www.myfxbook.com/calendarEmailMinAlert.xml?"; + String output = CurlWrapper.get( + serviceUrl+params, + "127.0.0.1", + 9050 + ); + CalendarMap cm = parseOutput(output); + return cm; + } +} \ No newline at end of file diff --git a/src/main/java/domain/tld/Commands.java b/src/main/java/domain/tld/Commands.java new file mode 100644 index 0000000..84c1c24 --- /dev/null +++ b/src/main/java/domain/tld/Commands.java @@ -0,0 +1,84 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package domain.tld; + +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import biz.igg.oopdp.ff.tools.curl.CurlWrapper; + +/** + * + * @author salvix + */ +public class Commands { + + + public static String whatIsMyIp() + { + String ip = ""; + String output; + try { + output = CurlWrapper.get("http://whatismyip.org"); + Pattern pattern = Pattern.compile("(.+?)"); + Matcher matcher = pattern.matcher(output); + matcher.find(); + int m = matcher.groupCount(); + if(m == 1){ + ip = matcher.group(1); + } + + } catch (IOException ex) { + + } + return ip; + } + + + public static String checkTorUsage(String output) + { + String ext = ""; + Pattern pattern = Pattern.compile("\\s+(.+?)\\s+"); + Matcher matcher = pattern.matcher(output); + matcher.find(); + int m = matcher.groupCount(); + if(m == 1){ + ext = matcher.group(1).trim(); + } + return ext; + } + + public static String getTor() + { + String output = ""; + try { + output = CurlWrapper.get("https://check.torproject.org", "127.0.0.1", 9050); + } + catch (IOException ex) { + + } + return output; + } + + public static String checkTorIp(String output) + { + String ext = ""; + Pattern pattern = Pattern.compile("

.*(.+?)

"); + Matcher matcher = pattern.matcher(output); + matcher.find(); + int m = matcher.groupCount(); + if(m == 1){ + ext = matcher.group(1).trim(); + } + return ext; + } + + public static String torStatus() + { + String ouput = getTor(); + return checkTorIp(ouput)+" - "+checkTorUsage(ouput); + } +} diff --git a/src/main/java/domain/tld/Curl.java b/src/main/java/domain/tld/Curl.java deleted file mode 100644 index 28453b5..0000000 --- a/src/main/java/domain/tld/Curl.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -package domain.tld; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.Proxy; -import java.net.SocketAddress; -import java.net.InetSocketAddress; - - -/** - * - * @author salvix - */ -public class Curl { - - private String url; - - private HttpURLConnection connection; - - private URL target; - - public void setUrl(String url) throws MalformedURLException - { - this.url = url; - target = new URL(this.url); - } - - public HttpURLConnection post() throws IOException - { - HttpURLConnection conn = (HttpURLConnection) target.openConnection(); - conn.setReadTimeout(10000); - conn.setConnectTimeout(15000); - conn.setRequestMethod("POST"); - conn.setDoInput(true); - conn.setDoOutput(true); - connection = conn; - return getConnection(); - } - - public HttpURLConnection get() throws IOException - { - HttpURLConnection conn = (HttpURLConnection) target.openConnection(); - conn.setReadTimeout(10000); - conn.setConnectTimeout(15000); - conn.setRequestMethod("GET"); - conn.setDoInput(true); - conn.setDoOutput(true); - connection = conn; - return getConnection(); - } - - public HttpURLConnection getProxy() throws IOException - { - SocketAddress addr = new InetSocketAddress("127.0.0.1", 9050); - Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr); - HttpURLConnection conn = (HttpURLConnection) target.openConnection(proxy); - conn.setReadTimeout(10000); - conn.setConnectTimeout(15000); - conn.setRequestMethod("GET"); - conn.setDoInput(true); - conn.setDoOutput(true); - connection = conn; - return getConnection(); - } - - public HttpURLConnection getConnection() - { - return connection; - } - /* - public void writeParams(HttpURLConnection conn, KeyValueList params) throws IOException - { - OutputStream os = conn.getOutputStream(); - BufferedWriter writer = new BufferedWriter( - new OutputStreamWriter(os, "UTF-8")); - writer.write(params.getQuery()); - writer.flush(); - writer.close(); - } - */ - - public String getOutput(HttpURLConnection conn) throws IOException - { - BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); - StringBuilder sb = new StringBuilder(); - String line; - while ((line = br.readLine()) != null) { - sb.append(line); - sb.append(System.lineSeparator()); - } - return sb.toString(); - } -} diff --git a/src/main/java/domain/tld/CurlWrapper.java b/src/main/java/domain/tld/CurlWrapper.java deleted file mode 100644 index 38234e1..0000000 --- a/src/main/java/domain/tld/CurlWrapper.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package domain.tld; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; - -/** - * - * @author salvix - */ -public class CurlWrapper { - - - public static String get(String url) throws MalformedURLException, IOException - { - Curl c = new Curl(); - c.setUrl(url); - HttpURLConnection cn = c.get(); - String output = c.getOutput(cn); - return output; - } - - public static String getWithProxy(String url) throws MalformedURLException, IOException - { - Curl c = new Curl(); - c.setUrl(url); - HttpURLConnection cn = c.getProxy(); - String output = c.getOutput(cn); - return output; - } -} -- 2.11.4.GIT