Parsing calendar event entry like Google Calendar

喜你入骨 提交于 2019-12-23 03:48:38

问题


In Google Calendar, when you click on a date and enter an event, it just asks you to enter something into a text field and it'll automatically interpret what you entered.

So like, I'll enter dinner at 7PM, 7PM dinner, dinner 7PM, etc. the app would just understand what it is I'm typing.

How is this done?


回答1:


Here's something in PHP: http://blog.builtbyprime.com/php/adding-google-quick-add-to-anything-the-textdate-php-class.




回答2:


Realize this is an old post, but just in case this is useful for someone: here are some more options/ideas:

Option 1: Python

The dateutil library works quite nicely:

>> from dateutil.parser import parse
>> parse("tomrrow at 6pm", fuzzy=True)
Out[14]: datetime.datetime(2016, 11, 10, 18, 0)

>> parse("tomrrow at 6pm", fuzzy_with_tokens=True)
Out[15]: (datetime.datetime(2016, 11, 10, 18, 0), ('tomrrow at ',))

Option 2: Use the Google Calendar API

This is a bit of a hack, but it should work. You could use Google Calendar API's quickAdd:

Example request:

POST https://www.googleapis.com/calendar/v3/calendars/primary/events/quickAdd?text=Peter%2C+tomorrow+at+8am&key={YOUR_API_KEY}

Which would return an Event resource, You could use the data from this object for your needs.

Unfortunately, there doesn't seem to be a way to call quickAdd without actually creating an event in a calendar. So you'd kinda need to just have a throw-away Google calendar sitting in the background where the events would get created.



来源:https://stackoverflow.com/questions/8483719/parsing-calendar-event-entry-like-google-calendar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!