Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
matsuya.pl
#!/usr/bin/env perl
use strict;
use warnings;
use Time::Piece;
use Data::ICal;
use Data::Dumper;
# ここにicsファイルのパスを入力
my $ICS_PATH = 'swarm.ics';
my $calendar = Data::ICal->new(filename => $ICS_PATH);
my %stores;
my @hours;
my $entry_num = 0;
for my $entry (@{$calendar->entries})
{
my $locations = $entry->property('location');
my $location = @$locations[0]->value;
if ($location =~ m/松屋/)
{
$entry_num++;
my $dtstarts = $entry->property('dtstart');
my $dtstart = @$dtstarts[0]->value;
my $dt = localtime Time::Piece->strptime($dtstart, "%Y%m%dT%H%M%SZ")->epoch;
print sprintf("%03d", $entry_num) . ". " . $dt->strftime("%Y/%m/%d %H:%M:%S") . " - " . $location . "\n";
$stores{$location} = {
'date' => $dt->strftime("%Y/%m/%d %H:%M:%S"),
'num' => exists($stores{$location}) ? ++$stores{$location}{num} : 1,
};
$hours[$dt->hour]++;
}
}
print "\n";
my $store_num = 0;
for my $store (sort {$stores{$b}{num} <=> $stores{$a}{num} || $stores{$a}{date} cmp $stores{$b}{date}} keys %stores)
{
$store_num++;
print sprintf("%02d", $store_num) . ". " . $stores{$store}{num} . "" . $store . " (" . $stores{$store}{date} . ")\n";
}
print "\n";
print Dumper(\@hours);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment