forked from Br3nda/legislation_pull
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
133 lines (102 loc) · 3.21 KB
/
index.php
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
<?php
require('./governments.inc.php');
do_command('rm -rf ./repo');
mkdir('repo');
// do_command("git init");
foreach(dirListing() as $doc_type) {
echo "=== INDEXING $doc_type \n";
foreach(dirListing($doc_type) as $doc_area) {
echo "$doc_type/$doc_area\n";
foreach(dirListing("$doc_type/$doc_area") as $year) {
echo "\t$doc_type/$doc_area/$year\n";
foreach(dirListing("$doc_type/$doc_area/$year") as $did) {
echo "\t\t$doc_type/$doc_area/$year/$did\n";
foreach(dirListing("$doc_type/$doc_area/$year/$did") as $version) {
echo "\t\t\t$doc_type/$doc_area/$year/$did/$version\n";
commit_document($doc_type, $doc_area, $year, $did, $version);
}
}
}
}
}
function commit_document($doc_type, $doc_area, $year, $did, $version) {
$xml = file_get_contents("www.legislation.govt.nz/subscribe/$doc_type/$doc_area/$year/$did/$version");
$xml = (array)new SimpleXMLElement($xml);
$body = (array)$xml['body'];
$path = $body['h1'];
$ul = (array)$body['ul'];
$xml_file = (array)$ul['li'][0];
$pdf = (array)$ul['li'][1];
$xml_filename = $xml_file['a'] ."\n";
$url = "http://www.legislation.govt.nz$path/$xml_filename";
echo "$url\n";
$pdf_filename = $pdf['a'];
$title = preg_replace('!\.pdf$!', '', $pdf_filename);
echo "title = $title\n";
// var_dump($body);
$dir_name = "";
chdir("repo/");
//all the bits, except $version and year
foreach(array($doc_type, $doc_area) as $a) {
$dir_name .= "$a/";
if (!is_dir($dir_name)) {
echo "Making $dir_name\n";
do_command("mkdir $dir_name");
}
}
$file = str_replace(" ", "_", $title);
do_command("echo 'Version $version' > $dir_name$file");
do_command("git add $dir_name$file");
$govt = government($year);
do_command("git commit $dir_name$file --author=\"$govt <government of $year>\" -m =\"$title\" --date=\"$year-01-01\"");
do_command("git status");
chdir('..');
echo "\n\n";
}
function dirListing($dir='.') {
$d = dir("www.legislation.govt.nz/subscribe/$dir");
while (false !== ($entry = $d->read())) {
if ('.' != $entry && '..' != $entry) {
$list[] = $entry;
}
}
$d->close();
return $list;
}
/*
$legislation = get_legislation();
foreach($legislation as $act) {
getNext($act['date'], $act['url'], $act['act']);
}
do_command('git filter-branch --commit-filter \'
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE";
git commit-tree "$@";
\' HEAD
');*/
/*
function getNext($date, $url, $act) {
mkdir($act);
chdir($act);
print "$data $url\n";
do_command("wget $url");
do_command("mv *.pdf $act.pdf");
do_command("rm *.txt");
do_command("ls -la");
do_command("pdftotext *.pdf");
do_command("ls -la");
do_command("rm *.pdf");
do_command("git add $act*.txt");
$time = strtotime($date);
$year = date('Y', $time);
$government = government($year);
if(!$government) $government = 'Victoria';
chdir('..');
do_command("git add $act");
do_command("git commit -a --date=\"". $time .'" -m "'. $act .' Act at '. $date .'" --author="' . $government . ' <[email protected]>"');
do_command("git status");
}*/
function do_command($command) {
echo getcwd()."\$ $command\n";
passthru($command);
# sleep(1);
}