⬆️ ⬇️

Movie flyers

I dreamed to study Pearl for quite a long time, but I still could not. But the other day I gathered all my resolve and sat down at the manual. Naturally, the task needed to be solved was needed, and it was found. There is a wonderful magazine TimeOut, and on its website, flyers for free film screenings are periodically distributed. The only drawback is that you cannot subscribe to these distributions, that is, no one will send the invitation to the movie free of charge by mail. This is the inconvenience I decided to fix.



Pictures with flyers on the timeout site look like vkino.timeout.ru/pix/XXXXX.jpeg , where XXXXX is the number of the flyer. The numbers are in order, that is, the task is to periodically check whether a new picture has appeared. If a picture has appeared, it is downloaded to the server, where a thumbnail is made from it, and is sent to specific addresses. The numbers of downloaded pictures, as well as email addresses, are stored in text files. Runs on the crown.



Actually, the code:



#!/usr/bin/perl

use LWP::Simple;

use MIME::Lite;

use GD;



print "Content-type: text/html; charset=UTF-8\n\n" ;



open(FLY, "+< ../data/flyers" );

flock(FLY,2);

my @flyers = <FLY>;

@flyers=reverse(@flyers);

my $nextFlyer=$flyers[0];

my $nothing=1;

for ($n=1; $n<4; $n++){ # ,

if ($nothing){

$nextFlyer++;

while ($file= get ( "http://vkino.timeout.ru/pix/" .$nextFlyer. ".jpeg" )){

print FLY $nextFlyer. "\n" ;

open(IMG, "> ../i/" .$nextFlyer. ".jpg" );

binmode IMG;

print IMG $file;

close(IMG);

$image=GD::Image->newFromJpeg( "../i/" .$nextFlyer. ".jpg" , 1);

$thubmHeight=240;

$thubmWidth=$thubmHeight*$image->width/$image->height;

$thumb= new GD::Image($thubmWidth,$thubmHeight,1);

$thumb->copyResampled($image,0,0,0,0,$thumb->getBounds(),$image->getBounds());

open(IMG, "> ../i/" .$nextFlyer. "-thumb.jpg" );

binmode IMG;

print IMG $thumb->jpeg(80);

close(IMG);

open(MAILS, "< ../data/mails" );

flock(MAILS,2);

@mails = <MAILS>;

close(MAILS);

foreach my $mail (@mails){

$msg=MIME::Lite-> new (

From => 'merrymakers.ru <info@merrymakers.ru>' ,

To =>$mail,

Subject => ' !' ,

Data => ", ! - .. ?))"

);

$msg->attach(

Type => 'image/jpeg' ,

Path => '../i/' .$nextFlyer. '.jpg' ,

Filename => 'timeout.jpg'

);

$msg->send;

}

$nextFlyer++;

$nothing=0;

}

}

}

close(FLY);




* This source code was highlighted with Source Code Highlighter .


')

http://timeout.merrymakers.ru/ - this is for Peter

http://freekino.merrymakers.ru/ - this is for Moscow



I repeat once again - the first time I saw Pearl two days ago. I'd like to hear your comments.



UPD: I will gladly enter your email address in the coveted list. From you - a letter to vantoozz@gmail.com and the city))

UPD2: Added RSS. http://timeout.merrymakers.ru/films.xml - for Peter and http://freekino.merrymakers.ru/films.xml - for Moscow

Source: https://habr.com/ru/post/72108/



All Articles