Skip to content

Commit

Permalink
start candidate osm wiki plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Dec 8, 2020
1 parent edcce1c commit 8d83a9d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- **[breaking]** - remove .dates() method (prev deprecated)
- **[breaking]** - normalize table rows
- **[new]** - Table.get() method
- **[new]** - set new infoboxes using .extend()
- deprecate wtf-plugin-category (moved to wtf-plugin-api)
-->
Expand Down
16 changes: 16 additions & 0 deletions plugins/misc-wikis/openstreetmap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Instructions for parsing OpenStreetMap's wiki at [https://wiki.openstreetmap.org](https://wiki.openstreetmap.org)


```js
wtf.extend(require('./plugin.js'))
```

The OSM wiki api uses a custom path:
```js
wtf.fetch('https://wiki.openstreetmap.org/wiki/Tag:highway%3Dmotorway', { path: '/w/api.php' }).then((doc) => {
console.log(doc.templates('ValueDescription'))
})
```

Some of the data in the osm wiki, such as [Map_features](https://wiki.openstreetmap.org/wiki/Map_features) is generated dynamically through [{{Taglist}}](https://wiki.openstreetmap.org/wiki/Taginfo/Taglists), which means it cannot be retrieved.

Empty file.
16 changes: 16 additions & 0 deletions plugins/misc-wikis/openstreetmap/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const boxes = {
KeyDescription: true,
ValueDescription: true,
Place: true,
}

const plugin = (models, templates, infoboxes) => {
// add infoboxes
Object.assign(infoboxes, boxes)
// add templates
templates.tag = (text, data) => {
console.log(data)
return
}
}
module.exports = plugin
29 changes: 9 additions & 20 deletions scratch.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
const wtf = require('./src/index')
wtf.extend(require('./plugins/api/src'))

const getBox = function (doc) {
let box = doc.infobox('currency') //.json()
let res = box.get(['iso_code', 'subunit_name_1', 'symbol']).map((s) => s.text())
return {
title: doc.title(),
iso: res[0],
subUnit: res[1],
symbol: res[2],
const plugin = (models, templates) => {
// add templates
templates.tag = (text, data, c, d) => {
console.log(d)
return
}
}

// const getAll = async function (tmpl) {
// let pages = await wtf.getTemplatePages(tmpl)
// let docs = await wtf.fetchList(pages)
// return docs.map(getBox)
// }
// console.log(JSON.stringify(getAll('Template:Infobox currency'), null, 2))
wtf.extend(plugin)

// wtf.fetch('Brunei dollar').then((doc) => {
// console.log(getBox(doc))
// wtf.fetch('https://wiki.openstreetmap.org/wiki/Tag:highway%3Dmotorway', { path: '/w/api.php' }).then((doc) => {
// // console.log(doc.templates('ValueDescription'))
// })

// wtf.fetch('https://wiki.openstreetmap.org/wiki/Tag:highway%3Dmotorway', { path: '/w/api.php' }).then((doc) => {
wtf.fetch('https://wiki.openstreetmap.org/wiki/Tag:highway%3Dmotorway').then((doc) => {
console.log(doc.templates('ValueDescription'))
})
wtf(`{{Tag|aerialway|subkey=occupancy}}`)

0 comments on commit 8d83a9d

Please sign in to comment.