Skip to content

Commit

Permalink
Adds handling for more than one meeting per month. Adds day and month…
Browse files Browse the repository at this point in the history
… to getMeetings
  • Loading branch information
zrrrzzt committed Sep 8, 2016
1 parent 619ce2d commit f1f9922
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -62,7 +62,8 @@ const ogm = require('opengov-meetings')
const opts = {
host: 'http://opengov.cloudapp.net',
path: '/Meetings/tfk',
boardId: '200151'
boardId: '200151',
year: 2015
}

function cb (err, data) {
Expand Down
13 changes: 11 additions & 2 deletions lib/parse-meetings.js
Expand Up @@ -2,6 +2,10 @@

const cheerio = require('cheerio')

function fixMonth (elem) {
return elem > 11 ? elem - 12 : elem
}

module.exports = page => {
var $ = cheerio.load(page)
var data = {}
Expand All @@ -16,15 +20,20 @@ module.exports = page => {

Object.keys(dates).forEach(function (elem) {
if (typeof parseInt(elem, 10) === 'number') {
const month = fixMonth(elem)
cell = dates[elem]
if (cell.hasOwnProperty('type') && cell.children.length > 0) {
item = {}
if (cell.attribs.title) {
item.date = cell.children[0].data + '. ' + headers[elem].attribs.title
item.date = cell.children[0].data + '. ' + headers[month].attribs.title
item.day = cell.children[0].data
item.month = parseInt(month, 10) + 1
item.status = cell.attribs.title
item.id = ''
} else {
item.date = cell.children[0].children[0].data + '. ' + headers[elem].attribs.title
item.date = cell.children[0].children[0].data + '. ' + headers[month].attribs.title
item.day = cell.children[0].children[0].data
item.month = parseInt(month, 10) + 1
item.status = cell.children[0].attribs.title
item.id = cell.children[0].attribs.href.split('/').pop()
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "opengov-meetings",
"description": "Connect to 360 OpenGov Meetings",
"version": "3.0.0",
"version": "3.1.0",
"license": "MIT",
"author": {
"name": "Geir Gåsodden",
Expand Down
6 changes: 6 additions & 0 deletions test/data/get-meetings-data-full.json
Expand Up @@ -3,18 +3,24 @@
"meetings": [
{
"date": "19. mars",
"day": "19",
"month": 3,
"status": "Offentlig",
"id": "212860",
"year": "2015"
},
{
"date": "8. juni",
"day": "8",
"month": 6,
"status": "Offentlig",
"id": "212864",
"year": "2015"
},
{
"date": "21. september",
"day": "21",
"month": 9,
"status": "Avlyst",
"id": "",
"year": "2015"
Expand Down
6 changes: 6 additions & 0 deletions test/data/get-meetings-data.json
Expand Up @@ -3,16 +3,22 @@
"meetings": [
{
"date": "19. mars",
"day": "19",
"month": 3,
"status": "Offentlig",
"id": "212860"
},
{
"date": "8. juni",
"day": "8",
"month": 6,
"status": "Offentlig",
"id": "212864"
},
{
"date": "21. september",
"day": "21",
"month": 9,
"status": "Avlyst",
"id": ""
}
Expand Down

0 comments on commit f1f9922

Please sign in to comment.