-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.java
More file actions
105 lines (79 loc) · 2.82 KB
/
Copy pathapi.java
File metadata and controls
105 lines (79 loc) · 2.82 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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.io.*;
import java.util.Scanner;
class ThreadDemo extends Thread {
Thread t;
private String threadName;
ThreadDemo( String name){
threadName = name;
}
static void updateProgress(double progressPercentage) {
final int width = 50; // progress bar width in chars
System.out.print("\r[");
int i = 0;
for (; i <= (int)(progressPercentage*width); i++) {
System.out.print(".");
}
for (; i < width; i++) {
System.out.print(" ");
}
System.out.print("]");
}
public void run() {
try {
for (double progressPercentage = 0.0; progressPercentage < 1.0; progressPercentage += 0.01) {
updateProgress(progressPercentage);
Thread.sleep(20);
}
} catch (InterruptedException e) {}
}
public void start ()
{
if (t == null)
{
t = new Thread (this, threadName);
t.start ();
}
}
}
public class api {
public static void main(String[] args) {
try {
ThreadDemo T1 = new ThreadDemo( "Thread-1");
System.out.println("Enter article to search: ");
Scanner so=new Scanner(System.in);
String word=so.nextLine();
T1.start();
String[] wordArray = word.split(" ");
word = "";
for(String s : wordArray) {
word = word + s.substring(0,1).toUpperCase() + s.substring(1).toLowerCase() + "+";
}
word = word.substring(0,word.length()-1);
String url_final="https://en.wikipedia.org/w/api.php?action=query&titles="+word+"&format=json";
URL url = new URL(url_final);
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String strTemp = "",ans="";
T1.t.join();
while (null != (strTemp = br.readLine())) {
ans=ans+strTemp;
}
int index = ans.indexOf("\"pageid\":");
ans = ans.substring(index + "pageid:".length()+2);
String pageid = ans.substring(0,ans.indexOf(","));
ans="http://en.wikipedia.org/wiki/index.html?curid="+pageid+"\n";
FileOutputStream fout=new FileOutputStream("javaWikiSearchDefaultLogFile",true);
String str="\n";
byte b1[]=str.getBytes();//converting string into byte array
fout.write(b1);
byte b[]=ans.getBytes();//converting string into byte array
fout.write(b);
fout.close();
System.out.println("\nLink can be found in javaWikiSearchDefaultLogFile file.");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}