forked from fser/aide-lautrenet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spip2pelican.pl
57 lines (46 loc) · 1.4 KB
/
spip2pelican.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env perl
use strict;
use warnings;
use DBI;
use v5.10;
use Data::Dumper;
my $pagenum = 1;
sub write_page
{
my $text = shift;
open(my $FH, '>', "pages/page$pagenum.md") or die "Could not open file $!";
print $FH $text;
$pagenum++;
close $FH;
}
sub do_page
{
my $ref = shift;
my $template = 'Title: TITLE
Date: DATE
Category: CATEGORY
Tags: old
Summary: SUMMARY
TEXT';
($template = $template) =~ s/TITLE/$ref->{titre}/;
($template = $template) =~ s/DATE/$ref->{date}/;
($template = $template) =~ s/CATEGORY/$ref->{category}/;
($template = $template) =~ s/SUMMARY/$ref->{descriptif} . $ref->{chapo}/;
($template = $template) =~ s/TEXT/$ref->{texte}/;
write_page $template;
}
$req = 'select a.texte, a.date, a.descriptif, a.chapo, a.titre, r.titre as category from spip_articles a, spip_rubriques r where r.id_rubrique = a.id_rubrique order by a.id_rubrique';
my $dsn = "DBI:mysql:MY_AWESOME_DB:MY_AWSOME_HOST";
my $username = 'MY_AWSOME_USERNAME';
my $password = 'NY_AWSOME_PASSWORD';
my %attr = ( PrintError=>0, # turn off error reporting via warn()
RaiseError=>1 # report error via die()
);
my $dbh = DBI->connect($dsn,$username,$password,\%attr);
my $sth = $dbh->prepare($req);
$sth->execute();
while (my $res = $sth->fetchrow_hashref)
{
do_page $res;
}
$dbh->disconnect();