Created
September 12, 2014 03:34
-
-
Save yusuke/ebf8df1e31d458804779 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package order; | |
| import twitter4j.HttpClient; | |
| import java.util.regex.Matcher; | |
| import java.util.regex.Pattern; | |
| /** | |
| * Created with IntelliJ IDEA. | |
| * User: yusuke | |
| * Date: 2013/10/17 | |
| * Time: 12:33 | |
| * To change this template use File | Settings | File Templates. | |
| */ | |
| public class Rate { | |
| public static void main(String[] args) { | |
| System.out.println(getUSDJPYRate()); | |
| } | |
| public static double getUSDJPYRate(){ | |
| HttpClient client = twitter4j.HttpClientFactory.getInstance(); | |
| double rate; | |
| try { | |
| String result = client.get("https://www.google.com/finance/converter?a=1&from=USD&to=JPY").asString(); | |
| Pattern p = Pattern.compile("<span class=bld>([0-9\\.]*) JPY</span>"); | |
| Matcher m = p.matcher(result); | |
| m.find(); | |
| String str = m.group(1); | |
| rate = Double.parseDouble(str.split(" ")[0]); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| rate = 100d; | |
| } | |
| return rate; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment