Skip to content
Browse files

generate also separate brands and models json

  • Loading branch information...
1 parent 6a9c97a commit 09a7bd94334c40b2eb9f350aa1469a8c2be93064 @jozef committed
Showing with 35 additions and 9 deletions.
  1. +3 −5 Makefile
  2. +29 −1 script/dbedia-wurfl-brands-models.pl
  3. +3 −3 script/{dbedia-wurfl-byid.pl → dbedia-wurfl-bybrand.pl}
View
8 Makefile
@@ -16,16 +16,15 @@ install: all
mkdir -p ${DESTDIR}/etc/dbedia/sites-available
cp etc/dbedia-WURFL.conf ${DESTDIR}/etc/dbedia/sites-available/
-# WURFL byID JSON
+# WURFL byBrand JSON
${WWW_FOLDER}/IDs.json: ${WURFL_LIB_FOLDER}/IDs.pm ${WURFL_LIB_FOLDER}/byID/g/en/generic.pm
mkdir -p ${WWW_FOLDER}
- script/dbedia-wurfl-byid.pl --lib tmp/lib --folder output
+ script/dbedia-wurfl-bybrand.pl --lib tmp/lib --folder ${WWW_FOLDER}
# WURFL brands&models JSON
${WWW_FOLDER}/brandsModels.json: ${WURFL_LIB_FOLDER}/IDs.pm ${WURFL_LIB_FOLDER}/byID/g/en/generic.pm
mkdir -p ${WWW_FOLDER}
- script/dbedia-wurfl-brands-models.pl --lib tmp/lib > $@.tmp
- mv $@.tmp $@
+ script/dbedia-wurfl-brands-models.pl --lib tmp/lib --folder ${WWW_FOLDER}
# UAs and IDs
${WURFL_LIB_FOLDER}/IDs.pm: ${WURFL_XML}
@@ -47,4 +46,3 @@ clean:
distclean:
rm -rf tmp/*
- rm -rf output/*
View
30 script/dbedia-wurfl-brands-models.pl
@@ -24,15 +24,19 @@ =head1 DESCRIPTION
use Getopt::Long;
use Pod::Usage;
use List::Util 'first';
+use File::Slurp 'write_file';
+use File::Path 'mkpath';
exit main();
sub main {
my $help;
my $lib;
+ my $folder;
GetOptions(
'help|h' => \$help,
'lib|l=s' => \$lib,
+ 'folder|f=s' => \$folder,
) or pod2usage;
pod2usage if $help;
@@ -79,7 +83,31 @@ sub main {
)
};
}
- print JSON::XS->new->utf8->pretty(1)->encode(\%brands);
+ write_file(
+ File::Spec->catfile($folder, 'brandsModels.json'),
+ JSON::XS->new->utf8->pretty(1)->encode(\%brands),
+ );
+
+ write_file(
+ File::Spec->catfile($folder, 'brands.json'),
+ JSON::XS->new->utf8->pretty(1)->encode([ sort keys %brands ]),
+ );
+
+ foreach my $brand_name (keys %brands) {
+ my $brand_folder = File::Spec->catdir($folder, 'byBrand', $brand_name);
+ my $models_filename = File::Spec->catfile($brand_folder, 'models.json');
+
+ mkpath($brand_folder)
+ if not -e $brand_folder;
+
+ my %models =
+ map { delete $_->{'model_name'} => $_ }
+ @{$brands{$brand_name}};
+ write_file(
+ $models_filename,
+ JSON::XS->new->utf8->pretty(1)->encode(\%models)
+ );
+ }
return 0;
}
View
6 script/dbedia-wurfl-byid.pl → script/dbedia-wurfl-bybrand.pl
@@ -2,11 +2,11 @@
=head1 NAME
-dbedia-wurfl-byid.pl - generate handsets info by id
+dbedia-wurfl-bybrand.pl - generate handsets info by id
=head1 SYNOPSIS
- dbedia-wurfl-byid.pl
+ dbedia-wurfl-bybrand.pl
=head1 DESCRIPTION
@@ -58,7 +58,7 @@ sub main {
# skip devices without brand_name
next if not $brand_name;
- my $device_folder = File::Spec->catdir($folder, 'byID', $brand_name);
+ my $device_folder = File::Spec->catdir($folder, 'byBrand', $brand_name);
my $device_filename = File::Spec->catfile($device_folder, $device->wurfl_id.'.json');
mkpath($device_folder)

0 comments on commit 09a7bd9

Please sign in to comment.
Something went wrong with that request. Please try again.