Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use threads::lite;
- use threads::lite::queue;
- use strict;
- use warnings;
- use feature 'say';
- use File::Slurper;
- use JSON::XS;
- use URL::Encode;
- use WWW::Curl::Easy;
- my $threadNum = 220;
- my $email = 'paulhedden8@gmail.com';
- my $name = 'Eliott Nicholas';
- my $queue = threads::lite::queue->new();
- my $listsJSON =JSON::XS::decode_json(File::Slurper::read_text('lists.json'));
- my @finalList = ();
- while(my($key, $value) = each(%{$listsJSON})) {
- push(@finalList, map {$key =~ s/%s/subscribe\/$_/r } @{$value});
- }
- my @threads;
- foreach(1..$threadNum) {
- my $thread = threads::lite::spawn({modules => ['URL::Encode', 'WWW::Curl::Easy']}, \&doThread)->send($queue, $email, $name);
- say "Thread $_ created!";
- }
- foreach(@finalList) {
- $queue->enqueue($_);
- }
- sub doThread {
- my($queue, $name, $email) = threads::lite::receiveq();
- my $curl = WWW::Curl::Easy->new();
- $curl->setopt(WWW::Curl::Easy::CURLOPT_USERAGENT(), 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36');
- while(my $url = $queue->dequeue()) {
- my $data;
- $curl->setopt(WWW::Curl::Easy::CURLOPT_URL(), $url);
- $curl->setopt(WWW::Curl::Easy::CURLOPT_WRITEDATA(), \$data);
- $curl->setopt(WWW::Curl::Easy::CURLOPT_POST(), 1);
- $curl->setopt(WWW::Curl::Easy::CURLOPT_COPYPOSTFIELDS(), "email=$email&fullname=$name&pw=nullbyte&pw-conf=nullbyte&digest=1&email-button=Subscribe");
- $curl->perform();
- my $code = $curl->getinfo(WWW::Curl::Easy::CURLINFO_RESPONSE_CODE());
- if($code == 200){
- say "Successfully subscribed to list '$url'.";
- next;
- }
- say "Error: Was not able to subscribe to list '$url'; Code: $code; Contents: $data";;
- }
- say('Thread finished with tasks! Exiting...');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement