Repository navigation
Expand file tree
/
Copy pathfix_db_ws_pages.plx
More file actions
executable file
·212 lines (127 loc) · 3.43 KB
/
Copy pathfix_db_ws_pages.plx
File metadata and controls
executable file
·212 lines (127 loc) · 3.43 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/local/bin/perl -w
#!/usr/bin/perl -w
## Given a NAR database (in HTML format), this script checks if the
## MetaBase entry for the given database can be 'safely' updated. User
## contributed text is saved, the update performed, and the user
## contributed text is then restored.
use Data::Dumper;
use Getopt::Long;
use MediaWiki::API;
use HTML::WikiConverter;
use strict;
## This will be moved into .pm
my $wc =
new HTML::WikiConverter( dialect => 'MediaWiki' );
## Set this to tag pages
my $version = "2.1.1";
## Set this to help debugging
my $verbose = 0;
## Import the helper functions
use NARDatabase
qw( mwLogin
parseNarDatabaseHtml
getPage
printPageRevisions
tidyHtmlForMediaWiki
updatePage
);
## Check that we have been passed an appropriate HTML file
die "pass me a NAR datbase HTML page!\n"
unless @ARGV;
my $file = $ARGV[0];
die "file not recognised: $file\n"
unless $file =~ /db_accn_(\d{4})\.html$/;
my $id = $1;
## OK
warn "doing $file\n";
## Get a connection to the wiki...
my $mw = mwLogin();
warn "logged in\n";
## parse the given NAR database HTML
my $fh;
open $fh, $file
or die "cant open $file : $! \n";
my $data = parseNarDatabaseHtml( $fh, $verbose )
or die "failed to parse $file\n";
warn "parsed $file\n";
## Unwrap the resulting data (for didactic purposes)
my ($title, # The database Title.
$no, # The database No.
$url, # The database URL(s).
$author, # The database authors (one line).
$authorAdr, # The author address (one line).
$contact, # The database contact(s).
$H3, # The H3 data.
#
$cat, # The category data.
$subCat, # The sub-category data.
#
$abstract, # Abstract URL.
$abstractYear # Abstract year
) = @$data;
&freakOut()
unless $id == $no;
## Move this check into the parser?
unless (keys %{$H3}){
die "no sections?\n"
}
for(keys %{$H3}){
warn "\tFound Section:$_\n";
}
printPageRevisions($title, $mw);
warn "\nUpdate?\n";
print "Press Enter to Continue . . .\n";
my $dummy = <STDIN>;
## Start building the template
my $text = <<EO;
{{Database entry
|name = $title
|nar id = $no
EO
##
my %sections =
("Database Description" => "10 nar description",
"Recent Developments" => "20 nar developments",
"Acknowledgements" => "30 nar acknowledgements",
"References" => "40 nar references",
);
for (keys %{$H3}){
next if $sections{$_};
die "unknown section -$_-\n"
}
for my $section (sort {$sections{$a} cmp
$sections{$b} } keys %sections){
if (defined($H3->{$section})){
my $paramName = substr($sections{$section},3);
$text .= "|$paramName = ";
my $t = $wc->html2wiki( $H3->{$section} ). "\n";
## Sad but true...
$t = tidyHtmlForMediaWiki( $t );
$text .= "$t\n"
}
}
if($author){
$text .= "|authors = $author\n";
}
if ($authorAdr){
$text .= "|author addresses = $authorAdr\n"
}
$text .= "|homepage = ". join(",", @$url). "\n";
$text .= <<EO;
|abstracts = $abstract
|nar years = $abstractYear
EO
$text .= "|emails = ". join(",", @$contact). "\n";
$text .= "|nar categories = ".
join(",", values(%$cat),
(map {values(%$_)} values(%$subCat))
). "\n";
$text .= "|version = $version\n";
$text .= "}}\n";
$text .= <<EO;
<!-- Add your text below -->
<!-- Add your text above -->
{{Page data|term=$title}}
EO
updatePage($title, $mw, $text, 'Moving to template based mayhem! ;-)');
warn "OK\n";