Permalink
Browse files

micro-site

  • Loading branch information...
Duck Duck Go
Duck Duck Go committed Jul 8, 2011
1 parent d340096 commit 47a3205aeaf952bd39c313612cb1c130c0bcffca
Showing with 260 additions and 0 deletions.
  1. +82 −0 grab.pl
  2. +178 −0 out.pl
View
82 grab.pl
@@ -0,0 +1,82 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use JSON;
+use Data::Dumper;
+use IO::Handle;
+use Net::Twitter;
+
+my $twitter = Net::Twitter->new(
+ traits => [qw/API::REST API::Search/],
+ username => 'duckduckgo',
+ password => 'XXXXXXXX'
+ );
+
+my $count = 0;
+
+$|++;
+
+my %searches = (
+ '#replaceawordinafamousquotewithduck' => undef,
+ );
+
+
+open(OUT,">>/usr/local/ddg/replaceawordinafamousquotewithduck.com/grab.txt");
+
+while (1) {
+ print $count++, "\n";
+
+ foreach my $search (keys %searches) {
+
+ my $since_id = $searches{$search} || 0;
+ my $mentions;
+ eval {
+ $mentions = $twitter->search({ q => "$search", since_id => $since_id, lang => 'en' });
+ };
+ next if !$mentions;
+
+ # For debugging.
+# print Dumper($mentions);
+
+ foreach my $mention (reverse @{$mentions->{'results'}}) {
+
+ # For debugging.
+# print Dumper($mention);
+
+ my $id = $mention->{'id'};
+ my $screen_name = $mention->{'from_user'};
+ next if !$id;
+ $searches{$search} = $id;
+
+ my $tweet = $mention->{'text'};
+ next if !$tweet;
+
+ $tweet = clean($tweet);
+ next if $tweet =~ /^(?:\@|RT)/o;
+ next if $tweet =~ /(?:@|http:\/\/)/o;
+
+ next if length($tweet)<20;
+
+ print qq($tweet\n);
+
+ print OUT qq($id\t$screen_name\t$tweet\n);
+ OUT->flush();
+
+ }
+ }
+
+ sleep(1);
+}
+close(OUT);
+
+sub clean {
+ my ($str) = @_;
+
+ $str = '' if !$str;
+
+ $str =~ s/[\t\n\r\f]//gso;
+
+ return $str;
+}
View
178 out.pl
@@ -0,0 +1,178 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use utf8;
+use Encode qw( is_utf8 _utf8_on from_to encode decode :fallbacks );
+binmode STDOUT, ":utf8";
+
+use File::Copy;
+
+my %count = ();
+my %full = ();
+my %dup = ();
+
+open(IN,"</usr/local/ddg/replaceawordinafamousquotewithduck.com/grab.txt");
+while (my $line = <IN>) {
+ chomp($line);
+ my @line = split(/\t/,$line);
+
+ my $id = $line[0];
+ next if exists $dup{$id};
+ $dup{id} = undef;
+
+ my $username = $line[1];
+ my $tweet = $line[2];
+
+ $tweet =~ s/\#replaceawordinafamousquotewithduck\s*//i;
+
+ my $tweet2 = $tweet;
+ $tweet2 =~ s/\#[^\s]+\s*//;
+ $tweet2 =~ s/\&quot\;/\"/og;
+ $tweet2 =~ s/\&amp\;/\&/g;
+ $tweet2 =~ s/\-\-.*//;
+ $tweet2 =~ s/^\s*\"//;
+ $tweet2 =~ s/\s*\"\s*$//;
+
+ # FOr debugging.
+# print qq($tweet\n);
+
+ $tweet2 = lc $tweet2;
+ $tweet2 =~ s/[^a-z]+//g;
+
+ next if !$tweet2;
+
+ $count{$tweet2}++;
+ if ($count{$tweet2}>1) {
+ $full{$tweet2} = qq($tweet\t$username\t$id);
+ }
+}
+
+my $lines = '';
+
+foreach my $tweet2 (sort {$count{$b}<=>$count{$a}} keys %count) {
+ my $count = $count{$tweet2};
+ last if $count<5;
+
+ # For debugging.
+# print $count, "\n";
+# print qq($count\t) . length($tweet2), qq(\t$tweet2\n);
+
+ my ($tweet,$username,$id) = split(/\t/,$full{$tweet2});
+
+ # For debugging.
+# print qq($tweet\t$username\t$id\n);
+
+ $lines .= qq(<div class="tweet">$tweet</div><div class="username">$count tweets; this latest one by <a href="http://twitter.com/$username">\@$username</a></div>);
+}
+
+
+open OUT, ">:encoding(UTF-8)", Encode::decode_utf8("/usr/local/ddg/www-static/replaceawordinafamousquotewithduck.com/index.tmp.html");
+print OUT <<EOH
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+ <title>#replaceawordinafamousquotewithduck</title>
+ <link title="DuckDuckGo" type="application/opensearchdescription+xml" rel="search" href="ddg/opensearch.xml">
+ <link rel="stylesheet" href="ddg/s99.css" type="text/css">
+ <meta http-equiv="refresh" content="180;url=/" />
+<style type="text/css">
+.tweet {
+ font-style: italic;
+ font-size: 20px;
+ padding-bottom: 5px;
+}
+.username {
+ font-size: 12px;
+ padding-bottom: 20px;
+}
+</style>
+</head>
+<body>
+
+<br><br>
+<center>
+
+DuckDuckGo, a search engine that <a href="http://donttrack.us">doesn't track</a> or <a href="http://dontbubble.us">bubble</a> you:
+<br><br>
+<iframe src="http://duckduckgo.com/search.html?duck=yes" style="overflow:hidden;margin:0;padding:0;width:473px;height:60px;" frameborder="0"></iframe>
+</center>
+
+<br><br>
+<center>
+<table>
+<tr>
+<td width="260" valign="top" style="padding-right: 50px;">
+
+<script src="http://widgets.twimg.com/j/2/widget.js"></script>
+<script>
+ new TWTR.Widget({
+ version: 2,
+ type: 'search',
+ search: '#replaceawordinafamousquotewithduck',
+ interval: 6000,
+ title: '#replaceawordinafamousquotewithduck',
+ subject: '',
+ width: 250,
+ height: 300,
+ theme: {
+ shell: {
+ background: '#d54249',
+ color: '#ffffff'
+ },
+ tweets: {
+ background: '#ffffff',
+ color: '#444444',
+ links: '#1986b5'
+ }
+ },
+ features: {
+ scrollbar: false,
+ loop: true,
+ live: true,
+ hashtags: true,
+ timestamp: true,
+ avatars: true,
+ toptweets: true,
+ behavior: 'default'
+ }
+ }).render().start();
+</script>
+
+<br><br>
+<a href="http://www.facebook.com/duckduckgo?sk=app_4949752878"><img src="wall-e.jpg"></a>
+<br><br>
+<a href="http://www.facebook.com/duckduckgo?sk=app_4949752878"><img src="inception.jpg"></a>
+<br><br>
+<a href="http://www.facebook.com/duckduckgo?sk=app_4949752878"><img src="jurassic-park.jpg"></a>
+<br><br>
+<a href="http://www.facebook.com/duckduckgo?sk=app_4949752878"><img src="twilight.jpg"></a>
+<br><br>
+<a href="http://www.facebook.com/duckduckgo?sk=app_4949752878"><img src="star-wars.jpg"></a>
+<br><br>
+<a href="http://www.facebook.com/duckduckgo?sk=app_4949752878"><img src="step-up-4.jpg"></a>
+<br><br>
+<a href="http://www.facebook.com/duckduckgo?sk=app_4949752878"><img src="spiderman-3.jpg"></a>
+
+</td>
+<td width="450" valign="top">
+<b>
+Top \#ReplaceAWordInAFamousQuoteWithDuck tweets,
+updated every 5min, by <a href="http://duckduckgo.com">DuckDuckGo</a> (a search engine).
+</b>
+<br><br>
+$lines
+</td>
+</tr>
+</table>
+
+</center>
+</body>
+</html>
+
+EOH
+ ;
+
+move("/usr/local/ddg/www-static/replaceawordinafamousquotewithduck.com/index.tmp.html","/usr/local/ddg/www-static/replaceawordinafamousquotewithduck.com/index.html");

0 comments on commit 47a3205

Please sign in to comment.