This repository has been archived by the owner on May 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from IniZio/people
Find People
- Loading branch information
Showing
5 changed files
with
260 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.comp3111.chatbot; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
|
||
@Slf4j | ||
public class PeopleList { | ||
private ArrayList <people> people; | ||
public static boolean too_many=false; | ||
|
||
public PeopleList () { | ||
this.people=null; | ||
} | ||
|
||
public void addPeople (String p0, String p1, String p2, String p3, String p4, String p5) { | ||
people p = new people(p0, p1, p2, p3, p4, p5); | ||
if (this.people==null) { | ||
this.people=new ArrayList<people>(); | ||
} | ||
this.people.add(p); | ||
} | ||
|
||
public ArrayList<people> getList(){ | ||
return this.people; | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/comp3111/chatbot/URLConnectionReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.comp3111.chatbot; | ||
|
||
import java.net.*; | ||
import java.io.*; | ||
import java.util.List; | ||
|
||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
import org.jsoup.select.Elements; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
|
||
@Slf4j | ||
public class URLConnectionReader { | ||
public PeopleList SearchPeople(String args) throws Exception { | ||
String s1=args.replace(" ", "%20"); | ||
Document doc = Jsoup.connect("http://www.ust.hk/search/"+s1+"/?sopt=people").get(); | ||
//Document doc = Jsoup.connect("http://www.ust.hk/search/a%20b%20c/?sopt=people").get(); | ||
Element content = doc.getElementById("p-s-table"); | ||
Elements inputElements = content.getElementsByTag("td"); | ||
|
||
String [] values = new String [42]; | ||
PeopleList l = new PeopleList(); | ||
|
||
int i=0; | ||
|
||
for(Element td : inputElements) { | ||
if (i<42) { | ||
values[i] = td.text(); | ||
if (values[i].equals("No result found matching your search criteria.")) | ||
return l; | ||
//log.info("values {} = {}", i, values[i]); | ||
i++; | ||
} | ||
else | ||
{ | ||
PeopleList.too_many=true; | ||
log.info("\nToo many results"); | ||
break; | ||
} | ||
} | ||
|
||
int j =0; | ||
while(j<i) { | ||
log.info("Values {} = {}",j, values[j]); | ||
log.info("Values {} = {}",j+1, values[j+1]); | ||
log.info("Values {} = {}",j+2, values[j+2]); | ||
log.info("Values {} = {}",j+3, values[j+3]); | ||
log.info("Values {} = {}",j+4, values[j+4]); | ||
log.info("Values {} = {}",j+5, values[j+5]); | ||
|
||
l.addPeople(values[j], values[j+1], values[j+2], values[+3], | ||
values[j+4], values[j+5]); | ||
|
||
j=j+6; | ||
} | ||
|
||
return l; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.comp3111.chatbot; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
|
||
@Slf4j | ||
public class people{ | ||
private String title; | ||
private String name; | ||
private String email; | ||
private String phone; | ||
private String department; | ||
private String room; | ||
|
||
public people( String title, String name, String email, String phone, | ||
String department, String room){ | ||
this.title=title; | ||
this.name=name; | ||
this.email=email; | ||
this.phone=phone; | ||
this.department=department; | ||
this.room=room; | ||
|
||
} | ||
|
||
public String getTitle() { | ||
if (this.title.equals("")) | ||
return "No info"; | ||
return this.title; | ||
} | ||
|
||
public String getName() { | ||
if (this.name.equals("")) | ||
return "No info"; | ||
return this.name; | ||
} | ||
public String getEmail() { | ||
if (this.email.equals("")) | ||
return "No info"; | ||
return this.email; | ||
} | ||
public String getPhone() { | ||
if (this.phone.equals("")) | ||
return "No info"; | ||
return this.phone; | ||
} | ||
public String getDepartment() { | ||
if (this.department.equals("")) | ||
return "No info"; | ||
return this.department; | ||
} | ||
public String getRoom() { | ||
if (this.room.equals("")) | ||
return "No info"; | ||
return this.room; | ||
} | ||
} |