Purlvin's private Weblog ‹℘›

through the EyE, through the Life

GRE words Agenda ICS文件

春节假期时,曾在图书馆花了两个小时翻遍这本薄薄的小册子《17天搞定GRE单词》 。GRE红宝书几近8千的词汇,竟可只用一二十天就能背完。惊叹之余,细细想那记忆曲线,貌似也是很有说服力。当时就想着是否可以写个按那规则背单词的小软件,并且还要是手机版本的。虽然终是有andorid的手机,却是没有时间去学着折腾,也就只得将这念头暂且放放。

大年三十那夜百无聊赖,折腾着,研究了下google calendar导入的ICS文件格式(MAC下iCal、Microsoft Office的Entourage也都可以直接以此文件导入),然后写了下面一个C的简单小程序,用来生成一个按照那书所提记忆规律的提醒、可以导入google calendar的ICS文件。虽也是折腾了许久,却依旧只是信手之作罢了,很多地方都是欠妥。对于ICS文件理解只凭了导出的文件,当日是露了些内容的,只能iCal导入,后来方才发现。晚间又是拿来稍微修改,可以网页上直接google calendar导入。配上Andorid的手机,手机桌面加个google calendar的widget,自动与google帐户的calendar同步,感觉着实不错。想想或许也会有人需要,虽是半成品,也索性贴出,有意者可拿去继续折腾。

/*

* main.c

* test

*

* Created by ZHANG Joseph on 2/2/11.

* Copyright 2011 __MyCompanyName__. All rights reserved.

*

*/

#include<stdio.h>

#include <time.h>

#include <string.h>

#include “main.h”

const int max_list=50;

const int list_per_day=2;

const int start_year=2011;

const int start_month=2;

const int start_day=16;

const int start_hour=22;

//int start_date=20110216;

const char *head_ics=

BEGIN:VCALENDARn

PRODID:-//Google Inc//Google Calendar 70.9054//ENn

VERSION:2.0n

CALSCALE:GREGORIANn

METHOD:PUBLISHn

X-WR-CALNAME:purlvin@gmail.comn

X-WR-TIMEZONE:Asia/Shanghain

n

BEGIN:VTIMEZONEn

TZID:Asia/Shanghain

X-LIC-LOCATION:Asia/Shanghain

BEGIN:STANDARDn

TZOFFSETFROM:+0800n

TZOFFSETTO:+0800n

TZNAME:CSTn

DTSTART:19700101T000000n

END:STANDARDn

END:VTIMEZONEn

;

int list_review[]={1,2,4,7,15};

int list_review_all[]={1,3,7,14,29};

const int max_day=1+(1+2+4+7+15)+50/2;

const int max_task=6;

//int list_arry[max_day][max_task];

char list_arry[54][255];

int main()

{

FILE *ptr_file;

int x;

time_t now;

struct tm *timenow;

time(&now);

timenow = localtime(&now);

char *now_str;

sprintf(now_str,“%04d%02d%02dT%02d%02d%02d”, timenow->tm_year+1900,timenow->tm_mon+1,timenow->tm_mday,timenow->tm_hour,timenow->tm_min,timenow->tm_sec);

time_t tmp_time;

struct tm time_str,*ptr_time;

time_str.tm_year = start_year1900;

time_str.tm_mon = start_month1;

time_str.tm_mday = start_day;

time_str.tm_hour = start_hour;

time_str.tm_min = 00;

time_str.tm_sec = 00;

time_str.tm_isdst = –1;

ptr_time=&time_str;

ptr_file =fopen(“GRE_words_Calendar.ics”, “w”);

for (x=0; x<max_list/list_per_day; x++)

{

char str_t[255];

strcpy(str_t,list_arry[x]);

sprintf(list_arry[x], “New L%d~%d %s “,x*list_per_day+1,(x+1)*list_per_day,str_t);

for (int j=0; j<sizeof(list_review)/sizeof(int); j++) {

int p=x+list_review_all[j];

sprintf(list_arry[p], “%s(*%d)Review L%d~%d “,list_arry[p],list_review[j],x*list_per_day+1,(x+1)*list_per_day);

}

}

fprintf(ptr_file,“%sn”, head_ics);

ptr_time=&time_str;

for (x=0; x<54; x++)

{

fprintf(ptr_file,“BEGIN:VEVENTn”);

fprintf(ptr_file,“DTSTART:%04d%02d%02dT%2d0000Zn”, ptr_time->tm_year+1900,ptr_time->tm_mon+1,ptr_time->tm_mday,ptr_time->tm_hour8);

fprintf(ptr_file,“DTEND:%04d%02d%02dT%2d0000Zn”, ptr_time->tm_year+1900,ptr_time->tm_mon+1,ptr_time->tm_mday,ptr_time->tm_hour+18);

fprintf(ptr_file,“DTSTAMP:%04d%02d%02dT%2d0000Zn”, ptr_time->tm_year+1900,ptr_time->tm_mon+1,ptr_time->tm_mday,ptr_time->tm_hour+18);

// fprintf(ptr_file,”DTSTAMP:20110202T134726Zn”);

// fprintf(ptr_file,”UID:D86791AF-4A96-4AA1-A4CC-ICS-%dn”,time(NULL)+clock());

fprintf(ptr_file,“UID:D86791AF-4A96-4AA1-A4CC-ICS-%s-%02dn”,now_str,x);

fprintf(ptr_file,“CREATED:20110202T131609Zn”);

fprintf(ptr_file,“DESCRIPTION:n”);

fprintf(ptr_file,“LAST-MODIFIED:20110202T134333Zn”);

fprintf(ptr_file,“LOCATION:n”);

fprintf(ptr_file,“SEQUENCE:1n”);

fprintf(ptr_file,“STATUS:CONFIRMEDn”);

fprintf(ptr_file,“SUMMARY:%sn”,list_arry[x]);

fprintf(ptr_file,“TRANSP:OPAQUEn”);

fprintf(ptr_file,“END:VEVENTn”);

fprintf(ptr_file,“n”);

time_str.tm_mday++;

tmp_time=mktime(&time_str);

ptr_time=localtime(&tmp_time);

}

fprintf(ptr_file,“END:VCALENDARn”);

fclose(ptr_file);

return 0;

}

顺便也附个个人理解非常典型的ICS文件,不作解释,想来看过自会明白。

BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:purlvin@gmail.com
X-WR-TIMEZONE:Asia/Shanghai

BEGIN:VTIMEZONE
TZID:Asia/Shanghai
X-LIC-LOCATION:Asia/Shanghai
BEGIN:STANDARD
TZOFFSETFROM:+0800
TZOFFSETTO:+0800
TZNAME:CST
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE

BEGIN:VEVENT
DTSTART:20110216T140000Z
DTEND:20110216T150000Z
DTSTAMP:20110216T150000Z
UID:D86791AF-4A96-4AA1-A4CC-ICS-20110219T003122-00
CREATED:20110202T131609Z
DESCRIPTION:
LAST-MODIFIED:20110202T134333Z
LOCATION:
SEQUENCE:1
STATUS:CONFIRMED
SUMMARY:New L1~2
TRANSP:OPAQUE
END:VEVENT

BEGIN:VEVENT
DTSTART:20110217T140000Z
DTEND:20110217T150000Z
DTSTAMP:20110217T150000Z
UID:D86791AF-4A96-4AA1-A4CC-ICS-20110219T003122-01
CREATED:20110202T131609Z
DESCRIPTION:
LAST-MODIFIED:20110202T134333Z
LOCATION:
SEQUENCE:1
STATUS:CONFIRMED
SUMMARY:New L3~4 (*1)Review L1~2
TRANSP:OPAQUE
END:VEVENT

END:VCALENDAR

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: