| line no. 1 (9 comments) | #!/usr/bin/perl |
| line no. 2 (3 comments) | use Net::HTTP; |
| line no. 3 (0 comments) | use IO::Socket; |
| line no. 4 (0 comments) | use IO::Select; |
| line no. 5 (0 comments) | open(IMG_COUNT, "flickr_count.txt"); |
| line no. 6 (0 comments) | my $buff; |
| line no. 7 (1 comments) | $phNum = <IMG_COUNT>; |
| line no. 8 (1 comments) | close IMG_COUNT; |
| line no. 9 (0 comments) | my $text; |
| line no. 10 (3 comments) | my $fileName = "ohoh9.svg"; |
| line no. 11 (0 comments) | my $do_draw = 0; |
| line no. 12 (1 comments) | my $socket = new IO::Socket::INET |
| line no. 13 (0 comments) | Proto => 'tcp', |
| line no. 14 (0 comments) | LocalPort => 6543, |
| line no. 15 (0 comments) | Reuse => 1, |
| line no. 16 (0 comments) | Listen => 90; |
| line no. 17 (0 comments) | my $select = IO::Select->new($socket); |
| line no. 18 (0 comments) | while(1){ |
| line no. 19 (1 comments) | open(IMG_COUNT, "> flickr_count.txt"); |
| line no. 20 (0 comments) | print IMG_COUNT "$phNum"; |
| line no. 21 (0 comments) | close IMG_COUNT; |
| line no. 22 (0 comments) | $buff = null; |
| line no. 23 (0 comments) | $phURL = null; |
| line no. 24 (0 comments) | my $s = Net::HTTP->new(Host => "www.flickr.com") || die $@; |
| line no. 25 (0 comments) | $myFile = "/photo_zoom.gne?id=".$phNum."&size=s"; |
| line no. 26 (0 comments) | $s->write_request(GET => $myFile, 'User-Agent' => "Mozilla/5.0"); |
| line no. 27 (1 comments) | my($code, $mess, %h) = $s->read_response_headers; |
| line no. 28 (0 comments) | while (1) { |
| line no. 29 (0 comments) | my $n = $s->read_entity_body($buf, 1024); |
| line no. 30 (0 comments) | last unless $n; |
| line no. 31 (0 comments) | $buff .= $buf; |
| line no. 32 (0 comments) | } |
| line no. 33 (0 comments) | print "$buff\n\n\n"; |
| line no. 34 (0 comments) | if($buff){ |
| line no. 35 (0 comments) | $buff =~ /a href="http:\/\/static.flickr.com\/([^"]*)"/g; |
| line no. 36 (0 comments) | if($1){ |
| line no. 37 (0 comments) | $phURL = "http://static.flickr.com/".$1; |
| line no. 38 (0 comments) | } |
| line no. 39 (0 comments) | } |
| line no. 40 (0 comments) | print "$phURL\n"; |
| line no. 41 (0 comments) | if($phURL eq null){ |
| line no. 42 (0 comments) | print "not fetching & sketching\n"; |
| line no. 43 (0 comments) | $do_draw = 0; |
| line no. 44 (0 comments) | }else{ |
| line no. 45 (0 comments) | print "fetching & sketching\n"; |
| line no. 46 (2 comments) | qx(convert -resize 600x550 -contrast -contrast -contrast -posterize 5 -blur 5 '$phURL' temp.png); |
| line no. 47 (2 comments) | qx(autotrace -color-count 5 -despeckle-level 5 -input-format PNG -output-file ohoh9.svg temp.png); |
| line no. 48 (0 comments) | $do_draw = 1; |
| line no. 49 (0 comments) | } |
| line no. 50 (0 comments) | $phNum++; |
| line no. 51 (0 comments) | print "$phNum\n"; |
| line no. 52 (3 comments) | if($do_draw){ |
| line no. 53 (0 comments) | print "broadcasting data...\n"; |
| line no. 54 (0 comments) | open(FILE, "<$fileName"); |
| line no. 55 (1 comments) | while(<FILE>){ |
| line no. 56 (0 comments) | #foreach my $user($select->can_write(0)) { |
| line no. 57 (0 comments) | # eval{$user->send($myUrls[$length]."\n")}; |
| line no. 58 (0 comments) | #} |
| line no. 59 (0 comments) | undef($text); |
| line no. 60 (0 comments) | chomp($_); |
| line no. 61 (0 comments) | #select(undef, undef, undef, 0.25); |
| line no. 62 (0 comments) | $_ =~ /d="([^"]*)"/; |
| line no. 63 (1 comments) | $coordat = $1; |
| line no. 64 (0 comments) | chop($coordat); |
| line no. 65 (0 comments) | $_ =~ /fill:([^;]*);/; |
| line no. 66 (0 comments) | $shapeCol = $1; |
| line no. 67 (0 comments) | #$coordat =~ s/\s/,/g; |
| line no. 68 (0 comments) | $coordat =~ s/([MCL])/-$1/g; |
| line no. 69 (0 comments) | #$coordat =~ s/z//g; |
| line no. 70 (0 comments) | $coordat =~ s/^.//; |
| line no. 71 (0 comments) | #@coorsplit = split("-", $coordat); |
| line no. 72 (0 comments) | #foreach(@coorsplit){ |
| line no. 73 (0 comments) | # $text .= "$_*"; |
| line no. 74 (0 comments) | #} |
| line no. 75 (0 comments) | #print "$coordat - $shapeCol\n\n\n"; |
| line no. 76 (0 comments) | $text = "$coordat-$shapeCol"; |
| line no. 77 (0 comments) | #select(undef, undef, undef, 0.25); |
| line no. 78 (0 comments) | my $newuse = 0; |
| line no. 79 (0 comments) | foreach $user($select->can_read(0)) { |
| line no. 80 (0 comments) | if ($user == $socket) { |
| line no. 81 (0 comments) | # looks like we have a new connection |
| line no. 82 (0 comments) | $user = $socket->accept(); |
| line no. 83 (0 comments) | $select->add($user); |
| line no. 84 (0 comments) | $newuse = 1; |
| line no. 85 (0 comments) | #print $user->fileno.":connected\n"; |
| line no. 86 (0 comments) | }else{ |
| line no. 87 (0 comments) | my $data = <$user>; |
| line no. 88 (0 comments) | if (defined($data)) { |
| line no. 89 (0 comments) | if ($data =~ /user/){ |
| line no. 90 (0 comments) | # add this to our user list |
| line no. 91 (0 comments) | my $i = chr(0); |
| line no. 92 (0 comments) | $data =~ s/\n//g; |
| line no. 93 (0 comments) | $data =~ s/user//; |
| line no. 94 (0 comments) | $data =~ s/$i//g; |
| line no. 95 (0 comments) | $data =~ s/\s/_/g; |
| line no. 96 (0 comments) | $newuse = 1; |
| line no. 97 (0 comments) | $users{$user->fileno} = $data; |
| line no. 98 (0 comments) | }else{ |
| line no. 99 (0 comments) | #print $panseconn $data; |
| line no. 100 (0 comments) | } |
| line no. 101 (0 comments) | }else{ |
| line no. 102 (0 comments) | delete($users{$user->fileno}); |
| line no. 103 (0 comments) | $select->remove($user); |
| line no. 104 (0 comments) | $user->close; |
| line no. 105 (0 comments) | $newuse = 1; |
| line no. 106 (0 comments) | } |
| line no. 107 (0 comments) | } |
| line no. 108 (0 comments) | } |
| line no. 109 (0 comments) | if($newuse == 1){ |
| line no. 110 (0 comments) | for (keys %users) { |
| line no. 111 (0 comments) | $tempval .= $users{$_}."\n"; |
| line no. 112 (0 comments) | } |
| line no. 113 (0 comments) | } |
| line no. 114 (0 comments) | foreach my $user($select->can_write(0)) { |
| line no. 115 (0 comments) | if($text =~ /[0-n]/){ |
| line no. 116 (0 comments) | #chop($text); |
| line no. 117 (0 comments) | eval{$user->send($text."\n")}; |
| line no. 118 (0 comments) | } |
| line no. 119 (0 comments) | } |
| line no. 120 (0 comments) | select(undef, undef, undef, 0.15); |
| line no. 121 (0 comments) | } |
| line no. 122 (0 comments) | } |
| line no. 123 (0 comments) | sleep(1); |
| line no. 124 (6 comments) | } |