Merging multiple Google Calendar feeds for display on my desktop - windows

I have several Google calendars that I'd like to merge and place on my windows desktop using Samurize. I've tried using Samurize's Page Scraper plugin, but it doesn't appear to be up to the task.
I can get Samurize to run a script and place it's output on the desktop, but I'm not sure
what the best tools are to do this.
All the URLs I have are of the form:
http://www.google.com/calendar/feeds/example%40gmail.com/private-REMOVED/basic?futureevents=true&orderby=starttime&sortorder=ascending&singleevents=true
So I could fetch them using curl, but then I need to filter them.
I want something that looks like:
2009 12 02 Event from calendar 1's description
2009 12 03 Event from calendar 2's description
2009 12 04 Event from calendar 1's description
2009 12 05 Event from calendar 3's description
2009 12 06 Event from calendar 1's description
However the dates in the calendar feeds are formatted like this:
<title type='html'>Event from calendar 1's description</title><summary type='html'>When: Fri 5 Dec 2008<br>
So how do I filter out the dates and descriptions, and convert the dates?
(I have cygwin installed so something using perl or sed/awk would be perfect as I'm familiar enough with them that I'd be confident about altering them in future, but I'm open to suggestions.)

I'm learning perl so please don't laugh too hard, but here's something that might get you most of the way towards parsing:
#!C:\Perl\bin -w
use strict;
my %months = ("Jan", "01", "Feb", "02", "Mar", "03", ... etc. etc. ... "Dec", "12");
$_ = "<title type='html'>Event from calendar 1's description</title><summary type='html'>When: Fri 5 Dec 2008<br>";
if (/<title type='html'>([\d\D]*)<\/title><summary type='html'>When: (\S+) (\S+) (\S+) (\S+)<br>/)
{
print "$5 $months{$4} $3 $1\n";
}

Two ideas.
You could use Yahoo Pipes (see this article.)
Or, if you don't want to wait around for Yahoo to refresh it's data, here is a python script under development to merge ICAL files.

Building on John W's script this is what I'm using
#!c:\cygwin\bin\perl.exe -w
use strict;
use LWP::Simple qw(get);
my %calendars = ( "Sam Hasler", "http://www.google.com/calendar/feeds/blah/blah/basic"
, "Family ", "http://www.google.com/calendar/feeds/blah/blah/basic"
, "Work ", "http://www.google.com/calendar/feeds/blah/blah/basic"
);
my $params = "?futureevents=true&orderby=starttime&sortorder=ascending&singleevents=true";
my %months = ( "Jan", "01", "Feb", "02", "Mar", "03", "Apr", "04"
, "May", "05", "Jun", "06", "Jul", "07", "Aug", "08"
, "Sep", "09", "Oct", "10", "Nov", "11", "Dec", "12");
my $calendar_name;
my $calendar_url;
my #lines;
while (($calendar_name, $calendar_url) = each(%calendars)){
my $calendar_data = get "$calendar_url$params";
#lines = split(/\n/, $calendar_data);
foreach (#lines) {
if (/<title type='html'>([\d\D]*)<\/title><summary type='html'>When: (\S+) (\S+) (\S+) (\S+)<br>/)
{
my $day = "$3";
if ($3 < 10 ) {
$day = "0$3";
}
print "$5 $months{$4} $day\t$calendar_name\t$1\n";
}
}
}
I just pipe the output through sort to get it in date order.
Update: I've converted my script to a plugin and submitted it to the Samurize website: Merge Google Calendar feeds.

Related

Business Profile Performance: values are differente than GBP App

I have a gap in values between the one returned by Google Business Profile Performance API and the one in Google Business Profile application.
For example, on 14th July 2022, Google Business Profile Performance API give me a value to 28 for the BUSINESS_DIRECTION_REQUESTS metric.
The request parameters:
{
"dailyMetric": "BUSINESS_DIRECTION_REQUESTS",
"dailyRange.startDate.day": 20,
"dailyRange.startDate.month": 7,
"dailyRange.startDate.year": 2021,
"dailyRange.endDate.day": 17,
"dailyRange.endDate.month": 7,
"dailyRange.endDate.year": 2022,
"name": "locations/10[...]19"
}
The response on 14th July:
{
"date": {
"year": 2022,
"month": 7,
"day": 14
},
"value": "28"
}
For the same day, on Google Business Profile application, the graph of customer actions give me 40 itinirary requests:
How to explain this gap between values ?
I had the same issue where BUSINESS_DIRECTION_REQUESTS were much lower than their old, supposedly equivalent metric actions_driving_directions. I contacted Google Profile and this was their answer:
“Going forward with the new Performance API multiple impressions by a unique user within a single day are counted as a single impression.”

Ruby ARGF & RegEx: How to split on paragraph carriage return "\r\n" but not end of line "\r\n"

I am trying to pre-process some text using regex in ruby to input into a mapper job and would like to split on the carriage return denoting the paragraph.
The text will be coming into the mapper using ARGF.each as part of a hadoop streaming job
"\"Walter Elliot, born March 1, 1760, married, July 15, 1784, Elizabeth,\r\n"
"daughter of James Stevenson, Esq. of South Park, in the county of\r\n"
"Gloucester, by which lady (who died 1800) he has issue Elizabeth, born\r\n"
"June 1, 1785; Anne, born August 9, 1787; a still-born son, November 5,\r\n"
"1789\"\r\n"
"\r\n" # <----- this is where I would like to split
"Precisely such had the paragraph originally stood from the printer's\r\n"
Once I have done this I will chomp the newline /carriage return of each line.
This will look something like this:
ARGF.each do |text|
paragraph = text.split(INSERT_REGEX_HERE)
#some more blah will happen beyond here
end
UPDATE:
The desired output then is an array as follows:
[
[0] "\"Walter Elliot, born March 1, 1760, married, July 15, 1784, Elizabeth,\r\n"
"daughter of James Stevenson, Esq. of South Park, in the county of\r\n"
"Gloucester, by which lady (who died 1800) he has issue Elizabeth, born\r\n"
"June 1, 1785; Anne, born August 9, 1787; a still-born son, November 5,\r\n"
"1789\"\r\n"
[1] "Precisely such had the paragraph originally stood from the printer's\r\n"
]
Ultimately what I want is the following array with no carriage returns within the array:
[
[0] "\"Walter Elliot, born March 1, 1760, married, July 15, 1784, Elizabeth,"
"daughter of James Stevenson, Esq. of South Park, in the county of"
"Gloucester, by which lady (who died 1800) he has issue Elizabeth, born"
"June 1, 1785; Anne, born August 9, 1787; a still-born son, November 5,"
"1789\""
[1] "Precisely such had the paragraph originally stood from the printer's"
]
Thanks in advance for any insights.
Beware when you do ARGF.each do |text|, the text will be every single line, NOT the whole text block.
You can provide ARGF.each a special line separator, it will return you two "lines", which are the two paragraphs in your case.
Try this:
paragraphs = ARGF.each("\r\n\r\n").map{|p| p.gsub("\r\n","")}
First, split input into two paragraphs, then use gsub to remove unwanted line breaks.
To split the text use:
result = text.gsub(/(?<!\")\\r\\n|(?<=\\\")\\r\\n/, '').split(/[\r\n]+\"\\r\\n\".*?[\r\n]+/)

Check if array of Dates are adjacent ordered months

I have an array of Dates. I need to check if it follows a month sequence, e.g.:
[Mar 2010, Apr 2010, May 2010, Jun 2010, ..., Jan 2012]
Since a Date object should have day, month and year, I want to ignore the day, and just worry about month and year.
I want to get true if there are no months "missing" on the sequence. In other words, after April or the vector ends, or I have a May; after a May either the vector ends or there is a June.
I want to get false if the months are not ordered correctly (from older to newer) or if there are months missing.
I can easily check if the dates are ordered by using the "<" operator. But I'm not sure how to check if there are missing months. How can I do that?
Here's one way
require 'date'
>> dates
=> ["Nov 2010", "Dec 2010", "Jan 2011"]
>> date_objs = dates.map{|d| Date.parse d }
=> [#<Date: 2010-03-01 ((2455257j,0s,0n),+0s,2299161j)...]
>> date_objs.each_cons(2).all?{|d1, d2| d1.next_month == d2 }
=> true
This handles missing months as well:
>> dates = ["Nov 2010", "Dec 2010", "Feb 2011"]
>> date_objs = dates.map{|d| Date.parse(d) }
>> date_objs.each_cons(2).all?{|d1, d2| d1.next_month == d2 }
=> false
require 'date'
ar =["Mar 2010","Apr 2010", "May 2010", "Jun 2010"]
p ar.map{|d| Date.parse(d)}.each_cons(2).all?{|(d1,d2)| (d1 >> 1) == d2} #=> true

Get the word after a particular word in a Ruby string?

How do I get the word after a particular word in a Ruby string?
For example:
From:Ysxrb<abc#gmail.com>\nTo: <xyzn#gmail.com>Subject: xyzabc\nDate: Tue, 19 Jun 2012 03:26:56 -0700\nMessage-ID: <9D.A1.02635.ABB40EF4#ecout1>
I just want to get:
Ysxrb<abc#gmail.com
xyzabc
I think your question/requirement may need a bit of refinement.
You state: "How to get the word after a particular word in a ruby string?" and your example text is this : "From:Ysxrb\nTo: Subject: xyzabc\nDate: Tue, 19 Jun 2012 03:26:56 -0700\nMessage-ID: <9D.A1.02635.ABB40EF4#ecout1>"
and then you finally say that what you really want out of these string are the following words:
"'Ysxrb' and 'xyzabc'".
Will you always be parsing email text, which is what this appears to be? If so, then there are some more specific approaches you could take. For instance, in this example you could do something like this:
eml = "From:Ysxrb\nTo: Subject: xyzabc\nDate: Tue, 19 Jun 2012 03:26:56 -0700\nMessage-ID: <9D.A1.02635.ABB40EF4#ecout1>"
tokens = eml.split(/[\s\:]/)
which would yield this:
["From", "Ysxrb", "To", "", "Subject", "", "xyzabc", "Date", "", "Tue,", "19", "Jun", "2012", "03", "26", "56", "-0700", "Message-ID", "", "<9D.A1.02635.ABB40EF4#ecout1>"]
At this point, if the word following "To" and "Subject" are what you're after, you could simply get the first non-blank array element after each one, like this:
tokens[tokens.find_index("From") + 1] => "Ysxrb"
tokens[tokens.find_index("Subject") + 2] => "xyzabc" # + 2 is needed because of the newline.
You can use a regular expresion, try this on a irb console:
string = "From:Ysxrb<abc#gmail.com>\nTo: <xyzn#gmail.com>Subject:"
/From:(.+)\n/.match string
$1
$1 hold the backreference we capture with the parenthesis in the regular expression
You could try a regexp, here's an example:
>> s = "From:Ysxrb\nTo: Subject: xyzabc\nDate: Tue, 19 Jun 2012 03:26:56 -0700\nMessage-ID: <9D.A1.02635.ABB40EF4#ecout1>"
=> "From:Ysxrb\nTo: Subject: xyzabc\nDate: Tue, 19 Jun 2012 03:26:56 -0700\nMessage-ID: <9D.A1.02635.ABB40EF4#ecout1>"
>> m, w1, w2 = s.match(/^From:(\w*)\W+.*Subject: (\w*)/).to_a
=> ["From:Ysxrb\nTo: Subject: xyzabc", "Ysxrb", "xyzabc"]
>> w1
=> "Ysxrb"
>> w2
=> "xyzabc"
to find out a good regexp for your requirements, you may use rubular, a Ruby regular expression editor

How to delete an element start with underscore ruby array

I am having an array
["You purchased 2 tickets to: \n",
"____________________________________________________________________________\n",
"_________________ \n",
"The Temper Trap\n", "Webster Hall, New York, NY\n", "Fri, Apr 2, 2010 07:00 PM \n",
"\n", "Order for: Vikas Sekhri\n"]
I want to remove the underscore (means second and third element of an array). I need like this
["You purchased 2 tickets to: \n", "The Temper Trap\n", "Webster Hall, New York, NY\n", "Fri, Apr 2, 2010 07:00 PM \n", "\n", "Order for: Vikas Sekhri\n"]
Anyone can help me
arr = ["You purchased 2 tickets to: \n", "____________________________________________________________________________\n", "_________________ \n", "The Temper Trap\n", "Webster Hall, New York, NY\n", "Fri, Apr 2, 2010 07:00 PM \n", "\n", "Order for: Vikas Sekhri\n"]
arr.reject { |elt| elt.starts_with? "_" }
array.reject! {|element| element =~ /_/ }
This modifies the array. If you don't want it modified, use reject (without the bang) instead.

Resources