I am having problems getting magicparser. It works on your site. The code i am using is below:
<?php
require("MagicParserForceISO-8859-1.php");
function myRecordHandler($record)
{
// This is where you write your code to process each record, such as loading a database
// You can display the record contents using PHP's internal print_r() function:
print_r($record);
// The following code will print out each field in your sample data:
print $record["merchant_id"];
print $record["merchant_name"];
print $record["aw_product_id"];
print $record["product_name"];
print $record["description"];
print $record["aw_deep_link"];
print $record["aw_image_url"];
print $record["ean"];
print $record["specifications"];
print $record["brand_name"];
print $record["category_id"];
print $record["display_price"];
print $record["merchant_category"];
print $record["merchant_image_url"];
print $record["web_offer"];
print $record["aw_thumb_url"];
print $record["commission_group"];
print $record["delivery_cost"];
print $record["merchant_product_id"];
print $record["merchant_thumb_url"];
print $record["merchant_deep_link"];
print $record["model_number"];
}
MagicParser_parse("{link saved}","myRecordHandler","csv|124|1|0");
?>
And if you go to {link saved} you will see the output i get
Regards,
Andrew Wade
Thanks for the reply, but it does not work i get the following error:
Warning: unlink(downloads/feed.xml) [function.unlink]: No such file or directory in /home/apwade/public_html/comparison/magic1.php on line 41
Does there need to be a file called feed.xml?
Or i do not need to use magicparser immediatley like your server could you advise on how your system is set up (although i am on a shared host, i do not have much control).
Regards,
Andrew
I completed the above steps and the following error occurred:
Warning: unlink(downloads/feed.xml) [function.unlink]: No such file or directory in /home/apwade/public_html/comparison/magic1.php on line 41
Regards,
Andrew
Hi Andrew,
That implies that the directory is not writable (so the copy() function hadn't worked). Could you try the following test script:
<?php
if (is_writable("downloads"))
{
print "OK!";
}
else
{
print "Not writable - check permissions...";
}
?>
Cheers,
David.
The above script prints OK, still the same error
Andrew
Hi Andrew,
Thanks. In that case, could you insert an exit() statement as follows in the block of code described above:
$url = "{link saved}";
$dst = "downloads/feed.xml";
copy($url,$dst.".zip");
exit();
$cmd = "/usr/bin/unzip -p ".$dst.".zip > ".$dst;
unlink($dst.".zip");
MagicParser_parse($dst,"myRecordHandler","csv|124|1|0");
unlink($dst);
...and at this point, can you look in /downloads/ to see if feed.xml.zip is present?
Cheers,
David.
Hi Andy,
My apologies, I just noticed that the exec() statement is missing from the code. Before continuing with more debug exits(); could you try this version:
$url = "{link saved}";
$dst = "downloads/feed.xml";
copy($url,$dst.".zip");
$cmd = "/usr/bin/unzip -p ".$dst.".zip > ".$dst;
exec($cmd);
unlink($dst.".zip");
MagicParser_parse($dst,"myRecordHandler","csv|124|1|0");
unlink($dst);
If that still doesn't work, please add an exit() statement after the following line:
exec($cmd);
...and then check /downloads/ for feed.xml
Thanks,
David.
I added the exit(); after the unzip command following code:
$cmd = "/usr/bin/unzip -p ".$dst.".zip > ".$dst;
exit();
and it does not unzip the file.
Andrew
Hi Andrew,
We just cross-posted - check my last post above for the missing exec() command, sorry about overlooking that...
Cheers,
David.
Thank you for the help, its working now. Now i can design my price comparison system.
Regards
Andrew
Hello Andrew,
Apologies due for not making this aspect clear within the demo. The URL is returning a .zipped file, which needs to be uncompressed before parsing. The demo system running on this server actually retrieves the URL independently of Magic Parser and auto-detects the compression and unzips if required.
I understand that the feed provider do not offer an uncompressed version, so in order to do this automatically (i.e. without downloading the feed to your local computer, unzipping, and uploading to your server) it will be necessary to implement something similar on your server.
The first requirement is a temporary directory in the same folder as your script that is writable by PHP. The easiest way to do this is generally with your FTP program. Create a directory, say "downloads" in the same directory as your script, and then right-click on the new folder in the remote window and look for "Permissions" or maybe "Properties..." and then Permissions. Then give write access to all users (Owner / Group / World).
With that in place, replace the single line calling MagicParser_parse(...) with the following block of code; replacing {link saved} with your .zipped feed URL.
$url = "{link saved}";
$dst = "downloads/feed.xml";
copy($url,$dst.".zip");
$cmd = "/usr/bin/unzip -p ".$dst.".zip > ".$dst;
unlink($dst.".zip");
MagicParser_parse($dst,"myRecordHandler","csv|124|1|0");
unlink($dst);
You find unwanted quote characters in your text - this is because the source feed does not quote the header row so it is not picked up in the autodetection. If this is the case, in place of the auto-detected format string, use "csv|124|1|34".
Hope this helps,
Cheers,
David.