Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3.  
  4. public class FinanceParser extends PageParser
  5. {
  6.     private int addNext;
  7.     private double price;
  8.     private String name;
  9.     private String symb;
  10.     private ArrayList<String> others;
  11.    
  12.     public FinanceParser(String site, String page)
  13.     {
  14.         super(site, page);
  15.        
  16.         others = new ArrayList<String>();
  17.     }
  18.  
  19.     public void saveData(String line)
  20.     {
  21.         if(others == null)
  22.             others = new ArrayList<String>();
  23.        
  24.         super.saveData(line);
  25.         int find;
  26.         int findEnd;
  27.         if(addNext != 0)
  28.         {
  29.             find = line.indexOf(">");
  30.             findEnd = line.indexOf("<", find);
  31.             price = Double.parseDouble(line.substring(find + 1, findEnd));
  32.             addNext = 0;
  33.         }
  34.        
  35.         if(line.equals("<span class=\"pr\">"))
  36.             addNext = 1;
  37.         else if(line.length() > 14 && line.substring(0, 7).equals("<title>"))
  38.         {
  39.             find = line.indexOf(":", 7);
  40.             name = line.substring(7, find);
  41.            
  42.             find = line.indexOf(":", find + 1);
  43.             findEnd = line.indexOf(" quotes", find);
  44.             symb = line.substring(find + 1, findEnd);
  45.         }
  46.         else if(symb != null && line.startsWith("title = \"" + symb + ": {LAST} {CHANGE} ({CHANGE_PCT}%)"))
  47.         {
  48.             find = line.indexOf("_aQ(", 40);
  49.             while(find != -1)
  50.             {
  51.                 find = line.indexOf(":", find);
  52.                 findEnd = line.indexOf("\"", find);
  53.                 if(find != -1 && findEnd != -1)
  54.                 {
  55.                     String s = line.substring(find + 1, findEnd);
  56.                     System.out.println(s);
  57.                     if(s != null && s != "" && !s.equals(symb))
  58.                         others.add(s);
  59.                     //System.out.println(others);
  60.                 }
  61.                 //find = line.indexOf("_aQ(", findEnd);
  62.                 find = line.indexOf("_aQ(", find + 1);
  63.             }
  64.         }
  65.     }
  66.    
  67.     public double getPrice()
  68.     {
  69.         return price;
  70.     }
  71.    
  72.     public String getName()
  73.     {
  74.         return name;
  75.     }
  76.  
  77.     public String getSymbol()
  78.     {
  79.         return symb;
  80.     }
  81.    
  82.     public ArrayList<String> getOthers()
  83.     {
  84.         System.out.println(others);
  85.         return others;
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement