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?
Here's something in PHP: http://blog.builtbyprime.com/php/adding-google-quick-add-to-anything-the-textdate-php-class.
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.
Related
I've got the following dictionary in my code:
{
"morning": now.hour > 0,
"afternoon": now.hour > 12,
"evening": now.hour > 18,
"bit_late": now.hour > 21,
}
It's part of a Django project (v3.1), and whenever I run the server it throws up no errors, but it is using UTC time instead of my local system's time (+ 5 1/2 UTC). Hence, when I viewed the page at 3 PM, it wished me "Good morning" (which it's programmed to do). I've included the datetime library, but I don't know how to use it or any other library to try and get the program to run using system time.
Am I missing any particular library? What method should I use to get the system time, and where do I put it?
now = datetime.datetime.now()
This is the code I used for now, just for reference!
Thanks in advance!
Yep, I've got my answer. I simply used JavaScript to display the message instead of trying something with Django. Thanks to everyone!
I have a simple script shown below. I want to use the value of holiday_value to create a filter. I am thinking this could be done by putting the value into zap storage and then retrieving the value from storage and use it in a zap filter. I don't know how to get the value from the script into zap storage.
from datetime import date
import holidays
us_holidays = holidays.US()
if date.today() in us_holidays:
holiday_value='true'
else:
holiday_value='false'
I'm not really good at Python, but here's what you could do.
Trigger
If you want to trigger another Zap from this Code step, you could use the requests library and Zapier's Webhooks as a Trigger step for your other Zap (Zap that you want to Trigger).
Here are the steps:
Setup a Zap with the trigger app as Webhooks. Get the webhook URL.
From the Code step, make a request to the Webhook URL with the value of holiday_value. (Here is a sample POST request). Also helpful to refer to this example.
Filter
If you are looking for creating a filter in the same Zap instead,
You could return the value of holiday_value from this code step. Refer documentation here.
Your code would probably look like (Please check syntax, I'm not good at Python),
from datetime import date
import holidays
us_holidays = holidays.US()
if date.today() in us_holidays:
return {'holiday_value': 'true'}
else:
return {'holiday_value': 'false'}
You can now add a filter step that only allows the Zap to continue if holiday_value equals True or False. Documentation for filters here.
Hope that helps.
I'm in France. UTC+02:00
If I try on my PC :
print(timezone.now())
print(make_aware(datetime.now()))
I get this:
2017-05-24 20:46:02.426011+00:00
2017-05-24 22:46:02.426011+02:00
In which format should I write the datetime?
Here's my mixin I wrote for all my forms and I'm not sure if I did the right thing. The idea behind this is: I 'convert' all datetimes I get to
UTC+00:00 (== UTC) and I write them, and when I have to display them, I call make_aware() so it takes the language of the client browser and use the UTC+xx:xx of the browser.
# from django.utils.datetime_safe import datetime as datetime_safe
class DateUtilsMixin(object):
#staticmethod
def make_date_aware(d):
# make d "aware"
if type(d) is str:
return make_aware(
datetime_safe.combine(parse_date(d),
time(0, 0, 0)),
timezone=pytz.timezone('UTC'))
elif type(d) is datetime_date:
return make_aware(
datetime_safe.combine(d, time(0, 0, 0)),
timezone=pytz.timezone('UTC'))
return d
Django itself activates the timezone of the client's browser (which is great) so I'm asking if my code seems "logical" and do/should adapt itself to various client's timezones. For example the Django app would work the same way if I'm in China and if I'm at Tahiti and if I'm in Australia (with the server in France)
Am I doing the right stuff, and if not, what should I change to be sure to display the date time to the right timezone, using the client's language?
query = gdata.calendar.client.CalendarEventQuery()
query.max_results = 100
feed = calendar_client.GetCalendarEventFeed(CALENDAR_URL, q=query)
for i, an_event in enumerate(feed.entry):
print an_event.when
Last line prints an empty list for all the events in the calendar. If I remove the CALENDAR_URL and use the default calendar for my account, then I can see the start/end times for each event. However, I cannot seem to do that for a shared calendar (although I can see all this information in the WebGUI and I also have all the permissions in place to modify the calendar with my username - even if I don't own it).
Any idea what I am doing wrong here?
Using the GData Calendar API via App Engine in Python, when you create an event there are handy little helper methods to parse the response:
new_event = calendar_service.InsertEvent(event, '/calendar/feeds/default/private/full')
helper = new_event.GetEditLink().href
When you create a new calendar:
new_calendar = gd_client.InsertCalendar(new_calendar=calendar)
I was wondering if there might be related methods that I just can't find in the documentation (or that are--perhaps--undocumented)?
I need to store the new calendar's ID in the datastore, so I would like something along the lines of:
new_calendar = gd_client.InsertCalendar(new_calendar=calendar)
new_calendar.getGroupLink().href
In my code, the calendar is being created, and G is returning the Atom response with a 201, but before I get into using elementtree or atom.parse to extract the desired element, I was hoping someone here might be able to help.
Many thanks in advance :)
I've never used the GData API, so I could be wrong, but...
It looks like GetLink() will return the link object for any specified rel. Seems like GetEditLink() just calls GetLink(), passing in the rel of the Edit link. So you should be able to call GetLink() on the response from InsertCalendar(), and pass in the rel of the Group link.
Here's the pydoc info that I used to figure this out: http://gdata-python-client.googlecode.com/svn/trunk/pydocs/gdata.calendar_resource.data.html