This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
143 lines (86 loc) · 2.84 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//package com.capmon;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.*;
import java.util.logging.Logger;
//import RateJSONParser;
public class Main {
public final static Logger LOGGER = Logger.getLogger(Main.class .getName());
public static void main(String [] args ) throws IOException {
LOGGER.setLevel(Level.INFO);
FileHandler fh;
try{
fh = new FileHandler("my.log");
LOGGER.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
LOGGER.info("hello");
}catch(Exception e){
System.out.println("logger error");
}
String data;
int count = 10;
DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
// Date dateobj = new Date();
BufferedWriter writer = new BufferedWriter(new FileWriter("logfile.csv"));
//writer.write (data);
writer.append("Date");
writer.append(",");
writer.append("Rate");
writer.append(",");
//writer.append("Link");
//writer.append(",");
writer.append('\n');
while (count > 0) {
data = ((new RateHttpClient()).getRateData());
data = RateJSONParser.Rate(data);
Date dateobj = new Date();
data = data.split(",")[0];
try {
//Close writer
//count--;
LOGGER.info(df.format(dateobj) + "," + data);
writer.append(df.format(dateobj));
writer.append(",");
// writer.append(RateJSONParser.Rate(data));
//curent.write(RateJSONParser.Rate(data));
writer.append(data);
currentWriter(data);
writer.append(",");
writer.append('\n');
//writer.close();
//curent.close();
} catch (Exception e) {
e.printStackTrace();
//curent.close();
//writer.close();
}
// curent.close();
delay();
// curent.close();
}
// rate = RateJSONParser.Rate(data);
writer.close();
// curent.close();
///System.out.println(rate);
//System.out.println("Hello");
//String rateString = "10";
// return rateString;
}
public static void delay(){
try{
Thread.sleep(10000);
}catch(Exception e){}
}
public static void currentWriter(String data)throws IOException{
BufferedWriter curent = new BufferedWriter(new FileWriter("current.txt"));
try{
curent.write(data);
}catch(Exception e) { curent.close();}
curent.close();
}
}