Skip to content

Commit

Permalink
Add total collections number to JSON endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmacwhite committed Jun 30, 2024
1 parent f18214f commit fc52702
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ calendars.forEach(function(filepath) {
const icalJs = require('ical.js');
const IcalExpander = require('ical-expander');
const ics = jetpack.read(filepath);
const icalExpander = new IcalExpander({ ics, maxIterations: 50 });
const icalExpander = new IcalExpander({ ics, maxIterations: 55 });
const events = icalExpander.all();
const filename = `${path.parse(filepath).name}.json`;
const jcalData = icalJs.parse(ics);
Expand All @@ -48,11 +48,12 @@ calendars.forEach(function(filepath) {
const jsonData = {
"filename": filename,
"name": comp.getFirstPropertyValue('x-wr-calname'),
"description": comp.getFirstPropertyValue('x-wr-caldesc'),
"icalPath": filepath,
"jsonPath": jsonPath.substring(2),
"lastGenerated": new Date().toJSON(),
"lastModified": fileProperties.modifyTime,
"description": comp.getFirstPropertyValue('x-wr-caldesc'),
"totalCollections": 0,
"collectionDates": []
};

Expand Down Expand Up @@ -88,6 +89,7 @@ calendars.forEach(function(filepath) {
const allEvents = [].concat(mappedEvents, mappedOccurrences)
.sort((a,b) => new Date(a.collectionDate) - new Date(b.collectionDate));

jsonData['totalCollections'] = allEvents.length;
jsonData['collectionDates'] = allEvents;

// Write to JSON folder for public API
Expand Down
3 changes: 2 additions & 1 deletion json-endpoints.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ <h1 class="h2">{{ page.title }}</h1>
{
"filename": "gedling_borough_council_friday_g4_bin_schedule.json",
"name": "Gedling Borough Council Bin Day 2023/24 Friday G4",
"description": "https://apps.gedling.gov.uk/refuse/data/FridayG4-2024.pdf",
"icalPath": "ical/gedling_borough_council_friday_g4_bin_schedule.ics",
"jsonPath": "json/gedling_borough_council_friday_g4_bin_schedule.json",
"lastGenerated": "2024-06-29T18:45:14.023Z",
"lastModified": "2024-06-17T14:12:39.206Z",
"description": "https://apps.gedling.gov.uk/refuse/data/FridayG4-2024.pdf",
"totalCollections": 53,
"collectionDates": [
...
]
Expand Down

0 comments on commit fc52702

Please sign in to comment.