Administrator approval is now required for registering new accounts. If you are registering a new account, and are external to the University, please ask the repository owner to contact ServiceLine to request your account be approved. Repository owners must include the newly registered email address, and specific repository in the request for approval.

Unverified Commit 0547866a authored by Mutantoe's avatar Mutantoe
Browse files

Migrated repository

parent 8b2ea6b4
package jrr1g18.ecsnames;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ECSNames {
public static String getURLSource(URL url) throws IOException {
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
StringBuilder result = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
result.append(line);
}
return result.toString();
}
public static String getNameFromSource(String source) {
Pattern pattern = Pattern.compile("(?<=\"name\">).*(?=<\\/h1)");
Matcher matcher = pattern.matcher(source);
matcher.find(); // As it turns out, this line is vital.
return matcher.group();
}
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
String uid = stdin.nextLine();
stdin.close();
URL url = null;
try {
url = new URL("https://www.ecs.soton.ac.uk/people/".concat(uid));
} catch (MalformedURLException e) {
e.printStackTrace();
System.exit(1);
}
String source = "";
try {
source = getURLSource(url);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
String result = getNameFromSource(source);
System.out.println(result);
}
}
#!/bin/sh
if [ $# -ne 1 ]
then
echo Exactly 1 argument is required >&2
exit 1
fi
curl --silent https://www.ecs.soton.ac.uk/people/$1 | grep -P '(?<="name">).*(?=<\/h1)' --only-matching
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