Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modern flag is gonna have issues with Modern Horizons. #196

Open
silasary opened this issue Mar 14, 2019 · 3 comments
Open

Modern flag is gonna have issues with Modern Horizons. #196

silasary opened this issue Mar 14, 2019 · 3 comments

Comments

@silasary
Copy link
Member

Should probably speak to mtgjson about an explicit "Modern Legal flag" or something?

@stash86
Copy link

stash86 commented Mar 14, 2019

I scrapped the legal sets from wotc website, so supposed to be okay

@stash86
Copy link

stash86 commented Mar 14, 2019

I’ll upload the code later

@stash86
Copy link

stash86 commented Mar 14, 2019

As long as wotc doesn't screw this page up, my scraper would get the set list correctly

`public static function getModernLegalSets()
{

    $url = 'https://magic.wizards.com/en/game-info/gameplay/formats/modern';

    $options = [
        'http'=> [
            'method'=> 'GET',
            'header'=> "Accept-language: en\r\n".
                "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n", // i.e. An iPad
        ],
    ];

    $context = stream_context_create($options);
    $htmlFull = @file_get_contents($url, false, $context);
    $dropdown = [];

    if($htmlFull!="")
    {
        $doc = new DOMDocument();
        $internalErrors = libxml_use_internal_errors(true);
        $doc->loadHTML($htmlFull);
        libxml_use_internal_errors($internalErrors);
        
        $xpath = new DOMXPath($doc);
        foreach($xpath->query("//div[@id='gameinfo-formats-modern-2']") as $divContent)
        {
            if($ulList = $divContent->getElementsByTagName('ul')->item(1))
            {
                $sets = $ulList->getElementsByTagName('li');
                foreach($sets as $set)
                {
                    //Some set names has non-breaking space, need to be removed
                    $dropdown[] = str_replace( chr( 194 ) . chr( 160 ), '', $set->nodeValue);
                }
            }
        }
        
    }

    return $dropdown;
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants