summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThunderbolt <schiewe31061@gmail.com>2018-04-30 17:11:36 +0200
committerGitHub <noreply@github.com>2018-04-30 17:11:36 +0200
commit4a9a8532464d7472eee392ed1eb221acb6d1d667 (patch)
treee5d2188898fa810bcdbad7c9832102d8efadc728
parenta439d29d8ff0bbee2d7c92c7594729c13c87baf8 (diff)
parentd895b2bbe19e502393e474b93597db7c093c03f6 (diff)
downloadsplus-4a9a8532464d7472eee392ed1eb221acb6d1d667.tar.gz
splus-4a9a8532464d7472eee392ed1eb221acb6d1d667.zip
Merge pull request #1 from schneefux/master
Add ICS support
-rw-r--r--.gitignore1
-rw-r--r--ICal.ts30
-rw-r--r--README.md11
-rw-r--r--docs/.gitkeep0
-rw-r--r--docs/informatik1.ics97
-rw-r--r--index.ts18
-rw-r--r--package-lock.json10
-rw-r--r--package.json3
8 files changed, 166 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c2658d7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules/
diff --git a/ICal.ts b/ICal.ts
new file mode 100644
index 0000000..fe74dab
--- /dev/null
+++ b/ICal.ts
@@ -0,0 +1,30 @@
+// ref. https://www.npmjs.com/package/ical-generator
+import * as ical from 'ical-generator';
+import * as crypto from 'crypto';
+import * as fs from 'fs';
+
+const TARGET_FILE = 'docs/informatik1.ics';
+const DOMAIN = 'schneefux.github.io'; // TODO config management
+
+const sha256 = (x) => crypto.createHash('sha256').update(x, 'utf8').digest('hex');
+
+const cal = ical();
+
+// TODO declare an interface
+export function createEvent(event) {
+ // TODO better duplicate detection and resolve conflicts lol
+ const eventId = sha256(JSON.stringify(event)).substr(0, 16);
+
+ const icalEvent = cal.createEvent({
+ uid: eventId,
+ start: event.start.dateTime,
+ end: event.end.dateTime,
+ timestamp: new Date(),
+ summary: event.summary,
+ description: event.description,
+ });
+}
+
+export function commit() {
+ fs.writeFile(TARGET_FILE, cal.toString(), (err) => {});
+}
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..aefe226
--- /dev/null
+++ b/README.md
@@ -0,0 +1,11 @@
+# SPlus Parser
+
+## Setup
+
+### Google
+
+no idea
+
+### ICS
+
+Run with ICS as command line argument: `npm start ics`. commit & it will be on [github pages](https://schneefux.github.io/splus/informatik1.ics).
diff --git a/docs/.gitkeep b/docs/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/docs/.gitkeep
diff --git a/docs/informatik1.ics b/docs/informatik1.ics
new file mode 100644
index 0000000..482e313
--- /dev/null
+++ b/docs/informatik1.ics
@@ -0,0 +1,97 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//sebbo.net//ical-generator//EN
+BEGIN:VEVENT
+UID:8cb5463bc6ac09ee@localhost
+SEQUENCE:0
+DTSTAMP:20180429T105331Z
+DTSTART:20180425T061500Z
+DTEND:20180425T074500Z
+SUMMARY:Grundlagen des Programmierens - VL
+DESCRIPTION:Prof. Dr. J. Weimar
+END:VEVENT
+BEGIN:VEVENT
+UID:3d6d97e8ed0b5008@localhost
+SEQUENCE:0
+DTSTAMP:20180429T105331Z
+DTSTART:20180426T080000Z
+DTEND:20180426T093000Z
+SUMMARY:Diskrete Strukturen
+DESCRIPTION:Prof. Dr. P. Riegler
+END:VEVENT
+BEGIN:VEVENT
+UID:1926bb7df8411c3f@localhost
+SEQUENCE:0
+DTSTAMP:20180429T105331Z
+DTSTART:20180424T100000Z
+DTEND:20180424T113000Z
+SUMMARY:Grundlagen des Programmierens - Labor
+DESCRIPTION:Prof. Dr. J. Weimar - Findet ab KW11 (13.3.) statt\, also nich
+ t am 6.3.
+END:VEVENT
+BEGIN:VEVENT
+UID:b35b7f60b9f78f21@localhost
+SEQUENCE:0
+DTSTAMP:20180429T105331Z
+DTSTART:20180423T121500Z
+DTEND:20180423T134500Z
+SUMMARY:Technische Grundlagen der Informatik - VL
+DESCRIPTION:Dipl.-Ing. K. Dammann
+END:VEVENT
+BEGIN:VEVENT
+UID:1cbd4999b193f6d7@localhost
+SEQUENCE:0
+DTSTAMP:20180429T105331Z
+DTSTART:20180424T121500Z
+DTEND:20180424T134500Z
+SUMMARY:Grundlagen des Programmierens - Labor
+DESCRIPTION:Prof. Dr. J. Weimar - Findet ab KW11 (13.3.) statt\, also nich
+ t am 6.3.
+END:VEVENT
+BEGIN:VEVENT
+UID:b6231494e1ea1f5a@localhost
+SEQUENCE:0
+DTSTAMP:20180429T105331Z
+DTSTART:20180425T121500Z
+DTEND:20180425T134500Z
+SUMMARY:Technische Grundlagen der Informatik - VL
+DESCRIPTION:Dipl.-Ing. K. Dammann - Achtung\, Veranstaltung findet unregel
+ mässig statt. Wöchentlich Stundenplan beachten!
+END:VEVENT
+BEGIN:VEVENT
+UID:1a744959b316cabf@localhost
+SEQUENCE:0
+DTSTAMP:20180429T105331Z
+DTSTART:20180426T121500Z
+DTEND:20180426T134500Z
+SUMMARY:Grundlagen des Programmierens - VL
+DESCRIPTION:Prof. Dr. J. Weimar
+END:VEVENT
+BEGIN:VEVENT
+UID:cdccad28daf287b8@localhost
+SEQUENCE:0
+DTSTAMP:20180429T105331Z
+DTSTART:20180423T140000Z
+DTEND:20180423T153000Z
+SUMMARY:Einführung in die Informatik
+DESCRIPTION:Prof. Dr. W. Pekrun
+END:VEVENT
+BEGIN:VEVENT
+UID:827650a4f581e5d1@localhost
+SEQUENCE:0
+DTSTAMP:20180429T105331Z
+DTSTART:20180424T140000Z
+DTEND:20180424T153000Z
+SUMMARY:Diskrete Strukturen
+DESCRIPTION:Prof. Dr. P. Riegler
+END:VEVENT
+BEGIN:VEVENT
+UID:9052b16c3fc97fce@localhost
+SEQUENCE:0
+DTSTAMP:20180429T105331Z
+DTSTART:20180423T154500Z
+DTEND:20180423T171500Z
+SUMMARY:Einführung in die Informatik
+DESCRIPTION:Prof. Dr. W. Pekrun
+END:VEVENT
+END:VCALENDAR \ No newline at end of file
diff --git a/index.ts b/index.ts
index 04af68a..f01ce49 100644
--- a/index.ts
+++ b/index.ts
@@ -1,7 +1,14 @@
-import {get} from 'http';
import {readFile} from 'fs';
import {SplusParser} from './SplusParser';
-import {createEvent, listEvents} from "./GoogleCalendar";
+let createEvent = (arg) => {};
+let commit = () => {};
+if (process.argv.includes('ics')) {
+ createEvent = require('./ICal').createEvent;
+ commit = require('./ICal').commit;
+} else {
+ createEvent = require('./GoogleCalendar').createEvent;
+}
+
const splusUrl = 'http://splus.ostfalia.de/semesterplan123.php?id=1362F014835FFFD0F67159E302EC1A3C&identifier=%23SPLUS7A3292';
@@ -26,7 +33,7 @@ readFile('sample.htm', (err, data) => {
return lecture.title.indexOf('Kompetenzen') === -1;
});
- lectures.forEach(lec => {
+ lectures.forEach((lec, index) => {
let beginDate = new Date(baseDate);
beginDate.setDate(beginDate.getDate() + lec.day);
@@ -52,6 +59,11 @@ readFile('sample.htm', (err, data) => {
useDefault: false
}
});
+
+ // TODO
+ if (index == lectures.length - 1) {
+ commit();
+ }
})
});
diff --git a/package-lock.json b/package-lock.json
index fff7d9e..d6f51b2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -275,6 +275,16 @@
"readable-stream": "2.3.6"
}
},
+ "ical-generator": {
+ "version": "0.2.10",
+ "resolved": "https://registry.npmjs.org/ical-generator/-/ical-generator-0.2.10.tgz",
+ "integrity": "sha512-q4TRRGIaG8McNeZRx9sF120vxVuZbPSAMiwn9GgI9+iRrrtUsLZnVUAO7dPP7XSXt+yrrrxP2LbQ+KEnUC6+JQ=="
+ },
+ "icalendar": {
+ "version": "0.7.1",
+ "resolved": "https://registry.npmjs.org/icalendar/-/icalendar-0.7.1.tgz",
+ "integrity": "sha1-0NNIZ5X48cXPT4yvrAgbS056Mq4="
+ },
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
diff --git a/package.json b/package.json
index ba71cd4..e2f7d52 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,8 @@
},
"dependencies": {
"cheerio": "^1.0.0-rc.2",
- "googleapis": "^27.0.0"
+ "googleapis": "^27.0.0",
+ "ical-generator": "^0.2.10"
},
"devDependencies": {
"@types/cheerio": "^0.22.7",