Advertisement
Guest User

Untitled

a guest
May 1st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. use threads::lite;
  2. use threads::lite::queue;
  3. use strict;
  4. use warnings;
  5. use feature 'say';
  6. use File::Slurper;
  7. use JSON::XS;
  8. use URL::Encode;
  9. use WWW::Curl::Easy;
  10.  
  11. my $threadNum = 220;
  12. my $email = 'paulhedden8@gmail.com';
  13. my $name = 'Eliott Nicholas';
  14.  
  15. my $queue = threads::lite::queue->new();
  16. my $listsJSON =JSON::XS::decode_json(File::Slurper::read_text('lists.json'));
  17. my @finalList = ();
  18.  
  19. while(my($key, $value) = each(%{$listsJSON})) {
  20. push(@finalList, map {$key =~ s/%s/subscribe\/$_/r } @{$value});
  21. }
  22.  
  23. my @threads;
  24. foreach(1..$threadNum) {
  25. my $thread = threads::lite::spawn({modules => ['URL::Encode', 'WWW::Curl::Easy']}, \&doThread)->send($queue, $email, $name);
  26. say "Thread $_ created!";
  27. }
  28. foreach(@finalList) {
  29. $queue->enqueue($_);
  30. }
  31.  
  32. sub doThread {
  33. my($queue, $name, $email) = threads::lite::receiveq();
  34.  
  35. my $curl = WWW::Curl::Easy->new();
  36.  
  37. $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');
  38. while(my $url = $queue->dequeue()) {
  39. my $data;
  40. $curl->setopt(WWW::Curl::Easy::CURLOPT_URL(), $url);
  41. $curl->setopt(WWW::Curl::Easy::CURLOPT_WRITEDATA(), \$data);
  42. $curl->setopt(WWW::Curl::Easy::CURLOPT_POST(), 1);
  43. $curl->setopt(WWW::Curl::Easy::CURLOPT_COPYPOSTFIELDS(), "email=$email&fullname=$name&pw=nullbyte&pw-conf=nullbyte&digest=1&email-button=Subscribe");
  44. $curl->perform();
  45. my $code = $curl->getinfo(WWW::Curl::Easy::CURLINFO_RESPONSE_CODE());
  46.  
  47. if($code == 200){
  48. say "Successfully subscribed to list '$url'.";
  49. next;
  50. }
  51. say "Error: Was not able to subscribe to list '$url'; Code: $code; Contents: $data";;
  52. }
  53.  
  54.  
  55. say('Thread finished with tasks! Exiting...');
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement