Advertisement
mixster

mixster

Dec 11th, 2008
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.73 KB | None | 0 0
  1. program GE_Price_Downloader;
  2. type
  3.   item = record
  4.     name: string;
  5.     id, minP, curP, maxP: Integer;
  6.   end;
  7.  
  8. var
  9.   items: array of item;
  10.   c, p: Integer;
  11.   n, e: TStringArray;
  12.   s: string;
  13.  
  14.  
  15. // http://itemdb-rs.runescape.com/viewitem.ws?obj=10392
  16. // http://itemdb-rs.runescape.com/results.ws?query=&sup=Initial Letter&cat=A
  17.  
  18.  
  19. procedure Writelm(input: array of Variant);
  20. var
  21.   i: Integer;
  22.   s: string;
  23. begin
  24.   for i := 0 to High(input) do
  25.     s := s + input[i];
  26.   Writeln(s);
  27. end;
  28.  
  29. function ExplodeM(str, del: string): TStringArray;
  30. var
  31.   i: Integer;
  32. begin
  33.   repeat
  34.     SetLength(Result, High(Result) + 2);
  35.     i := Pos(del, str);
  36.     if i < 1 then
  37.       Break;
  38.     Result[High(Result)] := Copy(str, 1, i - 1);
  39.     Delete(str, 1, i + Length(del) - 1);
  40.   until False;
  41.   Result[High(Result)] := str;
  42. end;
  43.  
  44. function ConvertPrice(input: string): Integer;
  45. var
  46.   f: Extended;
  47. begin
  48.   input := Replace(Lowercase(Trim(input)), ',', '');
  49.   if (Pos('m', input) > 0) then
  50.     f := StrToFloatDef(Copy(input, 1, Pos('m', input) - 1), 0) * 1000000
  51.   else if (Pos('k', input) > 0) then
  52.     f := StrToFloatDef(Copy(input, 1, Pos('k', input) - 1), 0) * 1000
  53.   else
  54.     f := StrToFloatDef(Input, 0);
  55.   Result := Round(f);
  56. end;
  57.  
  58. begin
  59.   SetLength(n, 1);
  60. //  for c := 0 to 26 do
  61.   //  n[c] := Chr(Ord('a') + c);
  62.   n[0] := 'other';
  63.  
  64.   for c := 0 to High(n) do
  65.   begin
  66.     s := GetPage('http://itemdb-rs.runescape.com/results.ws?query=&sup=Initial Letter&cat=' + n[c]);
  67.     for p := 1 to StrToIntDef(Between('page=', '&amp', Copy(s, Pos('Next &gt;', s), 200)), 1) do
  68.     begin
  69.       s := GetPage('http://itemdb-rs.runescape.com/results.ws?query=&sup=Initial Letter&cat=' + n[c] + '&page=' + IntToStr(p));
  70.       Delete(s, 1, Pos('tbody>' + #10 + '<tr', s) + 10);
  71.       e := ExplodeM(s, '</tr>' + #10 + '<tr');
  72.       e[High(e)] := Copy(e[High(e)], 1, Pos('</tr>', e[High(e)]));
  73.       Writelm([n[c], ':', p]);
  74.     end;
  75.   end;
  76.  
  77.   SetLength(items, High(e) + 1);
  78.   for c := 0 to High(e) do
  79.   begin
  80.     with items[c] do
  81.     begin
  82.       name := Between('alt="', '"', e[c]);
  83.       id := StrToIntDef(Between('obj=', '"', e[c]), -1);
  84.       if (id < 0) then
  85.       begin
  86.         Writelm([c, ': ', name, ' :: ', id, ' :: ', minP, '; ', curP, '; ', maxP, ';']);
  87.         Continue;
  88.       end;
  89.       s := GetPage('http://itemdb-rs.runescape.com/viewitem.ws?obj=' + IntToStr(id));
  90.       minP := ConvertPrice(Between('<b>Minimum price:</b> ', #10 + '</span>', s));
  91.       curP := ConvertPrice(Between('<b>Market price:</b> ', #10 + '</span>', s));
  92.       maxP := ConvertPrice(Between('<b>Maximum price:</b> ', #10 + '</span>', s));
  93.       Writelm([c, ': ', name, ' :: ', id, ' :: ', minP, '; ', curP, '; ', maxP, ';']);
  94.     end;
  95.   end;
  96. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement