Skip to content

Commit

Permalink
Bug #4/#6, Generate iCalendar .ics data files [i18n][iet:8994834]
Browse files Browse the repository at this point in the history
* Plus, locale/translation JSON
  • Loading branch information
nfreear committed May 19, 2017
1 parent 3b14e2a commit e260e23
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@

LICENSE*

test*.html
*.min.js
*.sa.js
#data/*.json
src/*.json
*copy*
*.php

x_legacy/
node_modules/
*.log

composer.*
vendor/
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ node_js:
git:
depth: 5

install:
- npm install
- npm run install-legacy-datejs

script:
- node bin/gaad.js
- npm run build
- npm run build-min
- npm test

after_script:
- ls -alh build
- ls -alh data

# End.
95 changes: 95 additions & 0 deletions bin/gaad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env node

/*!
Nick, 19-May-2017.
*/

const path = require('path');
const ICS_FILE = path.join(__dirname, '/../data/gaad.en.ics');
const JSON_FILE = path.join(__dirname, '/../data/gaad.json');
const LOCALE_DIR = path.join(__dirname, '/../locales/');
const LOCALE_FILE = path.join(__dirname, '/../src/locales.json');
// const JSON_TEXT = path.join(__dirname, '/../src/gaad-texts.json');

const GAAD_START_YEAR = 2011;
const LIMIT_YEARS = 15;
// const A_DAY = 24 * 60 * 60;

const fs = require('fs');
var icalendar = require('icalendar');
var datejs = require('datejs');

var texts = readLocaleTexts(LOCALE_DIR);
var today = new Date();

var ical = new icalendar.iCalendar(); // eslint-disable-line
var gaadobj = {
'//': '', // texts[ '//' ],
'timestamp': today.toString('u'),
texts: texts,
dates: {}
};
var idx;

ical.setProperty('X-WR-CALNAME', 'GAAD: http://globalaccessibilityawarenessday.org');
ical.setProperty('X-WR-CALDESC', 'Developed by: Nick Freear.');

for (idx = 0; idx < LIMIT_YEARS; idx++) {
var event = ical.addComponent('VEVENT');
var year = (GAAD_START_YEAR + idx) + '';

var GAAD_DATE = new Date(year).may().third().thursday();

console.log('> GAAD %d: %s', idx + 0, GAAD_DATE.toString());

event.setSummary('Global Accessibility Awareness Day (GAAD) #' + (idx + 0));
// event2.setDate(GAAD_DATE, A_DAY); // Duration in seconds
event.setDescription('Join in at – ' + texts.en.url);
event.addProperty('CREATED', today.toString('u'));
event.setProperty('DTSTART;VALUE=DATE', GAAD_DATE.toString('yyyyMMdd'));
event.setProperty('DTEND;VALUE=DATE', GAAD_DATE.toString('yyyyMMdd'));

gaadobj.dates[ year ] = {
'{x}': idx + 0,
'{d}': GAAD_DATE.toString('dd'),
'{th}': GAAD_DATE.toString('S'),
'{m}': GAAD_DATE.toString('MMMM'),
'{y}': GAAD_DATE.toString('yyyy')
};
}

var json = JSON.stringify(gaadobj, null, 2);
var locjson = JSON.stringify(texts, null, 2);
var ics = ical.toString();

fs.writeFile(JSON_FILE, json);
fs.writeFile(LOCALE_FILE, locjson);
fs.writeFile(ICS_FILE, ics);

setTimeout(function () {
var jsonstat = fs.statSync(JSON_FILE);
var icsstat = fs.statSync(ICS_FILE);

console.log('JSON, %d bytes: %s', jsonstat.size, JSON_FILE);
console.log('iCal, %d bytes: %s', icsstat.size, ICS_FILE);
}, 100);

console.log(datejs);

function readLocaleTexts (localedir) {
var texts = {};
fs.readdirSync(localedir).forEach(function (file) {
console.log('Locale: %s', file);

var locale = file.replace('.json', '');
var jsontext = fs.readFileSync(localedir + file, 'utf8');
texts[ locale ] = JSON.parse(jsontext);
});

return texts;

// var jsontext = fs.readFileSync(JSON_TEXT, 'utf8');
// var texts = JSON.parse(jsontext);
}

// End.
111 changes: 111 additions & 0 deletions data/gaad.en.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Tri Tech Computers//node-icalendar//EN
X-WR-CALNAME:GAAD: http://globalaccessibilityawarenessday.org
X-WR-CALDESC:Developed by: Nick Freear.
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #0
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20110519
DTEND;VALUE=DATE:20110519
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #1
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20120517
DTEND;VALUE=DATE:20120517
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #2
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20130516
DTEND;VALUE=DATE:20130516
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #3
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20140515
DTEND;VALUE=DATE:20140515
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #4
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20150521
DTEND;VALUE=DATE:20150521
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #5
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20160519
DTEND;VALUE=DATE:20160519
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #6
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20170518
DTEND;VALUE=DATE:20170518
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #7
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20180517
DTEND;VALUE=DATE:20180517
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #8
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20190516
DTEND;VALUE=DATE:20190516
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #9
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20200521
DTEND;VALUE=DATE:20200521
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #10
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20210520
DTEND;VALUE=DATE:20210520
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #11
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20220519
DTEND;VALUE=DATE:20220519
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #12
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20230518
DTEND;VALUE=DATE:20230518
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #13
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20240516
DTEND;VALUE=DATE:20240516
END:VEVENT
BEGIN:VEVENT
SUMMARY:Global Accessibility Awareness Day (GAAD) #14
DESCRIPTION:Join in at – http://globalaccessibilityawarenessday.org
CREATED:20170519T222835Z
DTSTART;VALUE=DATE:20250515
DTEND;VALUE=DATE:20250515
END:VEVENT
END:VCALENDAR
124 changes: 124 additions & 0 deletions data/gaad.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"//": "",
"timestamp": "2017-05-19 22:28:35Z",
"texts": {
"en": {
"name": "Global Accessibility Awareness Day (GAAD)",
"before": "Join us on Thursday May {d}{th}, {y} and mark the {x}th <a href='{u}' target='_top'>{g}</a>.",
"after": "Put next year's <a href='{u}' target='_top'>{g}</a>, Thursday May {d}{th}, {y}, in your diary. See you then!",
"url": "http://globalaccessibilityawarenessday.org"
},
"fr": {
"before": "Rejoignez-nous le jeudi {d} mai {y} et marquez le {x}ème <a href='{u}' target='_top'>{g}</a>.",
"after": "Mettez le <a href='{u}' target='_top'>{g}</a> de l'année prochaine, le jeudi {d} mai {y} dans votre journal. À plus tard!",
"url": "http://globalaccessibilityawarenessday.org/gaadfr.html"
}
},
"dates": {
"2011": {
"{x}": 0,
"{d}": "19",
"{th}": "th",
"{m}": "May",
"{y}": "2011"
},
"2012": {
"{x}": 1,
"{d}": "17",
"{th}": "th",
"{m}": "May",
"{y}": "2012"
},
"2013": {
"{x}": 2,
"{d}": "16",
"{th}": "th",
"{m}": "May",
"{y}": "2013"
},
"2014": {
"{x}": 3,
"{d}": "15",
"{th}": "th",
"{m}": "May",
"{y}": "2014"
},
"2015": {
"{x}": 4,
"{d}": "21",
"{th}": "st",
"{m}": "May",
"{y}": "2015"
},
"2016": {
"{x}": 5,
"{d}": "19",
"{th}": "th",
"{m}": "May",
"{y}": "2016"
},
"2017": {
"{x}": 6,
"{d}": "18",
"{th}": "th",
"{m}": "May",
"{y}": "2017"
},
"2018": {
"{x}": 7,
"{d}": "17",
"{th}": "th",
"{m}": "May",
"{y}": "2018"
},
"2019": {
"{x}": 8,
"{d}": "16",
"{th}": "th",
"{m}": "May",
"{y}": "2019"
},
"2020": {
"{x}": 9,
"{d}": "21",
"{th}": "st",
"{m}": "May",
"{y}": "2020"
},
"2021": {
"{x}": 10,
"{d}": "20",
"{th}": "th",
"{m}": "May",
"{y}": "2021"
},
"2022": {
"{x}": 11,
"{d}": "19",
"{th}": "th",
"{m}": "May",
"{y}": "2022"
},
"2023": {
"{x}": 12,
"{d}": "18",
"{th}": "th",
"{m}": "May",
"{y}": "2023"
},
"2024": {
"{x}": 13,
"{d}": "16",
"{th}": "th",
"{m}": "May",
"{y}": "2024"
},
"2025": {
"{x}": 14,
"{d}": "15",
"{th}": "th",
"{m}": "May",
"{y}": "2025"
}
}
}
2 changes: 1 addition & 1 deletion embed/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
iframe.gaad-widget-ifr { width: 100%; height: 4.2em; border: none; }
</style>
<iframe src="https://cdn.rawgit.com/nfreear/gaad-widget/1.0-beta.2/embed/index.html" class="gaad-widget-ifr"></iframe>
<iframe src="https://cdn.rawgit.com/nfreear/gaad-widget/2.0-beta/embed/" class="gaad-widget-ifr"></iframe>
-->
6 changes: 6 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Global Accessibility Awareness Day (GAAD)",
"before": "Join us on Thursday May {d}{th}, {y} and mark the {x}th <a href='{u}' target='_top'>{g}</a>.",
"after": "Put next year's <a href='{u}' target='_top'>{g}</a>, Thursday May {d}{th}, {y}, in your diary. See you then!",
"url": "http://globalaccessibilityawarenessday.org"
}
5 changes: 5 additions & 0 deletions locales/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"before": "Rejoignez-nous le jeudi {d} mai {y} et marquez le {x}ème <a href='{u}' target='_top'>{g}</a>.",
"after": "Mettez le <a href='{u}' target='_top'>{g}</a> de l'année prochaine, le jeudi {d} mai {y} dans votre journal. À plus tard!",
"url": "http://globalaccessibilityawarenessday.org/gaadfr.html"
}
Loading

0 comments on commit e260e23

Please sign in to comment.