-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
140 lines (98 loc) · 3.64 KB
/
Copy pathMain.java
File metadata and controls
140 lines (98 loc) · 3.64 KB
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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package chat;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import java.sql.Timestamp;
import java.util.GregorianCalendar;
import org.joda.time.DateTime;
import org.joda.*;
import org.jsoup.*;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.jsoup.nodes.Document;
/**
*
* @author Gowtham
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
Thread t = Thread.currentThread ( );
int g,uid = 0;
DateTime cal1 = new DateTime(2010,8,5,0,0);
Timestamp sd = new Timestamp(cal1.getMillis());
db mysql = new db();
int hour,minute;
Main a5 = new Main();
String html,message,shit,times;
Document go;
do{
org.jsoup.nodes.Document doc = Jsoup.connect("http://chat.stackexchange.com/transcript/118/"+cal1.getYear()+"/"+cal1.getMonthOfYear()+"/"+cal1.getDayOfMonth()).userAgent("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)").get();
Element transcript = doc.select(".pager").first();
if( b.attr(".pager").substring(1, 10).equals("transcript") ){
a5.getdata("http://chat.stackexchange.com"+b.attr("href"),sd,cal1);
}
cal1 = cal1.plusDays(1);
} while (1 > 0);
}
void getdata(String url,Timestamp sd,DateTime cal1 )throws java.io.IOException{
int g,uid = 0;
int hour,minute;
String html,message,shit,times;
Document go;
db mysql = new db();
org.jsoup.nodes.Document doc = Jsoup.connect(url).get();
Elements messages = doc.select(".monologue");
for( Element a : messages){
go = Jsoup.parse(a.html());
message=(go.select(".content").html());
shit = Jsoup.parse((go.select(".username").html())).select("a[href]").attr("href");
if(shit.length()> 0){
Scanner s = new Scanner (shit.substring(7));
s.useDelimiter("/");
if(s.hasNextInt())
uid=s.nextInt();
}
else{
uid=0;
}
times= go.select(".timestamp").html();
times= times.length()== 8? times: "0"+ times;
System.err.println(times);
if( times.equals("0") ? times == null :times.substring(4).equals("AM") ){
hour =Integer.parseInt (times.substring(0,1));
minute = Integer.parseInt(times.substring(3,5));
}else
{
System.err.println(times);
hour =(Integer.parseInt(times.substring(0,1)))+12;
minute = Integer.parseInt(times.substring(3,5));
}
sd.setTime((cal1.withTime(hour,minute,0,0)).getMillis());
try {
db.pushdata(uid, message, sd);
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}