program New;
const
DBLocation = 'C:\Program Files\SCAR 3.15\ItemDB\';
var
Page, ObjNum, ObjName, ObjPrice: String;
Letter, PLP1, PLP2, ObjNum1, PageLimit,
ObjNum2, ObjName2, ObjPrice2, ObjPrice1,
time, t, t1, PageNumber, theFile :integer;
ObjPriceN :extended;
PageLimitSet :boolean;
begin
time:=getsystemtime;
theFile := RewriteFile(DBLocation + Replace(DateToStr(Date), '/', '_') + '.idb', false);
Letter:=1;
repeat
PageNumber:=1;
repeat
if chr(64+Letter) = 'Q' then
begin
Letter:=Letter+1;
break;
end;
Page := GetPage('http://itemdb-rs.runescape.com/results.ws?query=&sup=Initial%20Letter&cat='+chr(Letter+64)+'&sub=All&page='+inttostr(PageNumber)+'&vis=1&order=1&sortby=name&price=&members=');
if not PageLimitSet then
begin
//writeln('Setting PageLimit');
PLP1:=Pos('<td class="navright">',Page);
PLP2:=LastPosEx('ers=">',Page,PLP1);
if PLP2=-1 then
begin
PageLimit:=1;
PageLimitSet:=true;
end;
if PageLimitSet=false then
begin
PLP1:=PosEx('</a>',Page,PLP2);
PageLimit:=strtoint(Copy(Page,PLP2+6,PLP1-PLP2-6));
end;
PageLimitSet:=true;
// writeln(chr(letter+64)+' '+inttostr(pagelimit));
end;
t:=Pos('Change Today',Page);
repeat
ObjNum1:=PosEx('em.ws?obj=',Page,t);
if ObjNum1=-1 then
begin
Page:='';
//writeln('Last Item '+inttostr(PageNumber)+' '+inttostr(pagelimit));
break;
end;
ObjNum2:=PosEx('">',Page,ObjNum1);
ObjNum:=Copy(Page,ObjNum1+10,ObjNum2-ObjNum1-10);
ObjName2:=PosEx('</a',Page,ObjNum2);
ObjName:=Copy(Page,ObjNum2+3,ObjName2-ObjNum2-3);
ObjPrice1:=PosEx('<td>',Page,ObjName2);
ObjPrice2:=PosEx('</td>',Page,ObjPrice1);
ObjPrice:=Copy(Page,ObjPrice1+4,ObjPrice2-ObjPrice1-4);
if pos('k',ObjPrice)>0 then
begin
ObjPriceN:=StrToFloat(TrimLetters(ObjPrice));
ObjPriceN:=ObjPriceN*1000;
end;
if pos('m',ObjPrice)>0 then
begin
ObjPriceN:=StrToFloat(TrimLetters(ObjPrice));
ObjPriceN:=ObjPriceN*1000000;
end;
ObjPrice:=TrimOthers(ObjPrice);
if (pos('k',ObjPrice)=0)and(pos('m',ObjPrice)=0) then
ObjPriceN := strtofloat(ObjPrice);
//writeln(ObjNum+': '+ObjName+' '+floattostr(ObjPriceN));
WriteFileString(theFile, '<n>' + ObjName + '</n> ' + '<id>' + ObjNum + '</id> ' + '<gp>' + floatToStr(ObjPriceN) + '</gp>' + chr(10));
//Dump to file, send to database, etc
t1:=t1+1;
t:=ObjName2;
until isfkeydown(11);
PageNumber:=PageNumber+1;
if PageNumber>PageLimit then
begin
PageLimitSet:=false;
Letter:=Letter+1;
break;
end;
until isfkeydown(11);
if Letter>26 then
break;
until isfkeydown(11);
CloseFile(theFile);
writeln(inttostr(t1)+' items in '+inttostr(getsystemtime-time)+'ms');
end.
Made Boreas' code output to a relatively easy to parse file. Took me 3 mins, 48 seconds to download & save.
Will work on a grapha after I finish my homework.
EDIT: Grapher is done, will post asap
EDIT: Grapher had some weird stuff going on with the gridlines, fixed it all, but somehow made gridline spacing pixel based rather than unit based. Here's the current grapher, the point plotting is accurate, but I'm going to have to work on the gridline algorithm before everything looks accurate. Also, if you don't force the axis to be visible, gridlines and axislines go waay out of sync with the graph. Working on this problem also.
EDIT: Still trying to fix the pesky gridlines..
TODO:
-Fix gridlines (priority)
-Axis-disable feature
-Axis movement bug
//GraphPxlsX, GraphPxlsY -> Size of graph on screen
//pts: TPointArray -> Data to be graphed
//GraphBCGColor, GraphAxisColor, GraphLineColor -> Various colors
//zoom -> How much to zoom the graph output
//Axis_ForceVisible -> Forces the origin (0,0) to be visible in the graph
//gridlines -> Shows gridlines
//GridlineXSpacing, GridlineYSpacing -> How far apart the gridlines should be
//GridlineColor -> Gridline color
program New;
procedure GraphPtsEx(GraphPxlsX, GraphPxlsY: integer; pts: TPointArray; GraphBCGColor, GraphAxisColor, GraphLineColor, zoom: integer; Axis_ForceVisible: boolean; gridlines: boolean; GridlineXSpacing, GridlineYSpacing, GridlineColor: integer);
var
x_min, x_max, y_min, y_max: integer;
i, temp: integer;
scaleX, scaleY: extended;
Graph_BMP: integer;
begin
//Param-error catching
if(GraphPxlsX = 0)then
Exit;
if(GraphPxlsY = 0)then
Exit;
if(zoom = 0)then
Exit;
if(GridlineXSpacing = 0)then
Exit;
if(GridlineYSpacing = 0)then
Exit;
//Create the bitmap that the graph will be displayed on and fill with a given color
DisplayDebugImgWindow(GraphPxlsX * zoom, GraphPxlsY * zoom);
Graph_BMP := BitmapFromString(GraphPxlsX, GraphPxlsY, '');
FastDrawClear(Graph_BMP, GraphBCGColor);
if(Axis_ForceVisible = false)then
begin
x_min := pts[0].x;
y_min := pts[0].y;
end;
//Find lowest and highest points
for i := 0 to high(pts) do
begin
if(pts[i].x < x_min)then
x_min := pts[i].x;
if(pts[i].x > x_max)then
x_max := pts[i].x;
if(pts[i].y < y_min)then
y_min := pts[i].y;
if(pts[i].y > y_max)then
y_max := pts[i].y;
end;
//add a 10% 'buffer' to the x axis
temp := (round(abs(x_max) + abs(x_min))) / 10;
x_min := x_min - temp;
x_max := x_max + temp;
//add a 10% 'buffer' to the y axis
temp := (round(abs(y_max) + abs(y_min))) / 10;
y_min := y_min - temp;
y_max := y_max + temp;
//Debug
{writeln(inttostr(x_min));
writeln(inttostr(x_max));
writeln(inttostr(y_min));
writeln(inttostr(y_max));}
//Determine Graph-point to pixel scale
scaleX := GraphPxlsX / round(abs(x_max) + abs(x_min));
scaleY := GraphPxlsY / round(abs(y_max) + abs(y_min));
//Debug
writeln(floattostr(scaleX));
writeln(floattostr(scaleY));
//GridlineXSpacing := round(GridlineXSpacing * ScaleX);
//GridlineYSpacing := round(GridlineYSpacing * ScaleY);
//Draw vertical gridlines
for temp := 0 to round(GraphPxlsX / (GridlineXSpacing * ScaleX)) do
//Reason for following if statement: Sometimes the gridline plotting algorithm would plot a gridline at a location outside the picture; this would sometimes throw an access violation error, but other times, it would simply wrap the pixels over to the other side of the bitmap, causing erratic gridlines to pop up in very strangle places
if((GridlineXSpacing * temp) + (round(abs(x_min) * scaleX) mod GridlineXSpacing) <= 125)then
for i := 0 to GraphPxlsX - 1 do
FastSetPixel(Graph_BMP, round(GridlineXSpacing * temp * ScaleX) + (round(abs(x_min) * scaleX) mod GridlineXSpacing), i, GridlineColor);
//round((abs(x_min) * scaleX) + pts[i].x * scaleX)
//round(GraphPxlsY - (abs(y_min * scaleY) + (pts[i].y * scaleY)))
//Draw horizontal gridlines
for temp := 0 to round(GraphPxlsY / (GridlineYSpacing * ScaleY)) do
//Read similar note above
if((GridlineYSpacing * temp) + (round(((GraphPxlsY / ScaleY) - abs(y_min)) * scaleY) mod GridlineYSpacing) <= 125)then
for i := 0 to GraphPxlsY - 1 do
FastSetPixel(Graph_BMP, i, round(GridlineYSpacing * temp * ScaleY) + (round(((GraphPxlsY / ScaleY) - abs(y_min)) * scaleY) mod GridlineYSpacing), GridlineColor);
// writeln(inttostr((GridlineYSpacing * temp) + (round(((GraphPxlsY / ScaleY) - abs(y_min)) * scaleY) mod GridlineYSpacing)));
//Draw vertical axis
for i := 0 to GraphPxlsX - 1 do
FastSetPixel(Graph_BMP, round(abs(x_min) * scaleX), i, GraphAxisColor);
//Draw horizontal axis
for i := 0 to GraphPxlsY - 1 do
FastSetPixel(Graph_BMP, i, round(((GraphPxlsY / ScaleY) - abs(y_min)) * scaleY), GraphAxisColor);
//Graph the points
for i := 0 to high(pts) do
begin
//Debug
//writeln(inttostr(round(((0 - x_min) * scaleX) + pts[i].x * scaleX)));
//writeln(inttostr(round(GraphPxlsY - ((0 - (y_min * scaleY)) + (pts[i].y * scaleY)))));
try
FastSetPixel(Graph_BMP, round((abs(x_min) * scaleX) + pts[i].x * scaleX), round(GraphPxlsY - (abs(y_min * scaleY) + (pts[i].y * scaleY))) {round((GraphPxlsY - (0 - (y_min * scaleY))) - (y_min * scaleY + pts[i].y * scaleY))}, GraphLineColor);
except
writeln('Error at pt ' + inttostr(i + 1));
end;
end;
//Display graph and free resources
SafeCopyCanvas(GetBitmapCanvas(Graph_BMP), GetDebugCanvas, 0, 0, GraphPxlsX, GraphPxlsY, 0, 0, GraphPxlsX * zoom, GraphPxlsY * zoom);
FreeBitmap(Graph_BMP);
end;
//Displays graph with white background, brown axis, and black points
procedure GraphPts(GraphPxlsX, GraphPxlsY: integer; pts: TPointArray);
begin
GraphPtsEx(GraphPxlsX, GraphPxlsY, pts, 16777215, 5018076, 0, 1, false, true, 10, 10, 16701619);
end;
begin
// GraphPtsEx(125, 125, [Point(5, 3){, Point(-5, -7), Point(0, 0), Point(1, 1)}, Point(5, 5), Point(10, 10)], 16777215, 5018076, 0, 3, false, true, 10, 10, 16701619);
GraphPtsEx(125, 125, [Point(0, 0), Point(1, 1), Point(5, 5), Point(10, 10)], 16777215, 5018076, 0, 3, true, true, 1, 1, 16701619);
end.