GoogleCalendarcommandlinetoolforNode.js
Programmaticeventlisting,insertorbulkinsertmadeeasy:
$gcalinsert'Partytomorrowfrom3pmto5pm'Party:2017-09-08T15:00:00+09:00~2017-09-08T17:00:00+09:00https://www.google.com/calendar/event?eid=amNpMWE5cjg2bG80n2s0Nmg1ZWlqcW01OXMgdG9rYWdlcm9oQG0$echo\'[{"calendarId":"primary","resource":{"summary":"Party","start":{"dateTime":"2017-09-08T20:00"},"end":{"dateTime":"2017-09-08T22:00"}}},{"calendarId":"primary","resource":{"summary":"Partyagain","start":{"dateTime":"2017-09-08T22:00"},"end":{"dateTime":"2017-09-08T23:30"}}}]'\>events.json$gcalbulk-eevents.jsonEventinsertedid:gif4hl86kgt7bmgq2ojvteqe2osummary:PartyhtmlLink:https://www.google.com/calendar/event?eid=Z2lmNGhsODZrZ3Q3Ym1ncTJvanZ0ZXFlMm8gdG9rYWdlcm9oQG0Eventinsertedid:blrrb8kbrih3pq9mn10slii8acsummary:PartyagainhtmlLink:https://www.google.com/calendar/event?eid=YmxycmI4a2JyaWgzcHE5bW4xMHNsaWk4YWMgdG9rYWdlcm9oQG0$gcallistUpcomingevents(2017-09-07T00:00:00+09:00~2017-09-07T23:59:59+09:00)2017-09-0720:00-MyfavoriteTVshow2017-09-0722:30-Preparetomorrow'smeetingstuffInstallationInstallitasaglobalmodule:
npminstall-ggcalAuthenticationAuthorizationandauthenticationisdonewithOAuth2.0.
Ok,thiswilltakeonly2minutes:
1)GetyourprojectcredentialsYouwillneedafilewithyourcredentials:clientID,clientsecretandredirectURI.ThiscanbeobtainedintheDeveloperConsole:
GotoyourprojectClickinCredentialsClickCreatecredentials→OAuthclientID(ApplicationtypemustbeOther)DownloadtheJSONfile2)GenerateconsentpageURLOncewegotthecredentialswemustgenerateaconsentpageURL.
$gcalgenerateUrl(Bydefaultthecredentialswillbesearchedinyourhomedirectoryunderthenameclient_secret.json).
Thepagewillpromptyoutoauthorizeaccess,followtheinstructions.
3)Getthetoken!Withthecodewegotthroughtheauthorizationpage,wecanobtainatokenandstoreitinourmachine.
$gcalstoreToken<code>(Bydefaultthetokenisstoredinyourhomefolderunderthenamecalendar_api_token.json).
NOTE:Thetokenwillexpiryafteronehour,butarefresh_tokenisincludedaswell,allowingtheapptorefreshautomaticallythetokeneachtimeit'sused.
Withthiswearegoodtogo.Thestoredtokenandcredentialsfileswillberequiredfromnowontousethistool.
UsageListListtodayevents:
$gcallistListeventsusingnaturallanguage(poweredbySherlock):
$gcallisttomorrow$gcallist'from03/23/2017to03/27/2017'$gcallist'fromMarch23thto27th'OrwithspecificISOdates:
$gcallist-f2017-03-23-t2017-03-27InsertInserteventsusingnaturallanguage:
$gcalinsert'Partytomorrowfrom3pmto5pm'Inserteventsspecifyingtheparameters:
$gcalinsert-s'Party'-d2017-03-23-t15:00-D2hBulkInsertBulkinsertpassinga.jsor.jsonfile:
events.json
[{"calendarId":"primary","resource":{"summary":"HavingcoffeewithOkuyasu","location":"MorioCity","description":"I'mnotveryimaginativenowsosomedescriptiongoeshere","start":{"dateTime":"2017-09-08T09:00:00"},"end":{"dateTime":"2017-09-08T10:00:00"}}},{"calendarId":"primary","resource":{"summary":"DefeatDio","location":"179OroubaSt,Cairo","description":"DioisabadboysoIneedtokickhisassasap","start":{"date":"1987-06-01"},"end":{"date":"1987-06-12"}}}]$gcalbulk-e./events.jsonUsinga.jsfilecanbeusefulforrelativedatesandmore:
events.js
consttoday=newDate();today.setHours('17','00','00');consttomorrow=newDate(today.getTime()+1000*60*60*24);module.exports=[{"calendarId":"primary","resource":{"summary":`Release`,"start":{"dateTime":today.toISOString()},"end":{"dateTime":today.toISOString()}}},{"calendarId":"primary","resource":{"summary":"Release","start":{"dateTime":tomorrow.toISOString()},"end":{"dateTime":tomorrow.toISOString()}}}];$gcalbulk-e./events.jsTheavailablepropertiesarelistedhere.
OverwritingdefaultconfigUsingtheoption-C<file>thedefaultconfigcanbeoverwritten.Thisfilemustbe.jsor.json.Configurableoptionsarelocatedin./conf.js.
Example:
/somepath/config.json
{"CRED_PATH":"/my/secret/path/credentials.json","TOKEN_PATH":"/my/secret/path/token.json"}$gcal-C/somepath/config.jsongenerateUrlDoingthisyoucanstoreyourcredentialfileswhereveryouwant.
APIUsethehelpcommand.Moredetailswillbeaddedsoon.
$gcalhelp
Usage:gcal[-C<file>][cmd][--debug]OPTIONS-C,--config<file>--debugCommands:list[<term>|[-f<date|datetime>][-t<date|datetime>]][-i]Listevents.Bydefaultitshowstodayevents(executedwithoutarguments).OPTIONS-f,--from<date|datetime>-t,--to<date|datetime>-i,--show-idinsert<term>|-s<summary>-d<date>[-t<time>][-D<duration>]Insertevents.<term>isspecifiedinnaturallanguage,incaseit'snotspecified,-sand-daremandatory.OPTIONS-s,--summary<summary>-d,--date<date>-t,--time<time>-D,--duration<duration>bulk-e<file>Bulkinsertofevents.Filecanbe.jsonor.js.OPTIONS-e,--events<file>generateUrlGenerateconsentpageURL.Inordertoworkclient_secret.jsmustbeinyourhomefolder.storeToken<code>StoreTokeninyourhomefolder.helpShowthishelppage.Aboutversion0.3.0Version0.3.0usedanimmersive-cliinsteadofshellcommands.Ifyouwanttouseit,gotothebranch0.3.0.
LicenseMIT©AntonioV
评论