-
Notifications
You must be signed in to change notification settings - Fork 1
/
ulice_create.js
executable file
·112 lines (93 loc) · 2.47 KB
/
ulice_create.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
#!/usr/bin/env node
/**
* Skrypt tworzący szkice stron o ulicach
*/
var fs = require('fs'),
bot = require('nodemw'),
client = new bot('config.js'),
utils = require('./utils');
var SUMMARY = 'Szkic strony',
YEAR = '2018',
ULICA = process.argv[2] || '';
if (ULICA === '') {
console.log('Podaj nazwę ulicy');
process.exit(1);
}
client.logIn((err, data) => {
client.getArticle(ULICA, (err, content) => {
// strona istnieje
if (typeof content !== 'undefined') {
throw 'Artykuł juz istnieje';
}
// Geo data
const query = `${ULICA}, Poznań`;
utils.osmSearch(client, query, (err, data) => {
if (err) {
console.log(data);
throw err;
}
if (!data || !data[0]) {
throw 'Address not found';
}
var place = data[0];
client.log(place);
place.address = place.address || {};
place.address.postcode = place.address.postcode || '';
place.address.suburb = place.address.suburb || '';
place.address.neighbourhood = place.address.neighbourhood || '';
/**
{ place_id: '196302900',
licence: 'Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright',
osm_type: 'way',
osm_id: '441844276',
boundingbox: [ '52.3933304', '52.3936783', '16.9577746', '16.9580225' ],
lat: '52.3934741',
lon: '16.9578421',
display_name: 'Anny Jantar, Łacina, Rataje, Poznań, wielkopolskie, 61-206, Polska',
class: 'highway',
type: 'residential',
importance: 0.41,
address:
{ road: 'Anny Jantar',
neighbourhood: 'Łacina',
suburb: 'Rataje',
city: 'Poznań',
county: 'Poznań',
state: 'wielkopolskie',
postcode: '61-206',
country: 'Polska',
country_code: 'pl' } }
**/
var content = `{{Ulica infobox
|nazwa_ulicy=${ULICA}
|mapa_ulica=<place lat="${place.lat}" lon="${place.lon}" width="300" zoom=14 />
|patron=
|patron_wikipedia=
|długość=
|dzielnice=${place.address.neighbourhood}, ${place.address.suburb}
|rok=[[${YEAR}]]
|numery=
|najwyższy_budynek=
|kody=${place.address.postcode}
|przystanki_autobusowe=
|przystanki_tramwajowe=
}}
'''${ULICA}'''
== Historia ==
{{Rozwiń Sekcję}}
{{Przy ulicy}}
== Źródła ==
<references />`;
content = content.replace(/=\s?,\s?/g, '=');
//content = content.replace(/, ?\n*/g, '\n');
client.log(content);
// edytuj
client.edit(ULICA, content, SUMMARY, (err) => {
if (err) {
throw err;
}
console.log(ULICA + ' założona');
});
});
});
});