Advertisement
mixster

mixster

Oct 18th, 2008
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.19 KB | None | 0 0
  1. program RSWorldParser;
  2. type
  3.   world = record
  4.     num, pla: Integer;
  5.     pre, url, fla, loc, act: string;
  6.     loo, qui, pvp, mem: Boolean;
  7.   end;
  8. var
  9.   worldList: array of world;
  10.   str: string;
  11.   tsa, tsb: TStringArray;
  12.   w: Integer;
  13.   dlgSave: TSaveDialog;
  14.  
  15. function Explode(str, del: string): TStringArray;
  16. var
  17.   i, l: Integer;
  18. begin
  19.   i := 0;
  20.   l := -1;
  21.   repeat
  22.     Inc(l);
  23.     SetLength(Result, l + 1);
  24.     i := Pos(del, str);
  25.     if i <= 0 then
  26.       Break;
  27.     Result[l] := Copy(str, 1, i - 1);
  28.     Delete(str, 1, i + Length(del));
  29.   until false
  30.   Result[l] := Copy(str, 1, Length(str));
  31. end;
  32.  
  33. begin
  34.   dlgSave := TSaveDialog.Create(nil);
  35.   dlgSave.Filter := 'ini files|*.ini';
  36.   if not dlgSave.Execute then
  37.     TerminateScript;
  38.   str := GetPage('http://www.runescape.com/slu.ws?order=WMPLA');
  39.   Delete(str, 1, Pos('"Sort descending"', str));
  40.   Delete(str, 1, Pos('<tr', str) + 3);
  41.   tsa := Explode(str, '<tr');
  42.   SetLength(worldList, High(tsa) + 1);
  43.   for w := 0 to High(tsa) do
  44.     with worldList[w] do
  45.     begin
  46.       tsb := Explode(tsa[w], '<td');
  47.       if High(tsb) <= 7 then
  48.       begin
  49.         Writeln('Skipping world ' + IntToStr(w + 1) + ' because explosion didn''t return enough values');
  50.         Continue;
  51.       end;
  52.       pla := StrToIntDef(Copy(tsb[2], 1, Pos(' Players', tsb[2]) - 1), 2000);
  53.       fla := Between('"', '"', tsb[3]);
  54.       loc := fla;
  55.       case Uppercase(loc) of
  56.         'US': loc := 'United States';
  57.         'UK': loc := 'UK';
  58.         'NL': loc := 'Netherlands';
  59.         'CA': Loc := 'Canada';
  60.         'AU': Loc := 'Australia';
  61.         'SE': Loc := 'Sweden';
  62.         'FI': Loc := 'Finland';
  63.       end;
  64.       url := 'http://' + Between('>', '<', tsb[3]) + '/a2,m0,j0,o0';
  65.       pre := Between('http://', '.runescape', url);
  66.       num := StrToIntDef(Copy(pre, 6, Length(pre) - 5), -1);
  67.       act := Copy(tsb[4], 1, Pos('<', tsb[4]) - 1);
  68.       if act = '-' then
  69.         act := '';
  70.       loo := Between('title="', '"', tsb[5]) = 'Y';
  71.       qui := Between('title="', '"', tsb[6]) = 'Y';
  72.       pvp := Between('title="', '"', tsb[7]) = 'Y';
  73.       mem := Between('>', '<', tsb[8]) = 'Members';
  74.     end;
  75.   WriteINI('Worlds', 'Count', IntToStr(High(worldList) + 1), dlgSave.FileName);
  76.   WriteINI('Worlds', 'High', IntToStr(worldList[High(worldList)].num), dlgSave.FileName);
  77.   for w := 0 to High(worldList) do
  78.     with worldList[w] do
  79.     begin
  80.       if mem then
  81.         str := 'Members'
  82.       else
  83.         str := 'Free';
  84.       WriteINI('World' + IntToStr(num), 'Prefix', pre, dlgSave.FileName);
  85.       WriteINI('World' + IntToStr(num), 'URL', url, dlgSave.FileName);
  86.       WriteINI('World' + IntToStr(num), 'Activity', act, dlgSave.FileName);
  87.       WriteINI('World' + IntToStr(num), 'Type', str, dlgSave.FileName);
  88.       WriteINI('World' + IntToStr(num), 'Flag', fla + 'Flag', dlgSave.FileName);
  89.       WriteINI('World' + IntToStr(num), 'Location', loc, dlgSave.FileName);
  90.       WriteINI('World' + IntToStr(num), 'Lootshare', BoolToStr(loo), dlgSave.FileName);
  91.       WriteINI('World' + IntToStr(num), 'Quickchat', BoolToStr(qui), dlgSave.FileName);
  92.       WriteINI('World' + IntToStr(num), 'PvP', BoolToStr(pvp), dlgSave.FileName);
  93.     end;
  94. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement