
Originally Posted by
KNM Computers
can anyone help please? with this script below
1. can it be used for a cron job?
2. at the top of it there a space to put url to fetch file can a user name and password be added to script for a passwored url? if so how do i do it?
3. can i modify the script to over ride an image url so instead of importing the image url that come with the feed file it would use an image url of i choose? if so how do i implement it ?
thankyou
http://www.zen-cart.com/attachment.p...3&d=1209389792
right if anyone has any idea on how to do the above 1,2 &3 on the script below your help would be greatfull
Code:
#!/usr/bin/perl
# Be sure to rename this file with a .pl extension as it is a Perl Script.
# Uses LWP to pull down a datafile, convert its format, save it to a temp location,
# and tell easypopulate.php to put the data into OSCommerce
# If the update is correct, the froogle extract file will be downloaded
# and ftp'd to google for processing
# Orginally Written by Marty Bostick
# Version 1.1.4
use LWP;
use LWP::UserAgent;
use Net::FTP;
####################################################################################
# User Defined Variables #
####################################################################################
# URL to get 3 column file from
# Note: The parsing routine can be customized to account for more than 3 columns
# But this script is used by me daily to update my quantities with that of my
# supplier. This is very helpful when you are using a Dropshipper.
# I also provide custom updates at reasonable prices for those interested.
$sourceURL = 'http://SOMEVENDOR.COM/Restrict3d/datafile_3.csv';
# Output File Name, output will be overwritten
#$outputFile = "Output.txt";
$outputFile = "/home/USERDIR/public_html/osc/temp/Output.txt";
# 1 to use proxy, 0 to disable proxy, this is read from the HTTP_proxy env variable
$useProxy = 0;
# URL to call to load data
$loadURL = 'http://MYSITE.COM/osc/admin/easypopulate.php?localfile=Output.txt';
# Change the variables below to be your OSC or ZenCart Admin Username/Password
$loadUserName = "OSCADMINUSERNAMEHERE";
$loadPassword = "OSCADMINPASSWORDHERE";
# If you want to, you can also upload your products to Froogle as I am below.
# Froogle Information
$froogleFeedURL = 'http://MYSITE.COM/osc/admin/easypopulate.php?download=stream&dltype=froogle';
# Be sure to change the frooglefilename.txt to the one you have setup with Froogle.
#$froogleFileName = "frooglefilename.txt";
$froogleFileName = "/home/USERDIR/public_html/osc/temp/frooglefilename.txt";
$froogleFtpSite = "hedwig.google.com";
$froogleFtpPort = 21;
# Set your Froogle Username/Password below
$froogleUser = 'FROOGLEUSERNAME';
$frooglePassword = "FROOGLEPASSWORD";
####################################################################################
# End User Defined Variables #
####################################################################################
print "Running Program at " . localtime() . "\n";
#create the user agent that will make the HTTP calls
$userAgent = LWP::UserAgent->new;
$userAgent->agent("Qty Update Agent");
# check to see if you need a proxy
if($useProxy == 1){
$userAgent->env_proxy;
}
$req = HTTP::Request->new(GET => $sourceURL);
my $res = $userAgent->request($req);
if ($res->is_success) {
if(open(OUTPUTFILE, ">$outputFile")){
print OUTPUTFILE "v_products_model\tv_products_quantity\tEOREOR\n";
@dataArray = split('\r\n', $res->content);
$length = @dataArray;
for($i=1; $i<$length-1; $i++){
$temp = $dataArray[$i];
$temp =~ s/\"//g;
@record = split(',', $temp);
print OUTPUTFILE "$record[0]\t$record[2]\tEOREOR\n";
}
close(OUTPUTFILE);
print "Successfully Created output file $outputFile \n";
}
else{
print "Could not create output file $outputFile \n";
}
#call the webpage to load the data into oscommerce
$loadRequest = HTTP::Request->new(GET => $loadURL);
$loadRequest->authorization_basic($loadUserName, $loadPassword);
$loadReponse = $userAgent->request($loadRequest);
if($loadReponse->is_success){
print "Successfully Updated Quanities\n";
}
else{
print "Could not update quanities\n";
print $loadReponse->status_line;
print "\n";
}
# update froogle data, this can occur even if you cannot update quanaites on the site
# but not if you cannot get the new quanities from the supplier
$froogleRequest = HTTP::Request->new(GET => $froogleFeedURL);
$froogleRequest->authorization_basic($loadUserName, $loadPassword);
$froogleResponse = $userAgent->request($froogleRequest);
if($froogleResponse->is_success){
$createdFile = 0;
if(open(FROOGLEFILE, ">$froogleFileName")){
print FROOGLEFILE ($froogleResponse->content);
close(FROOGLEFILE);
$createdFile = 1;
}
else{
print "Could not create froogle extract file, check permissions.\n";
}
if($createdFile == 1){
$froogleFtp = Net::FTP->new("$froogleFtpSite", Port => $froogleFtpPort);
$return = $froogleFtp->login("$froogleUser", "$frooglePassword");
if($return != 1){
print "Could not Login to FTP Server $froogleFtpSite\n";
}
else{
$froogleFtp->ascii;
$return = $froogleFtp->put("$froogleFileName");
if($return eq ""){
print "Could not Upload file $froogleFileName\n";
}
else{
print "Successfully Uploaded Froogle Feed\n";
}
}
$froogleFtp->quit;
}
}
else{
print "Could not download the froogle extract\n";
}
}
else {
print "Could not contact source server $sourceURL\n";
print $res->status_line;
print "\n";
}
Bookmarks