Commit c6132e07 authored by yihua.huang's avatar yihua.huang

some refector

parent 194152ab
......@@ -19,34 +19,29 @@ import java.util.Scanner;
*/
public class QuickStarter {
public static void main(String[] args) {
Map<String, Class> clazzMap = new LinkedHashMap<String, Class>();
private static Map<String, Class> clazzMap;
private static Map<String, String> urlMap;
private static void init(){
clazzMap = new LinkedHashMap<String, Class>();
clazzMap.put("1", OschinaBlog.class);
clazzMap.put("2", IteyeBlog.class);
clazzMap.put("3", News163.class);
Map<String, String> urlMap = new LinkedHashMap<String, String>();
urlMap = new LinkedHashMap<String, String>();
urlMap.put("1", "http://my.oschina.net/flashsword/blog");
urlMap.put("2", "http://flashsword20.iteye.com/");
urlMap.put("3", "http://news.163.com/");
Scanner stdin = new Scanner(System.in);
String key = null;
System.out.println("Choose a Spider demo:");
for (Map.Entry<String, Class> classEntry : clazzMap.entrySet()) {
System.out.println(classEntry.getKey()+"\t" + classEntry.getValue() + "\t" + urlMap.get(classEntry.getKey()));
}
while (key == null) {
key = new String(stdin.nextLine());
if (clazzMap.get(key) == null) {
System.out.println("Invalid choice!");
key = null;
}
}
System.out.println("The demo started and will last 20 seconds...");
public static void main(String[] args) {
init();
String key = null;
key = readKey(key);
System.out.println("The demo started and will last 20 seconds...");
//Start spider
OOSpider.create(Site.me().addStartUrl(urlMap.get(key)), clazzMap.get(key)).pipeline(new PagedPipeline()).pipeline(new ConsolePipeline()).runAsync();
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
......@@ -56,4 +51,20 @@ public class QuickStarter {
System.out.println("To more usage, try to customize your own Spider!");
System.exit(0);
}
private static String readKey(String key) {
Scanner stdin = new Scanner(System.in);
System.out.println("Choose a Spider demo:");
for (Map.Entry<String, Class> classEntry : clazzMap.entrySet()) {
System.out.println(classEntry.getKey()+"\t" + classEntry.getValue() + "\t" + urlMap.get(classEntry.getKey()));
}
while (key == null) {
key = new String(stdin.nextLine());
if (clazzMap.get(key) == null) {
System.out.println("Invalid choice!");
key = null;
}
}
return key;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment