From: Jess Robinson Date: Fri, 10 Dec 2010 19:35:55 +0000 (+0000) Subject: Add method of looking up talk urls on ACT conferences and adding to the talk data X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7b33909b36bbc4e89d16c48d1fcdc5a3d68d34f0;hp=0139501105bde5b42190cb136ac1ef99f69e92c8;p=catagits%2FApp-IdiotBox.git Add method of looking up talk urls on ACT conferences and adding to the talk data --- diff --git a/lib/App/IdiotBox/Importer.pm b/lib/App/IdiotBox/Importer.pm index b7ba153..0bd54f7 100644 --- a/lib/App/IdiotBox/Importer.pm +++ b/lib/App/IdiotBox/Importer.pm @@ -8,6 +8,9 @@ use ExtUtils::MakeMaker qw(prompt); use File::Spec::Functions qw(catfile catdir); use POSIX qw(strftime); +use Data::ICal; +use Text::LevenshteinXS 'distance'; + sub log_info (&) { print $_[0]->(), "\n"; } sub run { @@ -77,6 +80,15 @@ sub run { $info->{name} = prompt('What is the name of this talk?', $info->{name}); (my $slug = lc $info->{name}) =~ s/ /-/g; $info->{slug} = prompt('What is the slug for this talk?', $slug); + my $act_data = {}; + $act_data = get_act_talk_data($info->{name}, $bucket->{act_url}) + if $bucket->{act_url}; + if(exists $act_data->{talk_id}) { + $info->{act_talk_id} = $act_data->{talk_id}; + $info->{details} = $act_data->{description}; + } + + $info->{details} = prompt('Enter a talk description', $info->{details}); $info->{bucket} = $bucket; $info->{announcement} = $ann; $videos{$video_file} = bless($info, 'App::IdiotBox::Video'); @@ -96,6 +108,7 @@ sub run { $bucket->videos->add($_) for values %videos; } +## Bug, this doesn't cope with files named foo.bar.5.23.mkv etc (multiple periods) sub video_files_from_dir { my ($class, $dir) = @_; my %videos; @@ -106,4 +119,56 @@ sub video_files_from_dir { \%videos; } +## Parse the act timetable.ics to find talk data and description +## (best guess based on talk name) +sub get_act_talk_data { + my ($talk_name, $base_url) = @_; + + my $act_url = URI->new($base_url . '/timetable.ics'); + my $timetable < io($act_url); + + my $act_schedule = Data::ICal->new(data => $timetable) + or die "Can't parse timetable.ics: $!"; + + my $target = "Things I learned from users"; + + my $mangled_target = uc $target; + $mangled_target =~ s/\W//g; + + my @possibles; + + for my $entry (@{$act_schedule->entries}) { + my $title = $entry->property('SUMMARY')->[0]->decoded_value; + + my $description = $entry->property('DESCRIPTION')->[0]->decoded_value; + + my $eid = $entry->property('URL')->[0]->decoded_value; + $eid =~ s!/$!!; + $eid =~ m!.*/(.*?)$! or die "Couldn't find last component in $eid"; + $eid = $1; + + my $mangled_title = uc $title; + $mangled_title =~ s/\W//g; + + my $score = (length($mangled_title) - distance($mangled_title, $mangled_target))/length($mangled_title); + # print "Score for $mangled_title vs $mangled_target = $score\n"; + + push @possibles, { + score => $score, + title => $title, + description => $description, + event_id => $eid + }; + } + + @possibles = sort {$b->{score} <=> $a->{score}} @possibles; + + + print STDERR "ye2010/$target/ http://conferences.yapceurope.org/ye2010/talk/$possibles[0]{event_id}\n"; + + return $possibles[0]; + +} + + 1; diff --git a/share/sql/idiotbox-2.0-sqlite.sql b/share/sql/idiotbox-2.0-sqlite.sql new file mode 100644 index 0000000..ed4535d --- /dev/null +++ b/share/sql/idiotbox-2.0-sqlite.sql @@ -0,0 +1,24 @@ +CREATE TABLE buckets ( + slug TEXT NOT NULL PRIMARY KEY, + name TEXT NOT NULL, + act_url TEXT +); + +CREATE TABLE announcements ( + id INTEGER NOT NULL PRIMARY KEY, + made_at DATETIME NOT NULL, + bucket_slug TEXT REFERENCES buckets(slug) +); + +CREATE TABLE videos ( + slug TEXT NOT NULL, + bucket_slug TEXT NOT NULL REFERENCES buckets(slug), + name TEXT NOT NULL, + author TEXT NOT NULL, + act_talk_id INTEGER, + details TEXT NOT NULL DEFAULT '', + announcement_id INTEGER NOT NULL, + PRIMARY KEY (slug, bucket_slug), + FOREIGN KEY (announcement_id, bucket_slug) + REFERENCES announcements(id, bucket_slug) +);