Created
October 26, 2014 17:02
-
-
Save hatorikibble/670211b115ddc5ede366 to your computer and use it in GitHub Desktop.
Create a Top 10 list of your tweets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Text::xSV; | |
my $file = "tweet_activity_metrics.csv"; | |
my $csv = new Text::xSV; | |
my $i = 0; | |
my $all_impressions = 0; | |
my $means_impressions = 0; | |
my %tweets = (); | |
my $id = undef; | |
$csv->open_file($file); | |
$csv->read_header(); | |
while ( $csv->get_row() ) { | |
$i++; | |
($id) = $csv->extract( "Tweet id"); | |
( | |
$tweets{$id}->{tweet}, | |
$tweets{$id}->{impressions}, | |
$tweets{$id}->{url} | |
) | |
= $csv->extract( "Tweet text", "impressions", | |
"Tweet permalink" ); | |
$all_impressions += $tweets{$id}->{impressions}; | |
} | |
$means_impressions = $all_impressions / $i; | |
printf( "%s Zeilen analysiert, durchschnittliche Impressions: %.2f\n", | |
$i, $means_impressions ); | |
# Top ten | |
print "\n* Impressions\n\n"; | |
$i = 0; | |
foreach | |
my $k ( sort { $tweets{$b}->{impressions} <=> $tweets{$a}->{impressions} } | |
keys %tweets ) | |
{ | |
$i++; | |
next if $i > 10; | |
# print as html | |
# printf("<li><b><a href=\"%s\" target=\"_blank\">%s</a></b>: %s</li>\n", $tweets{$k}->{url}, $tweets{$k}->{tweet},$tweets{$k}->{impressions} ); | |
#print as text | |
printf( | |
"%s: %s (%s) %s impressions\n", | |
$i, | |
$tweets{$k}->{tweet}, | |
$tweets{$k}->{url}, | |
$tweets{$k}->{impressions} | |
); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment