2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00
fhem-mirror/fhem/contrib/zwavealliance.images.parse
2017-10-12 13:00:06 +00:00

58 lines
1.6 KiB
Plaintext

#/usr/bin/perl
# Creates the FHEM file from the raw data
# Usage: zwavealliance.images.parse downloaddir
# Downloaddir is filled with the following script:
# i=1
# while test $i -lt 2680
# do
# echo $i
# wget -O $i -q http://products.z-wavealliance.org/products/$i/XML
# i=`expr $i + 1`
# done
die("Usage: zwavealliance.images.parse downloaddir\n") if(int(@ARGV) != 1);
open(OF, ">zwave_alliancelinks.csv");
opendir(DIRH, $ARGV[0]) || die("Cant open $ARGV[0]\n");
my @files;
while(my $fn = readdir(DIRH)) {
push @files, $fn;
}
for my $fn (sort { $a <=> $b } @files) {
my $path = "$ARGV[0]/$fn";
next if (! -f $path);
print("$fn\n");
open(FH, $path) || die("Cant open $path\n");
my ($bn,$mi,$pti,$pi,$pic,$em) = ('','','','','','');
while(my $l = <FH>) {
chomp($l);
$em = empty if($l =~ m,<h2>Oh no ... we encountered an error!</h2>,);
$bn = $1 if($l =~ m,<Brand>(.*)</Brand>,);
$mi = $1 if($l =~ m,<ManufacturerId>0x(....)</ManufacturerId>,);
$pti = $1 if($l =~ m,<ProductTypeId>0x(....)</ProductTypeId>,);
$pi = $1 if($l =~ m,<ProductId>0x(....)</ProductId>,);
$pic = $1 if($l =~ m,<Image>.*productName=(.*)</Image>,);
}
close(FH);
if($mi eq '' && $pti eq '' && $pi eq '' && -s $path eq 4880) {
printf "DELETE empty $path\n";
next;
}
if($em eq 'empty') {
printf "Empty for $fn\n";
next;
}
if($mi eq '' || $pti eq '' || $pi eq '') {
printf "Missing parameters for $fn: $bn/$mi/$pti/$pi\n";
next;
}
printf OF "%s-%s-%s,%s,%s,%s\n", $mi,$pti,$pi,$fn,$pic,$bn;
}
closedir(DIRH);
close(OF);