Hallo alle zusammen,
ich habe mich jetzt selber erbarmt!! ![:wink: :wink:](https://community.symcon.de/images/emoji/win10/wink.png?v=9)
<?
/*=============================================================
eBayWatchList - Martin Heinzel - 30.06.2012
Version: 0.1
Beschreibung:
Mit diesem Script wird die eBay Beobachtungsliste eingelesen und als
HTML - String ausgegeben. Somit kann das Ergebnis direkt im Webfront
angezeigt werden.
Änderungen
----------
tt.mm.jjjj von Version x.x -> y.y
Beschreibung:
================================================================*/
// Variablen Deklaration --------------------------------------
//#################################### Bitte einstellen #######################
$DEVID = "ee50.....";
$AppID = "Mart......";
$CertID = "c32........";
$UserToken = "AgAAAA**.....";
//#############################################################################
// Variablen
//--------------
$filename = IPS_GetKernelDir()."data\\IPSeBay\\GetInfo.xml";
$browser = "";
//-------------------------------------------------------------
//--------------------------- Main ----------------------------
$responseDoc = new DomDocument();
$responseDoc->loadXML(callEbay($DEVID, $AppID, $CertID, $UserToken, $filename));
$responses = $responseDoc->getElementsByTagName("WatchList");
$browser = '<table border="1" cellpadding="1" cellspacing="1" summary="ebay">';
foreach ($responses as $response)
{
$totalNumberOfEntries = $response->getElementsByTagName("TotalNumberOfEntries")->item(0)->nodeValue;
$items = $response->getElementsByTagName("Item");
for($i=0; $i<$totalNumberOfEntries; $i++)
{
//Berechnen der verbleibenden Zeit
$EndTime = $items->item($i)->getElementsByTagName('EndTime')->item(0)->nodeValue;
$EndJahr = substr($EndTime, 0, 4);
$EndMonat = substr($EndTime, 5, 2);
$EndTag = substr($EndTime, 8, 2);
$EndStunde = substr($EndTime, 11, 2);
$EndMinute = substr($EndTime, 14, 2);
$EndSekunde = substr($EndTime, 17, 2);
$TimeDiff = mktime((int)$EndStunde, (int)$EndMinute, (int)$EndSekunde, (int)$EndMonat, (int)$EndTag, (int)$EndJahr) +(2*60*60) -time();
$Tage = (int)($TimeDiff/86400);
$Stunden = (int)(($TimeDiff -($Tage*86400))/3600);
$Minuten = (int)(($TimeDiff -($Tage*86400) -($Stunden*3600))/60);
if($TimeDiff >= 0)
{
$Restzeit = $Tage.'T'.$Stunden.'H'.$Minuten.'M';
}
else
{
$Restzeit = 'Beendet';
}
$ViewItemURL = $items->item($i)->getElementsByTagName('ViewItemURL')->item(0)->nodeValue;
$FeedbackScore = $items->item($i)->getElementsByTagName('FeedbackScore')->item(0)->nodeValue;
$UserID = $items->item($i)->getElementsByTagName('UserID')->item(0)->nodeValue;
$CurrentPrice = $items->item($i)->getElementsByTagName('CurrentPrice')->item(0)->nodeValue;
$Title = $items->item($i)->getElementsByTagName('Title')->item(0)->nodeValue;
if(strlen($Title)>=70) $Title = substr($Title, 0, 64)." ...";
$GalleryURL = $items->item($i)->getElementsByTagName('GalleryURL')->item(0)->nodeValue;
//zusammenbauen der Zeile
$browser .= '<tr>';
$browser .= '<td><img src="'.$GalleryURL.'" alt="not Found"></td>';
$browser .= '<td width="600px"><a href="'.$ViewItemURL.'" target="_blank">'.formatText($Title).'</a></br>'.$UserID.' | '.$FeedbackScore.'</td>';
$browser .= '<td width="150px" align="center">'.$CurrentPrice.' €</td>';
$browser .= '<td width="150px" align="center">'.$Restzeit.'</td>';
$browser .= '</tr>';
}
}
$browser .= '</table>';
SetValue(CreateVariableByName($IPS_SELF, "ebayWatchList", 3, "~HTMLBox"), $browser);
//------------------------- Main ENDE --------------------------
//------------------------ Funktionen -------------------------
/**
* Returns the Output of GetMyeBayBuying .
*
* @param string $DEVID -> The eBay DEVID
* @param string $AppID -> The eBay AppID
* @param string $CertID -> The eBay CertID
* @param string $UserToke -> The eBay UserToke
* @param string $filename -> The location of the GetInfo.xml
* @return xml -> xml answere from eBay.
*/
function callEbay($DEVID, $AppID, $CertID, $UserToken, $filename)
{
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, 'https://api.ebay.com/ws/api.dll');
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
$headers = array (
'X-EBAY-API-COMPATIBILITY-LEVEL: 779',
'X-EBAY-API-DEV-NAME: ' . $DEVID,
'X-EBAY-API-APP-NAME: ' . $AppID,
'X-EBAY-API-CERT-NAME: ' . $CertID,
'X-EBAY-API-CALL-NAME: GetMyeBayBuying',
'X-EBAY-API-SITEID: 77',
);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
$requestXmlBody = file_get_contents($filename);
$requestBody = str_replace('%%USER_TOKEN%%',$UserToken, $requestXmlBody);
curl_setopt($connection, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$responseXml = curl_exec($connection);
curl_close($connection);
return $responseXml;
}
// Textformatierung
function formatText($text)
{
$text = html_entity_decode($text);
$text = str_replace("ö", "oe", $text);
$text = str_replace("Ü", "Ue", $text);
$text = str_replace("ü", "ue", $text);
$text = str_replace("ä", "ae", $text);
$text = str_replace("ß", "ss", $text);
$text = str_replace("–", "-", $text);
$text = str_replace(''', "`", $text);
$text = str_replace("&", "&", $text);
$text = str_replace("Ö", "Oe", $text);
$text = str_replace("„", "\"", $text);
$text = str_replace("“", "\"", $text);
$text = str_replace("–", "-", $text);
$text = str_replace("„", "\"", $text);
$text = str_replace("“", "\"", $text);
$text = str_replace("„", "\"", $text);
$text = str_replace("–", "-", $text);
$text = str_replace("–", "-", $text);
$text = str_replace("é", "é", $text);
$text = str_replace("Ä", "Ae", $text);
return $text;
}
function CreateVariableByName($id, $name, $type, $profile = "")
{
global $IPS_SELF;
$vid = @IPS_GetVariableIDByName($name, $id);
if($vid === false)
{
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $id);
IPS_SetName($vid, $name);
IPS_SetInfo($vid, "this variable was created by script #$IPS_SELF");
if($profile !== "") { IPS_SetVariableCustomProfile($vid, $profile); }
IPS_SetScriptTimer($IPS_SELF, 300);
}
return $vid;
}
//--------------------- Funktionen ENDE ------------------------
?>
Die Beschreibung ist in Post #14.
Das Script erzeugt eine Variable die im Webfront angezeigt werden kann.