Advertisement
mixster

mixster

Jan 18th, 2009
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.18 KB | None | 0 0
  1. program RSWorldParser;
  2. type
  3.   world = record
  4.     num, pla: Integer;
  5.     pre, 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) - 1);
  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('<a href="?order=MWPLA">', 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], 2, Pos(' Players', tsb[2]) - 2), 2000);
  53.       fla := Between('"', '"', tsb[3]);
  54.       case Uppercase(fla) of
  55.         'US': loc := 'United States';
  56.         'UK': loc := 'UK';
  57.         'NL': loc := 'Netherlands';
  58.         'CA': Loc := 'Canada';
  59.         'AU': Loc := 'Australia';
  60.         'SE': Loc := 'Sweden';
  61.         'FI': Loc := 'Finland';
  62.         'NO': Loc := 'Norway';
  63.       end;
  64.       pre := Between('http://', '.runescape', tsb[1]);
  65.       if pre = '' then
  66.         pre := Replace(Lowercase(Between('>' + #10, #10 + #10, tsb[1])), ' ', '');
  67.       num := StrToIntDef(Replace(pre, 'world', ''), -1);
  68.       if num = -1 then
  69.         Writeln(tsb[1] + ' || ' + pre);
  70.       act := Between('>', '<', tsb[4]);
  71.       loo := Between('title="', '"', tsb[5]) = 'Y';
  72.       qui := Between('title="', '"', tsb[6]) = 'Y';
  73.       pvp := Between('title="', '"', tsb[7]) = 'Y';
  74.       mem := Between('>', '<', tsb[8]) = 'Members';
  75.     end;
  76.   WriteINI('Worlds', 'Count', IntToStr(High(worldList) + 1), dlgSave.FileName);
  77.   WriteINI('Worlds', 'High', IntToStr(worldList[High(worldList)].num), dlgSave.FileName);
  78.   for w := 0 to High(worldList) do
  79.     with worldList[w] do
  80.     begin
  81.       if mem then
  82.         str := 'Members'
  83.       else
  84.         str := 'Free';
  85.       WriteINI('World' + IntToStr(num), 'Prefix', pre, 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