Kyle starts a series on using the cloud (in this case, Google Calendar) from the comfort of the command line. If you follow my columns in Linux The first cloud service I thought Journal, you probably are aware that I'd cover also is one of the most I'm a big fan of the command line. prevalent: Google Calendar. When it comes to getting things Although a lot of calendaring done efficiently, most of the time the options exist, in a corporate command line can't be beat. This has environment, you often are talking led me to integrating services like about either Exchange (usually instant messaging and Twitter into larger, older-school companies) BitlBee so I can use them with my or Google Apps (usually smaller command-line IRC client lrssi (both startups). C-ioogle Calendar can written up in previous LJ issues). be pretty convenient as a shared You probably also are aware that calendar, particularly if you are unlike some other Linux Journal issued an Android device at work. writers out there (I'm looking at you Plus, like with all major cloud Bill Childers), I'm a bit more skeptical services, you can collaborate and of cloud services. That said, in this day share your data with other people and age, it seems you can't escape (like the NSA). |\/ly main problem cloud services, so what's a guy like me with Google Calendar always has to do? Well, l've just figured out how been having to open up a browser to use cloud services from the comfort every time I want to view my of my green-on-black terminal. So, I calendar. Although I'm sure some figured it might be interesting to write people are logged in to the Gmail a few articles describing how you can Web interface all day and get access various cloud services from the meeting notifications that way, I'm command line. not. Because I'm usually glued to
After missing a few meetings, I decided I needed to find some way to put meeting notifications inside my terminal.
my terminal window, I often don't see those reminders. After missing a few meetings, I decided I needed to find some way to put meeting notifications inside my terminal. The CLI to Google Calendar that worked for me was gcalcli. It provides a command-line interface to view your calendar in various formats and also lets you add events—aIl from the command line. Install gcalcli gcalcli itself was not packaged for my distribution, so installation took me a few extra steps. First, I cloned the project's git repository into a local directory named src that I use to keep track of source code (feel free to replace this with the directory you use for the same purpose). Then, I created a symlink to the included script sol At this point, I tried to launch the application but noticed I was missing a few required Python libraries, such as gflags, dateutil, httplib2 and google-api-python-client. The first three had Debian packages, so I was able to install them with: $ sudo apt-get install python-gflags python-dateuttl bpython-httplib2 The final Python library wasn't packaged in Debian. For better or worse, it seems just about every modern scripting language has its own implementation of Perl’s CPAN, so I fell back to using Python's pip (which I first had to install): $ sudo apt-get install python-pip $ sudo pip install -—upgrade google-api-python-client Initial Setup could start identifying what Python With all of the libraries in place, libraries I'd need: $ cd ~/src/ $ git clone https://github.com/insanum/gcalcli.git you are ready to set up gcalcli to use your Google account. The first time gcalcli is run, it will set up your account, but if you are not $sudo In s ~/src/gcalcli/gcalcli /usr/local/bin/gcalcli running It TFOITI your local machine you Will want ‘[0 add an extra 10:00am Meeting with the Bobs argument the first time you launch 11:00am Remodel Cubical watt it so it can provide you with a URL 11:45am Lunch at F11'nger's to load locally to authorize gcalcli: 1:00pm Meeting with Michael $ gcalcli agenda —-noauth_1ocal_webserver |'V€ fOUfid thé agenda OUtpU'[ ’[O be the most useful for seeing what’ Once it's set up, you can see your on my plate for the day; however, current calendar agenda with the you also can use calw and calm agenda command (the events have to output ASCII-art-style weekly been changed to protect the innocent): and monthly calendars, respectively (Figure 1). $ gcalcli agenda Meeting Notifications in Screen Mon Jul 15 9:15am Space out and Stare at screen Having access to my calendar from
Because notifications in screen are simply scripts that output short lines of text, what I want to do is tell gcalcli to display the next meeting in my agenda today that hasn’t yet started, or if there are no more meetings today, to display nothing.
the command line is handy, but it still doesn't quite solve my problem of getting notifications so I don't miss an important meeting. I'm sure many people simply rely on the pop-up notification in their browsers, but I usually am not looking at my browser, and when I am, I'm not logged in to Gmail. I am, however, almost always looking at a screen session, so I found the best approach for me was to put notifications there. I wrote about how to set up screen notifications in my February 2011 Hack and / column, so I recommend reading that column if you haven't set up your hardstatus line yet. Because notifications in screen are simply scripts that output short lines of text, what I want to do is tell gcalcli to display the next meeting in my agenda today that hasn t yet started, or if there are no more meetings today, to display nothing. That way, I can see at a glance what meeting is next. The first step is to create a basic shell script in my local ~/bin/ directory called gagenda that calls gcalcli with extra arguments and then parses the results: $ gcalcli - nocolor nostarted agenda date " 11:59pm -vgrep -v No Events‘ | head -2 | tail -1 | grep -v "‘$ With this long one-liner, I tell gcalcli to show me all of the events on my agenda that haven't started (--nostarted) between now ("‘date‘ ") and 11:59pm. Then if there are no events, I grep that out so I get empty output. If there are results, I use head and tail to pull out the line I want. Finally, if the line is empty I also grep that out. The end result is a single line of output suitable for screen. Of course, I didn't want to stop there. What I wanted was for regular events to show up in
The key to having a status appear to change colors is to have different backtick commands show up in the same location, each assigned its own color.
white on my output, but then as wtail -1 | grep -v 'As- > /tmp/gagenda-urgent
the meeting got closer, I thought #1f there are no urgent events, look for warning
it would be nice if it turned to re events in the next 10 minutes
yellow and then finally to red. Also, rr r ! -5 /tmp/gagenda-urgent 1; then
when commands in your screen gcalcli --nocolor --nostarted agenda "‘date“' “date -a
hardstatus line take a long time to --nen e 10 m1'nutes"" | grep -v ‘No Events’ | head -2 |
run, the whole screen session can wtail -1 | grep -v r~$- > /tmp/gagenda-warning
stall, so my solution was to have my # rr there are no warning events. just grab the next
gagenda script redirect the output # event for the day
to a few temporary files. The key to rr r r -S /tmp/gagenda-warning 1; then
having a status appear to change gcalcli --nocolor --nostarted agenda "‘date"‘ 11:59pm 1
colors is to have different backtick -grep -v ‘No Events‘ 1 head -2 | tail -1|
commands show up in the same -grep -v -Ag > /tmp/gagenda
location, each assigned its own else
color. Then as long as you make cat /dev/null > /tmp/gagenda
sure that only one of the commands n
will display output at any time, you else
get the illusion that you have only cat /dev/null > /tmp/gagenda-warning
one status that changes color. Here cat /dev/null > /tmp/gagenda
is the resulting gagenda shell script n
to accomplish that:
Now l edited my local user's crontab
#!/bin/bash with crontab -e to add gagenda:
# first look for urgent events occurring * * * * * /home/greenfly/bin/gagenda
# in the next five minutes
gcalcli --nocolor --nostarted agenda "‘date"‘ “date -e To configure screen.
After missing a few meetings, I decided I needed to find some way to put meeting notifications inside my terminal.
my terminal window, I often don't see those reminders. After missing a few meetings, I decided I needed to find some way to put meeting notifications inside my terminal. The CLI to Google Calendar that worked for me was gcalcli. It provides a command-line interface to view your calendar in various formats and also lets you add events—aIl from the command line. Install gcalcli gcalcli itself was not packaged for my distribution, so installation took me a few extra steps. First, I cloned the project's git repository into a local directory named src that I use to keep track of source code (feel free to replace this with the directory you use for the same purpose). Then, I created a symlink to the included script sol At this point, I tried to launch the application but noticed I was missing a few required Python libraries, such as gflags, dateutil, httplib2 and google-api-python-client. The first three had Debian packages, so I was able to install them with: $ sudo apt-get install python-gflags python-dateuttl bpython-httplib2 The final Python library wasn't packaged in Debian. For better or worse, it seems just about every modern scripting language has its own implementation of Perl’s CPAN, so I fell back to using Python's pip (which I first had to install): $ sudo apt-get install python-pip $ sudo pip install -—upgrade google-api-python-client Initial Setup could start identifying what Python With all of the libraries in place, libraries I'd need: $ cd ~/src/ $ git clone https://github.com/insanum/gcalcli.git you are ready to set up gcalcli to use your Google account. The first time gcalcli is run, it will set up your account, but if you are not $sudo In s ~/src/gcalcli/gcalcli /usr/local/bin/gcalcli running It TFOITI your local machine you Will want ‘[0 add an extra 10:00am Meeting with the Bobs argument the first time you launch 11:00am Remodel Cubical watt it so it can provide you with a URL 11:45am Lunch at F11'nger's to load locally to authorize gcalcli: 1:00pm Meeting with Michael $ gcalcli agenda —-noauth_1ocal_webserver |'V€ fOUfid thé agenda OUtpU'[ ’[O be the most useful for seeing what’ Once it's set up, you can see your on my plate for the day; however, current calendar agenda with the you also can use calw and calm agenda command (the events have to output ASCII-art-style weekly been changed to protect the innocent): and monthly calendars, respectively (Figure 1). $ gcalcli agenda Meeting Notifications in Screen Mon Jul 15 9:15am Space out and Stare at screen Having access to my calendar from
Because notifications in screen are simply scripts that output short lines of text, what I want to do is tell gcalcli to display the next meeting in my agenda today that hasn’t yet started, or if there are no more meetings today, to display nothing.
the command line is handy, but it still doesn't quite solve my problem of getting notifications so I don't miss an important meeting. I'm sure many people simply rely on the pop-up notification in their browsers, but I usually am not looking at my browser, and when I am, I'm not logged in to Gmail. I am, however, almost always looking at a screen session, so I found the best approach for me was to put notifications there. I wrote about how to set up screen notifications in my February 2011 Hack and / column, so I recommend reading that column if you haven't set up your hardstatus line yet. Because notifications in screen are simply scripts that output short lines of text, what I want to do is tell gcalcli to display the next meeting in my agenda today that hasn t yet started, or if there are no more meetings today, to display nothing. That way, I can see at a glance what meeting is next. The first step is to create a basic shell script in my local ~/bin/ directory called gagenda that calls gcalcli with extra arguments and then parses the results: $ gcalcli - nocolor nostarted agenda date " 11:59pm -vgrep -v No Events‘ | head -2 | tail -1 | grep -v "‘$ With this long one-liner, I tell gcalcli to show me all of the events on my agenda that haven't started (--nostarted) between now ("‘date‘ ") and 11:59pm. Then if there are no events, I grep that out so I get empty output. If there are results, I use head and tail to pull out the line I want. Finally, if the line is empty I also grep that out. The end result is a single line of output suitable for screen. Of course, I didn't want to stop there. What I wanted was for regular events to show up in
The key to having a status appear to change colors is to have different backtick commands show up in the same location, each assigned its own color.
white on my output, but then as wtail -1 | grep -v 'As- > /tmp/gagenda-urgent
the meeting got closer, I thought #1f there are no urgent events, look for warning
it would be nice if it turned to re events in the next 10 minutes
yellow and then finally to red. Also, rr r ! -5 /tmp/gagenda-urgent 1; then
when commands in your screen gcalcli --nocolor --nostarted agenda "‘date“' “date -a
hardstatus line take a long time to --nen e 10 m1'nutes"" | grep -v ‘No Events’ | head -2 |
run, the whole screen session can wtail -1 | grep -v r~$- > /tmp/gagenda-warning
stall, so my solution was to have my # rr there are no warning events. just grab the next
gagenda script redirect the output # event for the day
to a few temporary files. The key to rr r r -S /tmp/gagenda-warning 1; then
having a status appear to change gcalcli --nocolor --nostarted agenda "‘date"‘ 11:59pm 1
colors is to have different backtick -grep -v ‘No Events‘ 1 head -2 | tail -1|
commands show up in the same -grep -v -Ag > /tmp/gagenda
location, each assigned its own else
color. Then as long as you make cat /dev/null > /tmp/gagenda
sure that only one of the commands n
will display output at any time, you else
get the illusion that you have only cat /dev/null > /tmp/gagenda-warning
one status that changes color. Here cat /dev/null > /tmp/gagenda
is the resulting gagenda shell script n
to accomplish that:
Now l edited my local user's crontab
#!/bin/bash with crontab -e to add gagenda:
# first look for urgent events occurring * * * * * /home/greenfly/bin/gagenda
# in the next five minutes
gcalcli --nocolor --nostarted agenda "‘date"‘ “date -e To configure screen.
Aucun commentaire:
Enregistrer un commentaire