Advertisement
Kylroi

8th wowhead item loot scanner - 2015-08-11

Nov 21st, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6.01 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # adjust path to fit your host
  3.  
  4. # Seventh generation item loot scanner
  5. # Designed for use with Trinity DB 4.3.4
  6. # Other DB formats should be easily implemented
  7.  
  8. # Output sorted in ascending order (lowest value first)
  9. # Output is NOT sent to a file. Redirect output as desired.
  10.  
  11. # THE OUTPUT MUST BE MANUALLY EDITED BEFORE IMPORTING TO THE DATABASE!
  12. # THE OUTPUT MUST BE MANUALLY EDITED BEFORE IMPORTING TO THE DATABASE!
  13. # THE OUTPUT MUST BE MANUALLY EDITED BEFORE IMPORTING TO THE DATABASE!
  14. # THE OUTPUT MUST BE MANUALLY EDITED BEFORE IMPORTING TO THE DATABASE!
  15.  
  16. # Use this only as a starting point for construction of loot templates
  17. # `Reference`, `Chance`, `QuestRequired` and `GroupId` CANNOT be correctly set from wowhead data
  18.  
  19. # usage:
  20. #        item.pl                   (takes input from STDIN, aka piped stream)
  21. #        item.pl item#             (reads the specified item from www.wowhead.com)
  22. #        item.pl startitem enditem (reads the given range of items from www.wowhead.com)
  23.  
  24. # Generation history:
  25. #    First: based on my NPC script, but for the current (Nov 21, 2013) wowhead stream
  26. #   Second: back-ported the line merging code update that was added while adjusting code for gameobjects
  27. #    Third: changed to an updated "sourcemore" (sub-group in the wowhead item entry) filter
  28. #    Forth: changed filter from "sourcemore" to "sourcemore"|"modelviewer" to strip both sub-groups
  29. #           replaced split function with a regex method for splitting the items up
  30. #    Fifth: altered comment header format
  31. #    Sixth: fixed line merging code to properly filter Windows line termination (\r\n)
  32. #  Seventh: updated for latest (last?) Trinity DB 4.3.4 database (Jan 14, 2015)
  33. #   Eighth: updated for latest (for August 11 of 2015) wowhead page structure
  34.  
  35. use warnings;
  36. use strict;
  37. use LWP::Simple;
  38.  
  39. my $currentItem;
  40. my $page;
  41. my $line;
  42. my @lines;
  43. my $ItemName;
  44. my $ItemID;
  45.  
  46. # item level then id sort order
  47. sub itemcmp {
  48.   $a =~ /^.*\,\"level\":(\d+)\,/;
  49.   my $x = $1;
  50.   $a =~ /^.*\"id\":(.+?)\,/;
  51.   my $xx = $1;
  52.   $b =~ /^.*\,\"level\":(\d+)\,/;
  53.   my $y = $1;
  54.   $b =~ /^.*\"id\":(.+?)\,/;
  55.   my $yy = $1;
  56.   if ($x eq $y) {
  57.     return ($xx <=> $yy);
  58.   } else {
  59.     return ($x <=> $y);
  60.   }
  61. }
  62.  
  63. # build MySQL query
  64. sub lootlist {
  65.   my ($entry, $opened, $items) = @_;
  66.   my $slot = 1;
  67.   $items =~ s/\,\"sourcemore\":\[.+?\]\,|\,\"modelviewer\":\{.+?\}\,/\,/g;
  68.   $items =~ s/\,pctstack:\'\{.+?\}\'//g;
  69.   $items =~ s/\,context:.+?\,/\,/g;
  70.   my @itemlist = ($items =~ m/\"classs\".+?\}/g);
  71.   @itemlist = sort itemcmp @itemlist;
  72.   print "-- wowhead submissions: $opened\n";
  73.   print "DELETE FROM `item_loot_template` WHERE `Entry`=$entry;\n";
  74.   print "INSERT INTO `item_loot_template` (`Entry`, `Item`, `Reference`, `Chance`, `QuestRequired`, `LootMode`, `GroupId`, `MinCount`, `MaxCount`, `Comment`) VALUES\n";
  75.   foreach my $itemdata (@itemlist) {
  76.     $itemdata =~ /^.*\"id\":(.+?)\,\"level\":(.+?)\,\"name\":\"(.+?)\".*\,count:(.+?)\,stack:\[(.+?)\,(.+?)\]/;    
  77.     my $id = $1;
  78.     my $ilvl = $2;
  79.     my $name = $3;
  80.     my $count = $4;
  81.     my $minval = $5;
  82.     my $maxval = $6;
  83.     my $pct = sprintf("%.2f", (($count / $opened) * 100));
  84.     if ($name =~ /^[+-]?\d/) {
  85.       $name =~ s/^.//;
  86.     }
  87.     print "\t($entry, $id, 0, $pct, 0, 1, 0, $minval, $maxval, '$name (ilvl $ilvl)')", ($slot < scalar(@itemlist)) ? "," : ";";
  88.     print " -- $count time", ($count > 1) ? "s" : " ", "\n";
  89.     $slot++;
  90.   }
  91.   print "\n";
  92. }
  93.  
  94. # print name & ID as a comment header
  95. sub header {
  96.   my $dashes;
  97.   foreach $line (@lines) {
  98.     if (defined $line && length $line > 0) {
  99.       chop($line);
  100.       if ($line =~ /\$\.extend\(g_items/) {
  101.         $line =~ /\$\.extend\(g_items\[(.+?)\].*\,\"name\":\"(.+?)\"/;
  102.         $ItemID = $1;
  103.         $ItemName = $2;
  104.         if ($ItemName =~ /^[+-]?\d/) {
  105.           $ItemName =~ s/^.//;
  106.         }
  107.         $dashes = length($ItemID) + length($ItemName) + 3;
  108.         print "-- ---" . "-" x $dashes . "---\n";
  109.         print "-- -- $ItemName \($ItemID\) --\n";
  110.         print "-- ---" . "-" x $dashes . "---\n\n";
  111.         print "-- EDIT ME - EDIT ME - EDIT ME - EDIT ME - EDIT ME - EDIT ME - EDIT ME - EDIT ME - EDIT ME\n";
  112.         print "-- `Chance` and `GroupId` columns MUST be adjusted before query is executed\n";
  113.         print "-- `Reference` and `QuestRequired` columns MAY need to be altered, too\n\n";
  114.       }
  115.     }
  116.   }
  117. }
  118.  
  119. # scan the page, obviously
  120. sub parsepage {
  121.   my $data;
  122.   my $totalcount;
  123.   my $linemerge = 0;
  124.   foreach $line (@lines) {
  125.     if (defined $line && length $line > 0) {
  126.       $line =~ s/\s+$//;
  127.     }
  128.     if (defined $line && length $line > 0) {
  129.       if ($linemerge == 0 && $line =~ /^\s+/) {
  130.         $line =~ s/^\s+//;
  131.         if ($line =~ /^new.Listview.*id:.\'contains\'/) {
  132.           $linemerge = 4;
  133.           $data = "";
  134.         }
  135.       }
  136.       if ($linemerge > 0) {
  137.         $line =~ s/^\s+//;
  138.         $data .= "$line ";
  139.         $linemerge--;
  140.         if ($linemerge == 0) {
  141.           $line = $data;
  142.         }
  143.       }
  144.       if ($linemerge == 0 && $line =~ /^new.Listview.*id:.\'contains\'/) {
  145.          $line =~ /^.*_totalCount:.(.+?)\,/;
  146.          $totalcount = $1;
  147.          $line =~ /^new.Listview.*id:.\'contains\'.*data: \[(.+?)\]\}\)/;
  148.          $data = $1;
  149.          header();
  150.          lootlist($ItemID, $totalcount, $data);
  151.       }
  152.     }
  153.   }
  154. }
  155.  
  156. # generate a URL and get the HTML source
  157. sub getpage {
  158.   my ($Item) = @_;
  159.   my $URL = "http://www.wowhead.com/item=$Item";
  160.   $page = get($URL);
  161.   $page =~ s/(\r\n)|(\r)/\n/g;
  162. }
  163.  
  164. if ($#ARGV == -1) {
  165.   while ($_ = <>) {
  166.     push (@lines, $_);
  167.   }
  168.   parsepage();
  169.   exit;
  170. } elsif ($#ARGV == 0) {
  171.   $currentItem = $ARGV[0];
  172.   getpage($currentItem);
  173.   @lines = split(/(\r)|(\n)|(\r\n)/, $page);
  174.   parsepage();
  175.   exit;
  176. } elsif ($#ARGV == 1) {
  177.   for ($currentItem = $ARGV[0]; $currentItem <= $ARGV[1]; $currentItem++) {
  178.     getpage($currentItem);
  179.     @lines = split(/(\r)|(\n)|(\r\n)/, $page);
  180.     parsepage();
  181.     if ($currentItem < $ARGV[1]) { sleep(5); }
  182.   }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement