Skip to content

Commit 5a9feee

Browse files
authored
Merge pull request #240 from fanto666/fanto666-patch-1
Add Nokia CSV conversion script. Closes: #239
2 parents 43fd58c + 195e3e0 commit 5a9feee

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

tools/Tools.md

+15
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ To use, run:
7474

7575
and then visit `http://127.0.0.1:8222` in a web browser.
7676

77+
### [`nokia-suite-convert.pl`](contrib/nokia-suite-convert.pl)
78+
79+
This is an utility to convert SMS export file as made by Nokia Suite (in CSV format) into CSV format that can be parsed by [csv-convert.py](#csv-convert.py) above.
80+
Requires:
81+
- perl
82+
- Text::CSV (in Debian and alike libtext-csv-perl)
83+
- POSIX::strptime (in Debian and alike libposix-strptime-perl)
84+
85+
Usage:
86+
87+
`nokia-suite-convert.pl [input.csv [output.csv]]`
88+
89+
- if output file is omitted, standard output is used
90+
- if both files are omitted, standard input/output are used
91+
7792
## External Tools
7893

7994
This section lists tools for use with SMS I/E that have been developed, and are distributed, by outside developers. Descriptions of the tools are taken from their documentation:

tools/contrib/nokia-suite-convert.pl

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/perl
2+
#
3+
# nokia-suite-convert.pl - convert SMS export from CSV exported
4+
# by Nokia Suite into CSV that can be parsed by csv-convert.py
5+
#
6+
# Copyright (c) 2023 - 2024 by Matus UHLAR <uhlar@fantomas.sk>
7+
#
8+
# This program is free software: you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation, either version 3 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
21+
use strict;
22+
use Text::CSV;
23+
use Time::Local qw( timelocal_posix );
24+
use POSIX::strptime;
25+
use bignum;
26+
use open qw( :std :encoding(UTF-8) );
27+
28+
my ($fnin, $fhin, $fnout,$fhout);
29+
if ($fnin=shift @ARGV) {
30+
open $fhin, "<", $fnin or die "$fnin $!";
31+
} else {
32+
$fhin = *STDIN;
33+
}
34+
if ($fnout=shift @ARGV) {
35+
open $fhout, ">", $fnout or
36+
die "$fnout $!";
37+
} else {
38+
$fhout = *STDOUT;
39+
}
40+
41+
my $csvin = Text::CSV->new ({ binary => 1, auto_diag => 1 });
42+
#my $csvout = Text::CSV->new ({ binary => 1, quote_space => 0, quote_binary => 0 });
43+
# always quote if you want to filter in LibreOffice and compare results
44+
my $csvout = Text::CSV->new ({ binary => 1, always_quote => 1 });
45+
$csvout->say($fhout, ["type","read","address","date","body"]);
46+
47+
my ($type,$read,$addr,$date,$text);
48+
my ($year,$mon,$day,$hour,$min);
49+
50+
while (my $row = $csvin->getline ($fhin)) {
51+
my %type = map { $_ => 1 } (split /,/, $row->[1]);
52+
if ($type{'RECEIVED'}) {
53+
$type=1;
54+
$addr=$row->[2];
55+
} elsif ($type{'SENT'}) {
56+
$type=2;
57+
$addr=$row->[3];
58+
} else {
59+
print STDERR "unknown type ",$row->[1],"\n";
60+
next;
61+
}
62+
if ($type{'READ'}) {
63+
$read=1;
64+
} else {
65+
$read=0;
66+
}
67+
($min,$hour,$day,$mon,$year) =
68+
(POSIX::strptime($row->[5], "%Y.%m.%d %H:%M"))[1,2,3,4,5];
69+
$date=timelocal_posix(0,$min,$hour,$day,$mon,$year);
70+
$date*=1000;
71+
$text=$row->[7];
72+
$csvout->say($fhout,[$type,$read,$addr,$date,$text]);
73+
}
74+
close $fhin;
75+
76+
close $fhout;

0 commit comments

Comments
 (0)