Archive for the ‘Programming’ Category

Uitzendinggemist on your TV with DLNA

Saturday, February 13th, 2010

Hey people check out the following software:

http://code.google.com/p/uitzendinggemist-dlna/

It’s still in a beta, but you can use it for watching Uitzendinggemist, RTL Gemist, Net5, SBS6 and Veronica on your TV.

Paul Wagener has started the project as a Pyton script and rewrote it to Java as a plugin forĀ  PS3 Media Server (at least build 381). I’m trying to commit good code too ;-)

Will write some more text about this later, in the meantime please test it and enjoy!


PERL input and output files

Monday, November 17th, 2008

To read an input file, edit your data and put it to an output file try this:

#! /usr/bin/perl -w

use strict;

my $file = “in.csv”;
my $outfile = “out.csv”;

open(IN, “<$file”) or die “Could not open $file\n”;
open(OUT, “>$outfile”) or die “Could not open $outfile\n”;

while (<IN>)
{
chomp;
my @line = split(“,”); # this char is the separation sign.

# Your data will now be in a array called line[ ].

# Do whatever you want, access the data with the varable $line[FIELDNUMBER]
# Example: $line[3] = ‘blablbla’ #edit the 4th value from the input file.

print OUT “$line[0],$line[3],$line[2]“\n”; # write back to output file
}
# close the both files (importend! else the writing will not take place due caching!)
close(IN);
close(OUT);

PERL connect to SQL server

Monday, November 17th, 2008

To connect you PERL application to an SQL server is pretty easy.

First you need the driver for supporting SQL connections.

Install driver:

  1. Open command prompt
  2. Typ: ppm install DBD-mysql

After a correct installation of the driver your SQL connection can be made as follow:

#!/usr/local/bin/perl
print "Content-type:text/html\n\n";

use DBI;

$username = '';
$password = '';
$database = '';
$hostname = '';

$dbh = DBI->connect("dbi:mysql:database=$database;" .
 "host=$hostname;port=3306", $username, $password);

This is all you need to connect to your server.
If you don’t know your server ip, try connecting to your website address.

A very good website about this subject is:
http://www.codeproject.com/KB/perl/perldbi.aspx

TNT zone shipping module in Joomla Virtuemart

Friday, November 14th, 2008

After lots and lots of googling i couldn’t find any shipping module for Virtuemart that was suiteble for our situation.

There is some kind of module for TNT but its for TGP Post and I didn’t get it working.

So there is no other option then write a module myself.

The first steps:

(1) Shipping Zone importing

I’ve imported all country zone codes by downloading the zone PDF from TNT, copied the in Excel and wrote a PERL script for the importing.

To make it more simple to you just download the SQL file here and just run the code in phpmyadmin.

It will update zone information (zone_id) for all countries in the jos_vm_country table.

If you prefer just international country codes with shipping zone information find it here. (same data, other format)

Beware this zone data is only from the Dutch point of view ;-) This will be different for your country!

(2) Writing the module itself:

The problem is, there is a default Zone Shipping module in Virtuemart, but here in the Netherlands the shipping costs are calculated different.

For example, in the default module you can ship a product sized 30cm * 30cm * 30cm with the weight of 50 Kg for just the zone price. There’s no difference in shipping a very large/small/heavy package. Only the destination matters.

TNT caculates the weight and the volume weight. You pay the highest value.

Weight is just the weight in Kilogram.

Volume weight is the size of the package length*width*hight / 6000.

Source: http://members.ziggo.nl/mfleur/maten.html

I’m writing the PHP code for the shipping module at the moment, so hold on a week or two.

Update 19 november 2008:

I had success with writing the module. There is a working alpha version. My deadline is 31 december 2008, so working hard to make this happen. I will make it more configurable, some parameters are hardcoded at the moment.

Update 9 january 2009:

I can report the shipping module is working fine :-) It still has the be tested some more, but it working.
There is one practical problem I”m facing, the volume weight calculation.

When you have some products, you can calulate their volume. But not in witch box they will fit.

At the moment i’m tweaking this calculation for the most optimal box.

If someone has a good solution for this, please write a comment below :-)

Update 14 Juni

Thanks all for waiting! :-) I can report this module is working fine in production now. At the moment i’m VERY busy with school (tomorrow I’ll have my final exam!).

Within a short time I’ll set the code online for testing. Anyone interested in this testing?

First steps in Perl parsing CSV from Mamut to Joomla Virtuemart

Monday, October 27th, 2008

Today at the office I was asked to help migrating the webshop from Mamut to Joomla Virtuemart.

I installed the new webshop, and used the plugin CSVImport to import all data about the products.

As allways Mamut was a pain in the a**, you can export all products BUT:

  • Without all descriptions you perfectly made of the last year
  • Without all pictures chosen
  • Without a normal layout in the Categories (messed up with some $$%# charcs)

I’m still working on the pictures and descriptions, found the correct database file but they work with MEMO fields. For some reason the format is not default and cannot be readout easily (keep in touch).

I started to write a C# program to fix all this for me, an hour later my college asked me in what language I was coding. He told me “Ohh please write this kinda conversion in Perl”. Until today I never touched Perl, so that was a new experience. He wrote me a very simple program of about 10 lines of code as example and start up.
After some syntax reading I started to write code. I have to admit, 2 hours later the whole job (except images and descriptions) was done..
So take his (and my) advice, if you want to covert or parse a CSV file don’t use Java, C++, C# or whatever use Perl.
This code can be used to parse the exported product data from Mamut to the format used while importing products in Virtuemart.
To use this, install perl and save the code to a new textfile name FILENAME.pl.
Code for Category:
#! /usr/bin/perl -w

use strict;
# the input file (place in same dir as the script)
my $file = “in.csv”;

# output file (will be created in the script dir)
my $outfile = “catout.csv”;

# check for input file
open(IN, “<$file”) or die “Could not open $file\n”;

#check for permission to write output
open(OUT, “>$outfile”) or die “Could not open $outfile\n”;

# while there are input lines
while (<IN>)
{

chomp;
# split the input line at the comma char (you can change this)
my @line = split(“,”);

# Replace the Mamut category mess with the \ char
$line[3] =~ s/\%\%/\//g;

# print the parsed line to the output file.
# Note: You have to use \ to escape the ” char \”\” means an empty entry.
print OUT “$line[3],\”\”,\”\”,\”\”,\”\”,\”managed\”,\”flypage.tpl\”,\”y\”,\”\”,\n”;

}

# close input file
close(IN);
# close output file
close(OUT);

Code for products:

#! /usr/bin/perl -w

use strict;

my $file = “in.csv”;
my $outfile = “out2.csv”;

open(IN, “<$file”) or die “Could not open $file\n”;
open(OUT, “>$outfile”) or die “Could not open $outfile\n”;

while (<IN>)
{
chomp;
my @line = split(“,”);
$line[3] =~ s/\%\%/\//g; # replace the category
print OUT “$line[0],\”\”, $line[3], $line[1],\”\”,\”\”,$line[11],\”\”,\”\”,\”\”,\”\”,\”EUR\”,\”\”,\”\”,\”\”,\”\”,\”Y\”,\”N\”,\”\”,\”\”\n”;
}

close(IN);
close(OUT);