Changeset 631 for tools


Ignore:
Timestamp:
Dec 8, 2013, 8:06:28 PM (10 years ago)
Author:
maron
Message:
  • Added: GetmaxEntry from web for every type text
  • Added: option type of import
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/WoWHeadLoader/WoWHeadLoader.lpr

    r617 r631  
    5353    function GetEndtextData(data:string): string;
    5454    procedure GetTextQuest(Id: Integer);
    55     procedure UpdateQuest;
    5655
    5756    function GetMaxID(TextType: string): integer;
     
    6362  GroupDB: array [1..6] of string = ('TextAchievement','TextItem','TextCreature','TextGameObject','TextArea','TextQuest');
    6463  Column2DB: array [1..6] of string = ('Description','Description','SubName','','','');
    65 
     64  ImportTable: integer = 6;
    6665{ TWoWHeadLoader }
    6766//   IdHTTP1.Request.UserAgent:= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
     
    7473begin
    7574  // quick check parameters
    76   ErrorMsg:=CheckOptions('h','help');
     75  ErrorMsg:=CheckOptions('hsuptai','helpschemauserpasswordhostCharsetimporttable');
    7776  if ErrorMsg<>'' then begin
    7877    ShowException(Exception.Create(ErrorMsg));
     
    107106    Database.Encoding := GetOptionValue('a', 'Charset');
    108107  end else Database.Encoding := 'utf8';
     108  if HasOption('i', 'importtable') then begin
     109    ImportTable := StrToInt(GetOptionValue('i', 'importtable'));
     110  end else ImportTable := 6;
    109111
    110112  Database.Connect;
     
    137139begin
    138140  { add your help code here }
    139   writeln('Usage: ',ExeName,' -h');
     141  WriteLn('Usage: ', ExtractFileName(ExeName), ' [options]');
     142  WriteLn('  -h --help        Show this help');
     143  WriteLn('  -u --user        Database user name, default root');
     144  WriteLn('  -p --password    Database password name');
     145  WriteLn('  -s --schema      Database schema name, default wowpreklad');
     146  WriteLn('  -t --host        Database host name, default localhost');
     147  WriteLn('  -a --Charset     Database Charset, default utf8');
     148  WriteLn('  -i --importtable Table import: TextAchievement=1,TextItem=2,TextCreature=3,TextGameObject=4,TextArea=5,TextQuest=6, default 6');
    140149end;
    141150
     
    145154begin
    146155//  UpdateQuest;
     156  {
     157  GetText(1132,2);
     158    GetText(1132,2);
     159    GetText(1284,2);
     160    GetText(1180,2);
     161    GetText(1327,2);
     162     GetText(1361,2);
     163     GetText(1384,2);
    147164  GetText(1111,1);
    148   GetText(98148,2);
    149165  GetText(29,3);
    150166  GetText(55,4);
    151167  GetText(15,5);
    152168  GetText(4,6);
    153   for t :=1 to Length(Group) do
    154     for i := 0 to 1000 do begin //GetMaxID('quest')
    155       GetText(i,t);
    156      // write('.');
     169  }
     170 // for t :=1 to Length(Group) do
     171    for i := 1 to GetMaxID(Group[ImportTable]) do begin //GetMaxID('quest')
     172      GetText(i,ImportTable);
     173      write('.');
    157174    end;
    158175  //čekej před uzavřením
     
    270287      begin
    271288        //text je stejný
    272         Database.Query('UPDATE  `wowpreklad`.`TextQuest` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Id` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
    273         Database.Query('UPDATE  `wowpreklad`.`TextQuest` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Take` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
     289        Database.Query('UPDATE  `TextQuest` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Id` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
     290        Database.Query('UPDATE  `TextQuest` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Take` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
    274291        UpdateTranslated('textquest');
    275292        Exit;   //konec: text je stejný upravili se jenom výsledné verze
     
    286303    begin
    287304      {
    288       WriteLn('INSERT INTO  `wowpreklad`.`TextQuest` ('
     305      WriteLn('INSERT INTO  `TextQuest` ('
    289306      +'`ID` ,`Entry` ,`Title` ,`Details` ,`Objectives` ,`OfferRewardText` ,`RequestItemsText` ,`EndText` ,'
    290307      +'`ObjectiveText1` ,`ObjectiveText2` ,`ObjectiveText3` ,`ObjectiveText4` '
     
    303320      +'0,  NULL, 1,0,NULL,'+IntToStr(ImportedVersion)+','+IntToStr(ImportedVersion)+',NOW())');
    304321      }
    305       Database.Query('INSERT INTO  `wowpreklad`.`TextQuest` ('
     322      Database.Query('INSERT INTO  `TextQuest` ('
    306323      +'`ID` ,`Entry` ,`Title` ,`Details` ,`Objectives` ,`OfferRewardText` ,`RequestItemsText` ,`EndText` ,'
    307324      +'`ObjectiveText1` ,`ObjectiveText2` ,`ObjectiveText3` ,`ObjectiveText4` '
     
    365382end;
    366383
    367 procedure TWoWHeadLoader.UpdateQuest;
    368 var
    369   data : string;
    370   i:integer;
    371 begin
    372   GetTextQuest(7081);
    373   GetTextQuest(7122);
    374   GetTextQuest(9192);
    375 
    376   GetTextQuest(12509);
    377 
    378 
    379   GetTextQuest(12580);
    380 
    381   GetTextQuest(13369);
    382 
    383   GetTextQuest(13425);
    384 
    385   GetTextQuest(13675);
    386 
    387   GetTextQuest(13426);
    388 
    389 
    390 
    391 
    392   for i := 0 to GetMaxID('quest') do begin
    393     GetTextQuest(i);
    394     write('.');
    395   end;
    396 end;
    397 
    398384procedure TWoWHeadLoader.GetText(Id: Integer; TextType: Integer);
    399385var
     
    425411       foundtext:=false;
    426412       Exit;
     413     end;
     414
     415     if ('item' = Group[TextType]) then begin
     416       if (Pos('<span class="q2">Use:',data) >0) then begin
     417         data := skipto('<span class="q2">Use:',data);
     418         data := skipto('>',data);
     419       //  textdescription := TextStringReplace(Copy(data,0,Pos('</a',data)-1));
     420       //zatím nefunguje
     421       end;
    427422     end;
    428423
     
    436431     //description
    437432     data := skipto('</h1>',data);
    438      for i:= 0 to 4 do begin
    439        data := StringReplace(data,'<br>','$B',[rfIgnoreCase]);
    440        data := StringReplace(data,'<br />','$B',[rfIgnoreCase]);
    441      end;
     433
    442434     if ('' <> Column2DB[TextType]) then
    443      if ('item' = Group[TextType]) then begin
    444        data := skipto('Use:',data);
    445        data := skipto('<',data);
    446      //  textdescription := TextStringReplace(Copy(data,0,Pos('<',data)-1));
    447      end else begin
     435     if ('item' <> Group[TextType]) then begin
    448436         data := skipto('<script type="text/javascript">',data);
    449437         data := skipto('</script>',data);
     
    470458         begin
    471459           //text je stejný
    472            Database.Query('UPDATE  `wowpreklad`.`'+GroupDB[TextType]+'` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Id` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
    473            Database.Query('UPDATE  `wowpreklad`.`'+GroupDB[TextType]+'` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Take` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
     460           Database.Query('UPDATE  `'+GroupDB[TextType]+'` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Id` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
     461           Database.Query('UPDATE  `'+GroupDB[TextType]+'` SET  `VersionEnd` = '+IntToStr(ImportedVersion)+' WHERE  `Take` = '+DBRows.Data[0].Values['Id']+' AND `Entry` ='+IntToStr(Id)+';');
    474462           WriteLn('update');
    475463           UpdateTranslated(GroupDB[TextType]);
     
    477465         end;
    478466      end;
    479         sql := 'INSERT INTO  `wowpreklad`.`'+GroupDB[TextType]+'` (`ID` ,`Entry` ,`Name`,';
     467        sql := 'INSERT INTO  `'+GroupDB[TextType]+'` (`ID` ,`Entry` ,`Name`,';
    480468        if (Column2DB[TextType] <> '') then  sql += '`'+Column2DB[TextType]+'` ,';
    481469        sql +='`Language` , `User` , `Complete` ,`CompleteParts` ,`Take` ,`VersionStart` ,`VersionEnd` ,`ModifyTime`)'
     
    502490function TWoWHeadLoader.GetMaxID(TextType: string): integer;
    503491var
    504   data:string;
    505   maxid:integer=10000; //34000 pro questy
     492  data,cr:string;
     493  maxid:integer=1000; //34000 pro questy
    506494begin
    507495//  http://www.wowhead.com/quests?filter=cr=30;crs=1;crv=34000
    508   repeat
    509 
    510     data := IdHTTP1.Get('http://www.wowhead.com/'+TextType+'?filter=cr=30;crs=1;crv='+IntToStr(maxid));
    511     result := maxid;
    512     maxid := maxid+400;
    513   until (Pos('Your criteria did not match',data) > 0);
     496  if (TextType = 'quest') then begin
     497     maxid := 34000;
     498     cr := '30';
     499  end;
     500  if (TextType = 'npc') then begin
     501    //http://www.wowhead.com/npcs?filter=cr=37;crs=1;crv=10000
     502     maxid := 74000;
     503     cr := '37';
     504  end;
     505  if (TextType = 'achievement') then begin
     506    //http://www.wowhead.com/achievements?filter=cr=9;crs=1;crv=8000
     507     maxid := 8000;
     508     cr := '9';
     509  end;
     510  if (TextType = 'object') then begin
     511    //http://www.wowhead.com/objects?filter=cr=15;crs=1;crv=230000
     512     maxid := 230000;
     513     cr := '15';
     514  end;
     515  if (TextType = 'item') then begin
     516    //http://www.wowhead.com/items?filter=cr=151;crs=1;crv=106000
     517     maxid := 106000;
     518     cr := '151';
     519  end;
     520  if (TextType = 'zone') then begin
     521     maxid := 10000;
     522     result := maxid;
     523     Exit;
     524     cr := '30';
     525  end;
     526  result := maxid;
     527  try
     528    repeat
     529      data := IdHTTP1.Get('http://www.wowhead.com/'+TextType+'s?filter=cr='+cr+';crs=1;crv='+IntToStr(maxid));
     530      result := maxid;
     531      WriteLn(TextType+'s MaxID='+IntToStr(maxid));
     532      maxid := maxid+400;
     533    until (Pos('Your criteria did not match',data) > 0);
     534  except
     535     on E: EIdHTTPProtocolException do
     536      begin
     537        if E.ErrorCode = 404 then begin
     538        end;
     539      end;
     540       on E:Exception do
     541  end;
    514542end;
    515543
     
    521549  DBRows := Database.Query('SELECT * FROM  ClientVersion WHERE  `Title` !=  "" ORDER BY  `ClientVersion`.`BuildNumber` DESC LIMIT 0 , 30');
    522550  Result := StrToInt(DBRows.Data[0].Values['BuildNumber']);
    523   Database.Query('UPDATE  `wowpreklad`.`ClientVersion` SET  `Imported` = 1 WHERE  `clientversion`.`BuildNumber` ='+DBRows.Data[0].Values['BuildNumber']+';');
     551  Database.Query('UPDATE  `ClientVersion` SET  `Imported` = 1 WHERE  `clientversion`.`BuildNumber` ='+DBRows.Data[0].Values['BuildNumber']+';');
    524552end;
    525553
Note: See TracChangeset for help on using the changeset viewer.