Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program RSWorldParser;
- type
- world = record
- num, pla: Integer;
- pre, url, fla, loc, act: string;
- loo, qui, pvp, mem: Boolean;
- end;
- function Explode(str, del: string): TStringArray;
- var
- i, l: Integer;
- begin
- i := 0;
- l := -1;
- repeat
- Inc(l);
- SetLength(Result, l + 1);
- i := Pos(del, str);
- if i <= 0 then
- Break;
- Result[l] := Copy(str, 1, i - 1);
- Delete(str, 1, i + Length(del));
- until false
- Result[l] := Copy(str, 1, Length(str));
- end;
- procedure RewriteWorld;
- var
- worldList: array of world;
- str, FilePath: string;
- tsa, tsb: TStringArray;
- w: Integer;
- begin
- FilePath := AppPath + 'Includes\SRL\SCSS\worlds.ini';
- Writeln(FilePath);
- if FileExists(FilePath) then
- begin
- w := RewriteFile(filePath, False);
- WriteFileString(w, '');
- CloseFile(w);
- end;
- str := GetPage('http://www.runescape.com/slu.ws?order=WMPLA');
- Delete(str, 1, Pos('"Sort descending"', str));
- Delete(str, 1, Pos('<tr', str) + 3);
- tsa := Explode(str, '<tr');
- SetLength(worldList, High(tsa) + 1);
- for w := 0 to High(tsa) do
- with worldList[w] do
- begin
- tsb := Explode(tsa[w], '<td');
- if High(tsb) <= 7 then
- begin
- Writeln('Skipping world ' + IntToStr(w + 1) + ' because explosion didn''t return enough values');
- Continue;
- end;
- pla := StrToIntDef(Copy(tsb[2], 1, Pos(' Players', tsb[2]) - 1), 2000);
- fla := Between('"', '"', tsb[3]);
- loc := fla;
- case Uppercase(loc) of
- 'US': loc := 'United States';
- 'UK': loc := 'UK';
- 'NL': loc := 'Netherlands';
- 'CA': Loc := 'Canada';
- 'AU': Loc := 'Australia';
- 'SE': Loc := 'Sweden';
- 'FI': Loc := 'Finland';
- end;
- url := 'http://' + Between('>', '<', tsb[3]) + '/a2,m0,j0,o0';
- pre := Between('http://', '.runescape', url);
- num := StrToIntDef(Copy(pre, 6, Length(pre) - 5), -1);
- act := Copy(tsb[4], 1, Pos('<', tsb[4]) - 1);
- if act = '-' then
- act := '';
- loo := Between('title="', '"', tsb[5]) = 'Y';
- qui := Between('title="', '"', tsb[6]) = 'Y';
- pvp := Between('title="', '"', tsb[7]) = 'Y';
- mem := Between('>', '<', tsb[8]) = 'Members';
- end;
- WriteINI('Worlds', 'Count', IntToStr(High(worldList) + 1), FilePath);
- WriteINI('Worlds', 'High', IntToStr(worldList[High(worldList)].num), FilePath);
- for w := 0 to High(worldList) do
- with worldList[w] do
- begin
- if mem then
- str := 'Members'
- else
- str := 'Free';
- WriteINI('World' + IntToStr(num), 'Prefix', pre, FilePath);
- WriteINI('World' + IntToStr(num), 'URL', url, FilePath);
- WriteINI('World' + IntToStr(num), 'Activity', act, FilePath);
- WriteINI('World' + IntToStr(num), 'Type', str, FilePath);
- WriteINI('World' + IntToStr(num), 'Flag', fla + 'Flag', FilePath);
- WriteINI('World' + IntToStr(num), 'Location', loc, FilePath);
- WriteINI('World' + IntToStr(num), 'Lootshare', BoolToStr(loo), FilePath);
- WriteINI('World' + IntToStr(num), 'Quickchat', BoolToStr(qui), FilePath);
- WriteINI('World' + IntToStr(num), 'PvP', BoolToStr(pvp), FilePath);
- end;
- end;
- begin
- RewriteWorld;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement