-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter.java
132 lines (106 loc) · 3.97 KB
/
twitter.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
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class twitter {
public static void main(String[] args){
String counterFile = "counter.txt", rnumberFile = "rnumber.txt" ;
String counter, rnumber;
String name;
String url;
String date;
String ipAddress ="";
String portNumber = "";
String limitString = "";
int limit = 150;
String directory = System.getProperty("user.dir");
Command d = new Command();
String os = System.getProperty("os.name").toLowerCase();
boolean osWindows = os.indexOf("win") >= 0;
try{
for (int i = 0; i < args.length; i+=2){
if(args[i].equals("--ip")){
ipAddress = args[i+1];
}
else if (args[i].equals("--port")){
portNumber = args[i+1];
}
else if (args[i].equals("--directory") || args[i].equals("-d")){
directory = args[i+1];
}else if (args[i].equals("--limit") || args[i].equals("-l")){
limitString = args[i+1];
limit = Integer.parseInt(limitString);
}
}
//it determines the Operating system to apply the correct slash.
if(osWindows == true){
directory = directory+"\\";
}else{
directory = directory+"/";
}
if (ipAddress == ""){
Downloader ip = new Downloader();
ipAddress = ip.getIpAddress();
}
if (portNumber == "")
portNumber = "8080";
File fCounter = new File(directory+counterFile);
File fRnumber = new File(directory+rnumberFile);
if(!fCounter.exists()){
try {
FileWriter fw = new FileWriter(directory+counterFile);
BufferedWriter out = new BufferedWriter(fw);
out.write("1\n");
out.close();
System.out.println("countert.txt file does not exist\nCreating file.");
} catch (IOException e) {
e.printStackTrace();
}
}
if(!fRnumber.exists()){
try {
FileWriter fw = new FileWriter(directory+rnumberFile);
BufferedWriter out = new BufferedWriter(fw);
out.write("1\n");
out.close();
System.out.println("rnumber.txt file does not exist\nCreating file.");
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("IP: "+ipAddress);
System.out.println("Port: "+portNumber);
System.out.println("Limit: " + limit);
System.out.println("Directory: "+ directory);
int x=1;
while(x<limit){
++x;
date=d.execCommand("date");
ReaderBuffer bufferCounter = new ReaderBuffer();
ReaderBuffer bufferRnumber = new ReaderBuffer();
ReaderBuffer buffWr = new ReaderBuffer ();
ReaderBuffer intBuff = new ReaderBuffer ();
counter = bufferCounter.Reader(directory.concat(counterFile)); //gets the counter number from the counter.txt file
rnumber = bufferRnumber.Reader(directory.concat(rnumberFile)); //gets the real number or real amount of actual files downloaded
Downloader dLoader = new Downloader(); //sets the dLoader object in order to use for downloading xml file.
dLoader.setCounter(rnumber); //this sets the rnumber in order to be used to determine what number was the prvious download
url = "http://api.twitter.com/1/users/lookup.xml?user_id="+counter;
name=rnumber.concat(".xml");
buffWr.openStream(directory+name);
System.out.println("<body>\n\t<api>tweeter</api>\n\t<requestnumber>"+rnumber+"</requestnumber>\n\t<detail></detail>\n\t<date>"+date+"</date>");
dLoader.Get(url, directory.concat(name), ipAddress, portNumber);
System.out.println("</body>");
buffWr.closeStream();
buffWr.openStream(directory+counterFile);
int intRnumber = intBuff.str2Int(counter) + 1;
System.out.println(intRnumber);
buffWr.closeStream();
buffWr.openStream(directory+rnumberFile);
System.out.println(dLoader.getCounter());
buffWr.closeStream();
}
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
}