Guest User

Read.java

a guest
Feb 10th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.93 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.math.BigDecimal;
  5. import java.math.RoundingMode;
  6. import java.net.URL;
  7.  
  8.  
  9.  
  10. public class Read {
  11.    
  12.     public static double round(double value, int places) {
  13.         if (places < 0) throw new IllegalArgumentException();
  14.  
  15.         BigDecimal bd = new BigDecimal(value);
  16.         bd = bd.setScale(places, RoundingMode.HALF_UP);
  17.         return bd.doubleValue();
  18.     }
  19.    
  20.     public static double[] ConvertEuroPound(double Price) throws IOException{
  21.        
  22.         URL CurrencyURL = new URL("http://www.bloomberg.com/markets/currencies/");
  23.         BufferedReader SiteReader = new BufferedReader(new InputStreamReader(CurrencyURL.openStream()));
  24.         String CurrentLine = "";
  25.         boolean DoneWithEuro = false;
  26.         boolean DoneWithPound = false;
  27.         String EuroConvertStr = "";
  28.         String PoundConvertStr = "";
  29.         double EuroConvert = 0;
  30.         double PoundConvert = 0;
  31.        
  32.         while(true){
  33.             CurrentLine = SiteReader.readLine();
  34.             if(CurrentLine==null){
  35.                 break;
  36.             }
  37.             if(DoneWithEuro==true && DoneWithPound==true){
  38.                 break;
  39.             }
  40.             if(CurrentLine.contains("US DOLLAR (USD) to EURO (EUR) Exchange Rate")){
  41.                 EuroConvertStr = CurrentLine.substring(CurrentLine.indexOf(">")+1, CurrentLine.indexOf("</a"));
  42.                 EuroConvert = Double.parseDouble(EuroConvertStr);
  43.                 DoneWithEuro = true;
  44.             }
  45.             if(CurrentLine.contains("US DOLLAR (USD) to BRITISH POUND (GBP) Exchange Rate")){
  46.                 PoundConvertStr = CurrentLine.substring(CurrentLine.indexOf(">")+1, CurrentLine.indexOf("</a"));
  47.                 PoundConvert = Double.parseDouble(PoundConvertStr);
  48.                 DoneWithPound = true;
  49.             }
  50.            
  51.         }
  52.        
  53.         double[] Conversions = new double[2];
  54.         Conversions[0] = EuroConvert;
  55.         Conversions[1] = PoundConvert;
  56.        
  57.         return Conversions;
  58.        
  59.        
  60.        
  61.        
  62.        
  63.        
  64.     }
  65.    
  66.    
  67.    
  68.    
  69.    
  70.    
  71.    
  72.    
  73.    
  74.    
  75.     public static String Price(String WeaponName, String SkinName, String Quality, boolean StatTrak, boolean Souvenir) throws IOException{
  76.        
  77.         String KnifeSite = "http://steamcompanion.com/csgo/-";
  78.         String TrueSite = "http://steamcompanion.com/csgo/";
  79.         String StatTrakStr = "";
  80.         if(StatTrak==true){
  81.             StatTrakStr = "StatTrak-";
  82.         }else if(StatTrak==false){
  83.             StatTrakStr = "";
  84.         }
  85.        
  86.         String SouvenirStr = "";
  87.         if(Souvenir==true){
  88.             SouvenirStr = "Souvenir-";
  89.         }else if(Souvenir==false){
  90.             SouvenirStr = "";
  91.         }
  92.         if(WeaponName=="M9 Bayonet"){
  93.             TrueSite = KnifeSite;
  94.         }else if(WeaponName=="Gut Knife"){
  95.             TrueSite = KnifeSite;
  96.         }else if(WeaponName=="Flip Knife"){
  97.             TrueSite = KnifeSite;
  98.         }else if(WeaponName=="Bayonet"){
  99.             TrueSite = KnifeSite;
  100.         }
  101.        
  102.        
  103.        
  104.        
  105.        
  106.        
  107.         String Site = TrueSite + SouvenirStr + StatTrakStr + WeaponName + "--" + SkinName + "-" + Quality + "/";
  108.        
  109.         if(WeaponName=="Case"){
  110.             Site = TrueSite + SkinName + "-" + WeaponName + "/";
  111.         }
  112.         if(WeaponName=="Sticker Capsule"){
  113.             Site = TrueSite + "Sticker-Capsule/";
  114.         }
  115.         if(Quality=="None"){
  116.             Quality = "";
  117.         }
  118.         Site = Site.replace(' ', '-');
  119.        
  120.         URL CSurl = new URL(Site);
  121.         String Price = "";
  122.         System.out.println(Site);
  123.        
  124.         BufferedReader SiteReader = new BufferedReader(new InputStreamReader(CSurl.openStream())); // bufferedreader to read the source-code from csgolounge
  125.         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
  126.         while(true){ // always start this loop
  127.             CurrentLine = SiteReader.readLine(); // read a new line
  128.             if(CurrentLine==null){ // end loop if the line contains nothing (if we are at the end of document)
  129.                 break;
  130.             }
  131.            
  132.             if(CurrentLine.contains("price values")){
  133.                 Price = CurrentLine.substring(CurrentLine.indexOf(";")+1, CurrentLine.indexOf("</"));
  134.             }
  135.            
  136.            
  137.            
  138.            
  139.            
  140.                    
  141.         }// <-- while end
  142.        
  143.        
  144.        
  145.  
  146.        
  147.        
  148.         if(Price.contains("<td class")){
  149.             Price = "";
  150.         }
  151.        
  152.         return Price;
  153.        
  154.  
  155.        
  156.        
  157.        
  158.        
  159.        
  160.  
  161.        
  162.        
  163.        
  164.     }
  165.  
  166. }
Advertisement
Add Comment
Please, Sign In to add comment