Skip to content

Commit

Permalink
✨ Added experimental add-to-calendar feature (#64) #66
Browse files Browse the repository at this point in the history
## REFER TO ICALENDAR STANDARD FOR DETAILS
This code is experimental several things need to be implemented for it to be complete:
1 )  Need to find out how to get the day for a given date, since ICS needs a specific date
2 ) recurring events works, even has a stop date. users should decide when to stop reminding.
3 ) replace the first code up until Future.wait to suit application needs.
  • Loading branch information
PlashSpeed-Aiman authored Apr 2, 2023
1 parent f39e3e9 commit e44cec6
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions lib/calTec.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'dart:io';
import 'dart:convert';
import 'package:albiruni/albiruni.dart';
import 'package:ical/serializer.dart';

void main(List<String> args) async {
print("hello world");
var arr = ['AERO1121', 'AERO1322', 'AERO2128'];
Albiruni albiruni = Albiruni(semester: 2, session: "2022/2023");
var mappedArr = arr
.map((e) => albiruni.fetch("ENGIN", course: e.toAlbiruniFormat()))
.toList();
var result = await Future.wait(mappedArr);
result.map((e) => print(e)).toList();
if(result.isNotEmpty){
var class_appointments = result.map((e) => GenerateCalData(e)).toList();
var serialized_calendar_data = class_appointments.map((e) => e.serialize()).toList();
var file = new File('test.ics');
var _ = serialized_calendar_data.map((e) => file.writeAsStringSync(e, mode: FileMode.append)).toList();
}

}

ICalendar GenerateCalData(List<Subject> item) {
ICalendar cal = ICalendar();
//IF SUBJECT HAS MORE THAN TWO DATES
if (item.single.dayTime.length > 1) {
for (var element in item.single.dayTime) {
cal.addElement(
IEvent(
uid: 'test@example.com',
start: DateTime(2023,3,6,),
url: 'https://pub.dartlang.org/packages/srt_parser',
status: IEventStatus.CONFIRMED,
location: 'IIUM',
description:
'COURSE TITLE:${item.single.title}\nCREDIT HOUR:${item.single.chr}\nVENUE:${item.single.venue}\nLECTURERS:\n${item.single.lect.map((e) => print(e+"\n"))}',
summary: item.single.code,
//FOR RECURRENCE UNTIL DATE, ASK INPUT FROM USER
rrule: IRecurrenceRule(
frequency: IRecurrenceFrequency.WEEKLY,
untilDate: DateTime(2023, 6, 6)),
),
);
}
return cal;}

cal.addElement(
IEvent(
uid: 'test@example.com',
start: DateTime(
2023,
3,
6,
),
url: 'https://pub.dartlang.org/packages/srt_parser',
status: IEventStatus.CONFIRMED,
location: 'IIUM',
description:
'COURSE TITLE:${item.single.title}\nCREDIT HOUR:${item.single.chr}\nVENUE:${item.single.venue}',
summary: item.single.code,
rrule: IRecurrenceRule(
frequency: IRecurrenceFrequency.WEEKLY,
untilDate: DateTime(2023, 6, 6)),
),
);
return cal;
}

0 comments on commit e44cec6

Please # to comment.