-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadimages.java
More file actions
122 lines (103 loc) · 3.28 KB
/
loadimages.java
File metadata and controls
122 lines (103 loc) · 3.28 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
package images;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class main {
//src=.+?".+?"
static String lastSentence = null;
static String imgsrc = null;
//static String strURL ="http://en.wikipedia.org/w/api.php?action=query&titles=Stackoverflow";
static String originalName = null;
static String wikiT = "Apple Inc.";
//
static String strURL;
//static String strURL = "http://www.amazon.com/";
public static void main(String[] args) throws IOException {
System.out.println(getImage(wikiT));
System.out.println(getName());
}
public static String getImage(String name)
{
wikiT = name;
originalName = wikiT;
wikiT = wikiT.replace(" ","_");
strURL = "http://en.wikipedia.org/w/api.php?action=parse&format=json&page="+wikiT;
wikiT = wikiT.split("_")[0];
URL url = null;
try {
url = new URL(strURL);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader reader = null;
//src=.+?".+?"
try {
try {
reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
for (String line; (line = reader.readLine()) != null;) {
if(regexFinder("src=.+?\".+?\"",line,1))
{
}
//System.out.println(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} finally {
if (reader != null) try { reader.close(); } catch (IOException ignore) {}
}
String trimedName = lastSentence.substring(8, lastSentence.length()-2);
//System.out.println(trimedName);
return trimedName;
}
public static String getName()//Execute after the function getImage!!!
{
return originalName;
}
public static boolean regexFinder(String regex, String checker, int findwhat)
{
//System.out.println("hello");
Pattern checkRegex = Pattern.compile(regex);
Matcher matchRegex = checkRegex.matcher(checker);
//System.out.println(matchRegex.find());
while(matchRegex.find())
{
if(matchRegex.group().length() != 0)
{
//System.out.println(matchRegex.group().trim());
//fullWords.add(matchRegex.group().trim());
if(findwhat==1)
{
//System.out.println(matchRegex.group().trim());
lastSentence=matchRegex.group().trim();
if(regexFinder(wikiT,matchRegex.group().trim(),2))
{
return true;
}
}
else if(findwhat==2)
{//We Found MICROSOFT!!!!!!!!!
return true;
}
}
//System.out.println(findSentence(checker, matchRegex.start(), matchRegex.end()));
//meanings.add(findSentence(checker, matchRegex.start(), matchRegex.end()));
}
return false;
}
}