我正在尝试获取校园谈话信息并插入Google日历。
我的问题是,我只能将事件插入默认日历(xxxx@gmail.com),但无法将事件插入其他日历(例如,名为“校园谈话”的日历)
我正在使用python执行此操作,而我正在使用Google日历api v2。
这是代码。
calendarExample类为here。
email = raw_input("Email:")
password = raw_input("Password:")
infolist = CampusTalk("http://my.yingjiesheng.com/xuanjianghui_school_4.html")
calendar = calendarExample.CalendarExample(email,password)
# Delete old calendar
feed = calendar.cal_client.GetOwnCalendarsFeed()
for entry in feed.entry:
if entry.title.text == "Campus Talk":
print 'Deleting calendar: %s' % entry.title.text
calendar.cal_client.Delete(entry.GetEditLink().href)
# Insert new calendar
calendar._InsertCalendar(title="Campus Talk",description="Calendar of Campus Talk",time_zone='Asia/Shanghai', hidden=False, location='Shanghai',color='#2952A3')
for campustalk_info in infolist:
try:
content = "%s\n%s\n%s\n%s\n%s"%(campustalk_info["city"],campustalk_info["school"],campustalk_info["location"],campustalk_info["time"].strftime("%Y-%m-%d %H:%M:%S"),campustalk_info["link"])
if campustalk_info["time"] == "0":
campustalk_info["time"] = campustalk_info["date"]
start_time = (campustalk_info["time"]+datetime.timedelta(hours=-8)).strftime("%Y-%m-%dT%H:%M:%S.000Z")
end_time = (campustalk_info["time"]+datetime.timedelta(hours=-6)).strftime("%Y-%m-%dT%H:%M:%S.000Z")
calendar._InsertSingleEvent(title=campustalk_info["company"], content=content, where=campustalk_info["location"], start_time=start_time, end_time=end_time)
except Exception,e:
print e
print "Finished!"
如您所见,我创建了一个新日历“Campus Talk”,如何将事件插入此日历而不是默认日历?
请帮帮我,谢谢!
答案 0 :(得分:0)
_InsertCalendar
会返回Calendar
个对象(请参阅第157
行)。当您致电calendar
时,请使用那个而不是当前的_InsertSingleEvent
对象(如行557
中所示)。
对于示例,请注意talks
对象的创建和使用:
talks = calendar._InsertCalendar(title="Campus Talk", ... ,color='#2952A3')
....
talks._InsertSingleEvent(title=campustalk_info["company"], ... ,end_time=end_time)
(注意我用...
缩写了长行