-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.java
111 lines (84 loc) · 2.42 KB
/
Item.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
import java.io.*;
import java.net.*;
public class Item {
private String itemName;
private String userID;
private String website;
private int originalKeys;
public Item(String name, String site) throws IOException {
itemName = name;
website = site;
userID = getID();
originalKeys = checkKeywords();
}
public String getName() {
return itemName;
}
public String getKey() {
return userID;
}
public String getWebsite() {
return website;
}
public int getOrigKeys() {
return originalKeys;
}
private static String getUrlSource(String url) throws IOException {
String inputLine;
URL webURL = new URL(url);
URLConnection yc = webURL.openConnection();
yc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream(), "UTF-8"));
StringBuilder a = new StringBuilder();
while ((inputLine = in.readLine()) != null)
a.append(inputLine);
in.close();
return a.toString();
}
public int checkKeywords() throws IOException {
String websiteSource = getUrlSource(website);
int stop = websiteSource.length() - userID.length();
int count = 0;
for (int i = 0; i < stop; i++) {
if (websiteSource.substring(i, i + userID.length()).equals(userID)) {
count++;
}
}
return count;
}
public String getID() throws IOException {
String search = "author may-blank id-";
String id = "";
String websiteSource = getUrlSource(website);
int stop = websiteSource.length() - search.length();
int count = 0;
int idStart = 0;
int idStop = 0;
for (int i = 0; i < stop; i++) {
if (websiteSource.substring(i, i + search.length()).equals(search)) {
count++;
if (count == 32) {
int index = i + search.length();
int index2 = i + search.length();
while (!websiteSource.substring(index2, index2 + 1).equals("\"")) {
index2++;
}
idStart = index;
idStop = index2;
}
}
}
id = websiteSource.substring(idStart, idStop);
return id;
}
public boolean hasChanged() throws IOException {
boolean change = false;
if (checkKeywords() != originalKeys) {
change = true;
}
return change;
}
public void resetHasChanged() throws IOException{
originalKeys = checkKeywords();
}
}