Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.net.URL;
- public class Read {
- public static double round(double value, int places) {
- if (places < 0) throw new IllegalArgumentException();
- BigDecimal bd = new BigDecimal(value);
- bd = bd.setScale(places, RoundingMode.HALF_UP);
- return bd.doubleValue();
- }
- public static double[] ConvertEuroPound(double Price) throws IOException{
- URL CurrencyURL = new URL("http://www.bloomberg.com/markets/currencies/");
- BufferedReader SiteReader = new BufferedReader(new InputStreamReader(CurrencyURL.openStream()));
- String CurrentLine = "";
- boolean DoneWithEuro = false;
- boolean DoneWithPound = false;
- String EuroConvertStr = "";
- String PoundConvertStr = "";
- double EuroConvert = 0;
- double PoundConvert = 0;
- while(true){
- CurrentLine = SiteReader.readLine();
- if(CurrentLine==null){
- break;
- }
- if(DoneWithEuro==true && DoneWithPound==true){
- break;
- }
- if(CurrentLine.contains("US DOLLAR (USD) to EURO (EUR) Exchange Rate")){
- EuroConvertStr = CurrentLine.substring(CurrentLine.indexOf(">")+1, CurrentLine.indexOf("</a"));
- EuroConvert = Double.parseDouble(EuroConvertStr);
- DoneWithEuro = true;
- }
- if(CurrentLine.contains("US DOLLAR (USD) to BRITISH POUND (GBP) Exchange Rate")){
- PoundConvertStr = CurrentLine.substring(CurrentLine.indexOf(">")+1, CurrentLine.indexOf("</a"));
- PoundConvert = Double.parseDouble(PoundConvertStr);
- DoneWithPound = true;
- }
- }
- double[] Conversions = new double[2];
- Conversions[0] = EuroConvert;
- Conversions[1] = PoundConvert;
- return Conversions;
- }
- public static String Price(String WeaponName, String SkinName, String Quality, boolean StatTrak, boolean Souvenir) throws IOException{
- String KnifeSite = "http://steamcompanion.com/csgo/-";
- String TrueSite = "http://steamcompanion.com/csgo/";
- String StatTrakStr = "";
- if(StatTrak==true){
- StatTrakStr = "StatTrak-";
- }else if(StatTrak==false){
- StatTrakStr = "";
- }
- String SouvenirStr = "";
- if(Souvenir==true){
- SouvenirStr = "Souvenir-";
- }else if(Souvenir==false){
- SouvenirStr = "";
- }
- if(WeaponName=="M9 Bayonet"){
- TrueSite = KnifeSite;
- }else if(WeaponName=="Gut Knife"){
- TrueSite = KnifeSite;
- }else if(WeaponName=="Flip Knife"){
- TrueSite = KnifeSite;
- }else if(WeaponName=="Bayonet"){
- TrueSite = KnifeSite;
- }
- String Site = TrueSite + SouvenirStr + StatTrakStr + WeaponName + "--" + SkinName + "-" + Quality + "/";
- if(WeaponName=="Case"){
- Site = TrueSite + SkinName + "-" + WeaponName + "/";
- }
- if(WeaponName=="Sticker Capsule"){
- Site = TrueSite + "Sticker-Capsule/";
- }
- if(Quality=="None"){
- Quality = "";
- }
- Site = Site.replace(' ', '-');
- URL CSurl = new URL(Site);
- String Price = "";
- System.out.println(Site);
- BufferedReader SiteReader = new BufferedReader(new InputStreamReader(CSurl.openStream())); // bufferedreader to read the source-code from csgolounge
- String CurrentLine = "START"; // START is just there to be something before we actually start reading, this will be the current line which is being processed
- while(true){ // always start this loop
- CurrentLine = SiteReader.readLine(); // read a new line
- if(CurrentLine==null){ // end loop if the line contains nothing (if we are at the end of document)
- break;
- }
- if(CurrentLine.contains("price values")){
- Price = CurrentLine.substring(CurrentLine.indexOf(";")+1, CurrentLine.indexOf("</"));
- }
- }// <-- while end
- if(Price.contains("<td class")){
- Price = "";
- }
- return Price;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment