Ejemplo n.º 1
0
 public function __construct(SetDB $setDB, CardDB $cardDB)
 {
     $this->cardDB = $cardDB;
     $file = fopen_utf8('data/formats.txt', 'r');
     while (!feof($file)) {
         $format = trim(fgets($file, 6000));
         if (!$format) {
             continue;
         }
         $this->formats[] = $format;
         $this->formatToBanned[$format] = array();
         $this->formatToRestricted[$format] = array();
         $this->formatToSets[$format] = array();
         $state = null;
         while (!feof($file)) {
             $line = trim(fgets($file, 6000));
             if (!$line) {
                 break;
             }
             if ($line == 'BANNED' || $line == 'RESTRICTED' || $line == 'SETS') {
                 $state = $line;
                 continue;
             }
             $line = strtolower($line);
             switch ($state) {
                 case 'BANNED':
                     $this->formatToBanned[$format][] = $line;
                     break;
                 case 'RESTRICTED':
                     $this->formatToRestricted[$format][] = $line;
                     break;
                 case 'SETS':
                     $set = $setDB->normalize($line);
                     if (!$set) {
                         error('Error parsing "data/formats.txt". Unknown set: ' . $set);
                     }
                     $this->formatToSets[$format][] = $set;
                     break;
                 default:
                     error('Error parsing "data/formats.txt". Invalid section: ' . $line);
             }
         }
     }
     fclose($file);
 }
Ejemplo n.º 2
0
        $set = substr($title, strrpos($title, '(') + 1, -1);
        $title = substr($title, 0, strrpos($title, '(') - 1);
    } else {
        $set = null;
    }
    $price = trim(substr($line, $comma + 3, strpos($line, ',', $comma + 3)));
    if (!@$prices[$title]) {
        $prices[$title] = array();
    }
    if (!@$prices[$title]['']) {
        $prices[$title][''] = array();
    }
    $prices[$title][''][] = $price;
    asort($prices[$title]['']);
    if ($set) {
        $mainSet = $setDB->normalize($set);
        if ($mainSet) {
            $prices[$title][$mainSet] = $price;
        }
        //if (!$mainSet) echo "\nUnknown set \"$set\" for card: $title";
    }
    $count++;
    if ($count % 200 == 0) {
        echo '.';
    }
}
fclose($file);
echo "\n{$count} prices downloaded.\nCalculating totals...\n\n";
$grandTotal = 0;
foreach ($files as $file) {
    $decklist = new Decklist($setDB, $cardDB, $convertor, $file, true);
Ejemplo n.º 3
0
 public function __construct(SetDB $setDB, ArtDB $artDB)
 {
     global $config;
     $this->setDB = $setDB;
     $this->artDB = $artDB;
     // Load english cards.
     echo 'Loading card data';
     $file = fopen_utf8('data/cards.csv', 'r');
     if (!$file) {
         error('Unable to open file: data/cards.csv');
     }
     $i = 0;
     while (($row = fgetcsv($file, 6000, ',')) !== FALSE) {
         if ($i++ % 400 == 0) {
             echo '.';
         }
         $card = CardDB::rowToCard($row);
         // Ignore cards with an unknown set.
         $card->set = $setDB->normalize($card->set);
         if (!$card->set) {
             continue;
         }
         $title = strtolower($card->title);
         if (!@$this->titleToCards[$title]) {
             $this->titleToCards[$title] = array();
         }
         $this->titleToCards[(string) $title][] = $card;
     }
     fclose($file);
     echo "\n";
     // Load foreign card data.
     $language = strtolower($config['output.language']);
     if ($language && $language != 'english') {
         echo "Loading {$language} card data";
         $file = fopen_utf8("data/cards-{$language}.csv", 'r');
         if (!$file) {
             error("Unable to open file: data/cards-{$language}.csv");
         }
         $i = 0;
         while (($row = fgetcsv($file, 6000, ',')) !== FALSE) {
             if ($i++ % 400 == 0) {
                 echo '.';
             }
             // Overwrite some of the english card values with the foreign values.
             $englishTitle = strtolower($row[0]);
             $cards = @$this->titleToCards[(string) $englishTitle];
             if (!$cards) {
                 //print_r($row);
                 echo "\nError matching card data for card: {$row['0']}";
                 continue;
                 // Skip errors
             }
             foreach ($cards as $card) {
                 CardDB::applyLanguageRowToCard($row, $card);
             }
         }
         fclose($file);
         echo "\n";
         if (!$config['output.english.flavor.text']) {
             echo "Loading {$language} card flavor data";
             $file = fopen_utf8("data/cards-{$language}-flavor.csv", 'r');
             if (!$file) {
                 echo "\nNo localized flavor for language: {$language}";
             } else {
                 $i = 0;
                 while (($row = fgetcsv($file, 6000, ',')) !== FALSE) {
                     if ($i++ % 400 == 0) {
                         echo '.';
                     }
                     // Overwrite some of the english card values with the foreign values.
                     $englishTitle = strtolower($row[0]);
                     $cards = @$this->titleToCards[(string) $englishTitle];
                     if (!$cards) {
                         //print_r($row);
                         echo "\nError matching card flavor for card: {$row['0']}";
                         continue;
                         // Skip errors.
                     }
                     // Find the card from needed edition and apply localized flavor.
                     foreach ($cards as $card) {
                         if ($card->set == $setDB->normalize($row[1])) {
                             $card->flavor = $row[2];
                             break;
                         }
                     }
                 }
                 fclose($file);
                 echo "\n";
             }
         }
     }
 }