Skip to content

Commit 53eb9fb

Browse files
committed
Shouuuuld be working properly.
1 parent e3d4c53 commit 53eb9fb

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

cors/pipelines.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def dst(self,dt):
2121
RECESS_WEEK = 7
2222
TOTAL_WEEKS = 14
2323
WEEK2ACTUAL=[1,2,3,4,5,6,8,9,10,11,12,13,14]
24+
WEEKDAY=['MO','TU','WE','TH','FR','SA','SU']
25+
2426
week = timedelta(days=7)
2527
day = timedelta(days=1)
2628
hour = timedelta(hours=1)
@@ -62,16 +64,16 @@ def process_item(self, item, spider):
6264
ts_hr,ts_min = ts/100, ts%100
6365
te_hr,te_min = te/100, te%100
6466

65-
combstr = ','.join([str(WEEK2ACTUAL[i-1]+startweek) for i in lec['occurence']])
67+
combstr = ','.join([str(WEEK2ACTUAL[i-1]+startweek-1) for i in lec['occurence']])
6668

6769
lectureday = SEM_START + (dow-1)*day
6870
lecture = Event()
6971
lecture.add('summary', '%s %s'%(item['code'],l['name']))
7072
setstartend(lecture,
7173
lectureday + ts_hr*hour + ts_min*minute,
7274
lectureday + te_hr*hour + te_min*minute)
73-
lecture['RRULE'] = 'FREQ=YEARLY;BYWEEKNO=%s;'%combstr
74-
75+
lecture['rrule'] = 'FREQ=YEARLY;BYWEEKNO=%s;BYDAY=%s' % (combstr,WEEKDAY[lec['day']-1])
76+
lecture['location'] = lec['location']
7577
cal.add_component(lecture)
7678

7779
if item['tutorial_time_table'] != 'null':
@@ -83,21 +85,28 @@ def process_item(self, item, spider):
8385
ts_hr,ts_min = ts/100, ts%100
8486
te_hr,te_min = te/100, te%100
8587

86-
combstr = ','.join([str(WEEK2ACTUAL[i-1]+startweek) for i in tut['occurence']])
88+
combstr = ','.join([str(WEEK2ACTUAL[i-1]+startweek-1) for i in tut['occurence'] if i!=1 ]) #precautionary check
8789

88-
tutday = SEM_START + (dow-1)*day
90+
tutday = SEM_START + (dow-1)*day + (WEEK2ACTUAL[
91+
(tut['occurence'][0] if tut['occurence'][0] != 1 else tut['occurence'][1]) - 1 #another stupid check, tutorials really shouldn't start on 1st week.
92+
]-1)*week
8993
tutorial = Event()
9094
tutorial.add('summary', '%s %s' % (item['code'],t['name']))
9195
setstartend(tutorial,
9296
tutday + ts_hr*hour + ts_min*minute,
9397
tutday + te_hr*hour + te_min*minute)
94-
tutorial['RRULE'] = 'FREQ=YEARLY;BYWEEKNO=%s;'%combstr
98+
tutorial['rrule'] = 'FREQ=YEARLY;BYWEEKNO=%s;BYDAY=%s' % (combstr,WEEKDAY[tut['day']-1])
99+
tutorial['location'] = tut['location']
95100
cal.add_component(tutorial)
96101

97-
f = open(os.path.join('ics','%s.ics'%item['code']),'wb')
102+
f = open(os.path.join('ics',('%s.ics'%item['code'].split()[0])),'wb')
98103
f.write(cal.as_string())
99104
f.close()
100105
return item
101106
def setstartend(event,start,end):
102107
event['dtstart'] = vDatetime(start).ical()
103108
event['dtend'] = vDatetime(end).ical()
109+
event['dtstamp'] = vDatetime(datetime.now()).ical()
110+
#event['uid'] = '%s/shawn@wtf.sg'%vDatetime(datetime.now()).ical()
111+
event['sequence'] = 0
112+

0 commit comments

Comments
 (0)