Jump to content

"Console Status" script help


outl4w

Recommended Posts

just joined after hoping to find an answer and to find other useful snippets.

this script use to work and now since PSN reformatted their status page...can't seem to get it working again.  the previous PSN url - http://support.us.playstation.com/app/answers/detail/a_id/237/
 
snippet
error_reporting(E_ERROR);


$PSN_url = 'https://status.playstation.com/en-us/';
$PSNhtml = file_get_contents($PSN_url);
$PSNdom = new DOMDocument();
@$PSNdom->loadHTML($PSNhtml);
$PSNxpath = new DOMXPath($PSNdom);


//PSN Query
$PSN_query = "/html/body[@id='scea_body']/div[@id='wrap']/div[@class='boxshadow']/div[@id='main']/div[@id='search_main_box']/div[@id='rn_PageContent']/div[@id='rn_AnswerTop']/h1[@id='rn_Summary']";


$PSN_rows = $PSNxpath->query($PSN_query);


//PSN Status
foreach ($PSN_rows as $PSN_object){
    $PSNstatus =  $PSN_object->childNodes->item(0)->nodeValue;
}
$PSNstatus = str_replace('PSN Status:', '', $PSNstatus);
 
what this is suppose to do is search the PSN status page and look for the content and return the results to a slide out tab on my site.....similar to how it scrapes the xbl status page.
 
I've done the "view source" on the PSN page and experimented with all the "id's/class's" ie "alert-content" but can't narrow it down....just wondering if any php guru's here could help out.

 

post-179875-0-00301300-1443748577_thumb.png

 

any help is greatly appreciated...

 

 

Link to comment
Share on other sites

sorry for double posting but if a admin/mod would merge this with the my op....I guess you have a message editing time limit.

 

just wanted to add the original code:

<?php 

error_reporting(E_ERROR); 

$PSN_url = 'http://support.us.playstation.com/app/answers/detail/a_id/237/'; 
$PSNhtml = file_get_contents($PSN_url); 
$PSNdom = new DOMDocument(); 
@$PSNdom->loadHTML($PSNhtml); 
$PSNxpath = new DOMXPath($PSNdom); 
  
//PSN Query 
$PSN_query = "/html/body[@id='scea_body']/div[@id='wrap']/div[@class='boxshadow']/div[@id='main']/div[@id='search_main_box']/div[@id='rn_PageContent']/div[@id='rn_AnswerTop']/h1[@id='rn_Summary']";

$PSN_rows = $PSNxpath->query($PSN_query); 
  
//PSN Status 
foreach ($PSN_rows as $PSN_object){ 
    $PSNstatus =  $PSN_object->childNodes->item(0)->nodeValue; 
} 
$PSNstatus = str_replace('PSN Status:', '', $PSNstatus); 

$XBOX_url = 'http://support.xbox.com/en-US/xbox-live-status'; 
$XBOXhtml = file_get_contents($XBOX_url); 
$XBOXdom = new DOMDocument(); 
@$XBOXdom->loadHTML($XBOXhtml); 
$XBOXxpath = new DOMXPath($XBOXdom); 
  
//Xbox Social And Gaming 
$XBOXSocialAndGaming_query = "/html/body[@id='DocumentBody']/div[@id='bodycolumn']/div[@id='BodyContent']/div[@class='liveStatusPage']/div[2]/ul[@class='core']/li[@id='SocialandGaming']/div[@class='item']/h3";
$XBOXSocialAndGaming_rows = $XBOXxpath->query($XBOXSocialAndGaming_query); 
  
//Xbox Social And Gaming loop 
foreach ($XBOXSocialAndGaming_rows as $XBOXSocialAndGaming_object){ 
    $XBOXSocialAndGamingStatus =  $XBOXSocialAndGaming_object->childNodes->item(1)->nodeValue; 
} 


//Xbox Live Core Services 
$XBOXLiveCore_query = "/html/body[@id='DocumentBody']/div[@id='bodycolumn']/div[@id='BodyContent']/div[@class='liveStatusPage']/div[2]/ul[@class='core']/li[@id='XboxLiveCoreServices']/div[@class='item']/h3";
$XBOXLiveCore_rows = $XBOXxpath->query($XBOXLiveCore_query); 
  
//Xbox Live Core Status 
foreach ($XBOXLiveCore_rows as $XBOXLiveCore_object){ 
    $XBOXLiveCoreStatus = $XBOXLiveCore_object->childNodes->item(1)->nodeValue; 
} 

$output = " 
<style> 
.xboxtitle { 
    display: inline-block; 
    height: 14px; 
    line-height: 14px; 
    font-size: 14px; 
    font-weight: 600; 
    padding: 4px 4px; 
    margin-top: 4px; 
    letter-spacing:0.5px; 
    color: #FAF9F7 !important; 
    vertical-align: middle !important; 
    cursor:default; 
    text-shadow: 0 0 0 transparent, 0px -3px 0px #333;
	
} 
.xboxstatus a{ 
    color:#D4D4D4;
    font-weight:600;
    background: #c9de96; /* Old browsers */
    background: -moz-linear-gradient(top,  #c9de96 0%, #8ab66b 44%, #398235 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#c9de96), color-stop(44%,#8ab66b), color-stop(100%,#398235)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  #c9de96 0%,#8ab66b 44%,#398235 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  #c9de96 0%,#8ab66b 44%,#398235 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  #c9de96 0%,#8ab66b 44%,#398235 100%); /* IE10+ */
    background: linear-gradient(to bottom,  #c9de96 0%,#8ab66b 44%,#398235 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#c9de96', endColorstr='#398235',GradientType=0 ); /* IE6-9 */ 
    padding: 6px !important;
    border-radius: 4px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    -webkit-box-shadow: 6px 6px 20px 0px rgba(0,0,0,0.75);
    -moz-box-shadow: 6px 6px 20px 0px rgba(0,0,0,0.75);
    box-shadow: 6px 6px 20px 0px rgba(0,0,0,0.75);
    border:groove 1px #000;
	
} 
.psntitle { 
    display: inline-block;
    height: 16px; 
    line-height: 16px; 
    font-size: 14px; 
    font-weight: 600; 
    padding: 4px 4px; 
    margin-top: 4px; 
    letter-spacing:0.5px; 
    color: #FAF9F7 !important; 
    vertical-align: middle !important; 
    cursor:default; 
    text-shadow: 0 0 0 transparent, 0px -3px 0px #333;
	
}

.psnstatus a{ 
    color:#D4D4D4;
    font-weight:600;
    background: rgb(181,189,200); /* Old browsers */
    background: -moz-linear-gradient(top,  rgba(181,189,200,1) 0%, rgba(130,140,149,1) 36%, rgba(40,52,59,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(181,189,200,1)), color-stop(36%,rgba(130,140,149,1)), color-stop(100%,rgba(40,52,59,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top,  rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top,  rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top,  rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* IE10+ */
    background: linear-gradient(to bottom,  rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=0 ); /* IE6-9 */
    line-height: 1.95;
    border-radius: 4px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    -webkit-box-shadow: 6px 6px 20px 0px rgba(0,0,0,0.75);
    -moz-box-shadow: 6px 6px 20px 0px rgba(0,0,0,0.75);
    box-shadow: 6px 6px 20px 0px rgba(0,0,0,0.75);
    border:groove 1px #000;
    padding: 6px !important;
} 
</style> 
<span class='psntitle'> PSN Status: </span><br /><span class='psnstatus'> <a href='https://support.us.playstation.com/app/answers/detail/a_id/237/'>" .
 $PSNstatus . "</a></span><br /><br /><span class='xboxtitle'> XBL Status: </span><br /><span class='xboxstatus'><a href='http://support.xbox.com/en-US/xbox-live-status'> " . $XBOXSocialAndGamingStatus . "</a></span><br /><br /><span class='xboxtitle'> XBL Core Status: </span><br /><span class='xboxstatus'><a href='http://support.xbox.com/en-US/xbox-live-status'>" . $XBOXLiveCoreStatus . "</a></span>";  

echo $output; 

 ?>

I'm more of a css guy and this is sorta my first dive into the phpool by adapting the php from templates...got the xbl script right. 

Link to comment
Share on other sites

This is what I came up with:

<?php

$PSN_url = 'https://status.playstation.com/en-us/';
$PSNhtml = file_get_contents($PSN_url);
$PSNdom = new DOMDocument();
@$PSNdom->loadHTML($PSNhtml);
$PSNxpath = new DOMXPath($PSNdom);

//PSN Query
$PSN_query = "//div/ul[@class='main-content']//li";

$PSN_rows = $PSNxpath->query($PSN_query);

$statuses = array();

//PSN Status
foreach ($PSN_rows as $PSN_object){
    // get the raw HTML of this node so that we can 
    // examine the status image
    $html = $PSN_object->ownerDocument->saveHTML($PSN_object);

    // determine if this service is up
    // the image "./images/green.png" means the service is up
    $isUp = (preg_match('/img src="\.\/images\/green\.png"/', $html) === 1);

    // add this service to the statuses list
    $statuses[trim($PSN_object->nodeValue)] = $isUp;
}

echo '<pre>' . print_r($statuses, true) . '</pre>';
It will look at each of the services on that page and determine if there is a "green.png" image, which would presumably mean that service is up. It will create an array of each service with a true/false status. This is the output:

 

Array
(
    [Account Management] => 1
    [Sign In] => 1
    [Create Account] => 1
    [Gaming and Social] => 1
    [PlayStation™Now] => 1
    [PlayStation™Video] => 1
    [PlayStation™Vue] => 1
    [PlayStation®Store] => 1
    [Purchase] => 1
    [Download] => 1
    [Browse] => 1
    [Search] => 1
    [Redeem Voucher] => 1
)

EDIT: Here's the same thing but with strpos instead of preg_match (regex wasn't really necessary)

 

<?php

$PSN_url = 'https://status.playstation.com/en-us/';
$PSNhtml = file_get_contents($PSN_url);
$PSNdom = new DOMDocument();
@$PSNdom->loadHTML($PSNhtml);
$PSNxpath = new DOMXPath($PSNdom);

//PSN Query
$PSN_query = "//div/ul[@class='main-content']//li";

$PSN_rows = $PSNxpath->query($PSN_query);

$statuses = array();

//PSN Status
foreach ($PSN_rows as $PSN_object){
    // get the raw HTML of this node so that we can 
    // examine the status image
    $html = $PSN_object->ownerDocument->saveHTML($PSN_object);

    // determine if this service is up
    // the image "./images/green.png" means the service is up
    $isUp = (strpos($html, 'src="./images/green.png"') !== false);

    // add this service to the statuses list
    $statuses[trim($PSN_object->nodeValue)] = $isUp;
}

echo '<pre>' . print_r($statuses, true) . '</pre>';
Edited by scootstah
Link to comment
Share on other sites

This is what I came up with:

<?php

$PSN_url = 'https://status.playstation.com/en-us/';
$PSNhtml = file_get_contents($PSN_url);
$PSNdom = new DOMDocument();
@$PSNdom->loadHTML($PSNhtml);
$PSNxpath = new DOMXPath($PSNdom);

//PSN Query
$PSN_query = "//div/ul[@class='main-content']//li";

$PSN_rows = $PSNxpath->query($PSN_query);

$statuses = array();

//PSN Status
foreach ($PSN_rows as $PSN_object){
    // get the raw HTML of this node so that we can 
    // examine the status image
    $html = $PSN_object->ownerDocument->saveHTML($PSN_object);

    // determine if this service is up
    // the image "./images/green.png" means the service is up
    $isUp = (preg_match('/img src="\.\/images\/green\.png"/', $html) === 1);

    // add this service to the statuses list
    $statuses[trim($PSN_object->nodeValue)] = $isUp;
}

echo '<pre>' . print_r($statuses, true) . '</pre>';
It will look at each of the services on that page and determine if there is a "green.png" image, which would presumably mean that service is up. It will create an array of each service with a true/false status. This is the output:

 

Array
(
    [Account Management] => 1
    [Sign In] => 1
    [Create Account] => 1
    [Gaming and Social] => 1
    [PlayStation™Now] => 1
    [PlayStation™Video] => 1
    [PlayStation™Vue] => 1
    [PlayStation®Store] => 1
    [Purchase] => 1
    [Download] => 1
    [Browse] => 1
    [Search] => 1
    [Redeem Voucher] => 1
)
EDIT: Here's the same thing but with strpos instead of preg_match (regex wasn't really necessary)

 

<?php

$PSN_url = 'https://status.playstation.com/en-us/';
$PSNhtml = file_get_contents($PSN_url);
$PSNdom = new DOMDocument();
@$PSNdom->loadHTML($PSNhtml);
$PSNxpath = new DOMXPath($PSNdom);

//PSN Query
$PSN_query = "//div/ul[@class='main-content']//li";

$PSN_rows = $PSNxpath->query($PSN_query);

$statuses = array();

//PSN Status
foreach ($PSN_rows as $PSN_object){
    // get the raw HTML of this node so that we can 
    // examine the status image
    $html = $PSN_object->ownerDocument->saveHTML($PSN_object);

    // determine if this service is up
    // the image "./images/green.png" means the service is up
    $isUp = (strpos($html, 'src="./images/green.png"') !== false);

    // add this service to the statuses list
    $statuses[trim($PSN_object->nodeValue)] = $isUp;
}

echo '<pre>' . print_r($statuses, true) . '</pre>';

thanks but I keep getting the error message:

Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /home//public_html/status/PSN_stat.php on line 20
Array
(
[Account Management] =>
[Sign In] =>
[Create Account] =>
[Gaming and Social] =>
[PlayStationâ„¢Now] =>
[PlayStationâ„¢Video] =>
[PlayStationâ„¢Vue] =>
[PlayStation®Store] =>
[Purchase] =>
[Download] =>
[Browse] =>
[Search] =>
[Redeem Voucher] =>
)

fyi....Saved the file as PSN_stat.php

Link to comment
Share on other sites

You're using a very old version of PHP then. The parameter was added in PHP5.3. You should look into updating to 5.6 because you're not getting any more security updates to the version you're running.

currently using php ver. 5.3.28

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.