-
Notifications
You must be signed in to change notification settings - Fork 1
/
senat.js
161 lines (134 loc) · 3.45 KB
/
senat.js
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
/**
* this script requires casparjs >= 1.1 with phantomjs >= 1.8
**/
var XDate = require('xdate');
var fs = require('fs');
var casper = require('casper').create({
pageSettings:
{
loadImages: false,
loadPlugins: false,
},
clientScripts: ['xdate.js'],
verbose: true,
viewportSize: // circumvent being accidentally redirected to mobile sites based on screen real estate
{
width: 1024,
height: 768
}
});
var ba_list = [
"ba-charlottenburg-wilmersdorf",
"ba-friedrichshain-kreuzberg",
"ba-lichtenberg",
"ba-marzahn-hellersdorf",
"ba-mitte",
"ba-neukoelln",
"ba-pankow",
"ba-reinickendorf",
"ba-spandau",
"ba-steglitz-zehlendorf",
"ba-tempelhof-schoeneberg",
"ba-treptow-koepenick"
];
var current = 0;
var getAll = false;
function makeReadable(ba)
{
return ba.slice(3).replace(/-/, ' ').split(' ').map(function(e) {
return e.charAt(0).toUpperCase() + e.slice(1);
}).join(' ');
}
function buildURL(ba)
{
if (ba == "ba-steglitz-zehlendorf")
{
return "http://www.berlin.de/ba-steglitz-zehlendorf/politik-und-verwaltung/bezirksverordnetenversammlung/online/vo040.asp"
}
return "http://www.berlin.de/" + ba + "/bvv-online/vo040.asp";
}
function evaluateURL(getAll)
{
var rows = document.querySelectorAll('#rismain_raw tbody tr');
var result = new Array();
for (i = 0; i < rows.length; i++)
{
var link = rows[i].getElementsByTagName('a');
var date_col = rows[i].getElementsByTagName('td');
date = date_col[4];
if (date)
{
date = date.innerText;
xdate = date.split('.');
xdate = new XDate(Date.UTC(parseInt(xdate[2]), parseInt(xdate[1]), parseInt(xdate[0])));
xdate.addMonths(-1); // xdate adds one month.
description = link[0].innerText;
id = description.match(/Bebauungsplan ([\w-]+)/i);
if (id && id.length == 2 && (xdate.diffWeeks(XDate.now()) <= 1 || getAll))
{
result.push({
"id": id[1],
"link": link[0].href,
"description": description,
"date": xdate.toISOString(),
});
}
}
}
return result;
}
function get(url)
{
var resolutions;
casper.echo("Processing '" + makeReadable(ba_list[current]) + "'");
casper.start().open(url,
{
'method': 'post',
'data':
{
VO040FIL1: '',
filtvoname: 'filter',
VO040FIL2: 'Bebauungsplan',
filtvobetr1: 'filter',
x: 9,
y: 12
}
});
casper.thenBypassUnless(function() {
return this.exists("#rismain_raw tbody td.text4 a");
}, 2);
casper.thenClick("#rismain_raw tbody td.text4 a")
casper.wait(750);
casper.then(function()
{
resolutions = this.evaluate(evaluateURL, getAll);
});
casper.run(function() {
var out = "";
for (i = 0; i < resolutions.length; i++)
{
out += "Datum: " + resolutions[i].date
+ "\nLink: " + resolutions[i].link
+ "\nBezeichner: "+resolutions[i].id
+ "\n\nBeschreibung:\n\n"
+ resolutions[i].description
+ "\n\n---\n\n";
}
fs.write('data/text/' + ba_list[current - 1].slice(3) +".txt", out, 'w');
fs.write('data/json/' + ba_list[current - 1].slice(3) +".json", JSON.stringify(resolutions, null, '\t'), 'w');
});
}
if (casper.cli.has("all"))
{
getAll = true;
}
get(buildURL(ba_list[current]));
casper.on('run.complete', function () {
if (++current < ba_list.length)
{
get(buildURL(ba_list[current]));
} else
{
casper.exit();
}
});