Advertisement
Guest User

Qidian underground

a guest
May 17th, 2018
1,436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.99 KB | None | 0 0
  1. #! /usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use LWP::UserAgent ();
  6. use Email::Send;
  7. use Email::Send::Gmail;
  8. use Email::Simple::Creator;
  9. use WWW::Pastebin::PastebinCom::API;
  10. use Reddit::Client;
  11.  
  12. my $ChapterInfoFile = "ChapterInfoFile";
  13. #File that Contains the Book URL number then a tab and then the
  14. #most recent chapter number that your looking for extend as needed
  15. #Example for TMW shown below for chapter 1091
  16. #7834185605001405   1091
  17.  
  18. my %Books =();
  19. #Hash of Books To Get with corresponding chapters to look for
  20.  
  21.  
  22. my $sender = Email::Send->new(
  23.       {   mailer      => 'Gmail',
  24.           mailer_args => [
  25.               username => 'username',
  26.               password => 'password',
  27.           ]
  28.       }
  29.   );
  30.  
  31. my $bin = WWW::Pastebin::PastebinCom::API->new(
  32.                         api_key => 'api_key');
  33. $bin->get_user_key("PasteBinUserName","PasteBinPassword");
  34. #Set up PasteBin API
  35.  
  36.                    
  37. my $reddit = new Reddit::Client(
  38.         user_agent => "Beep Boop Robot"
  39.     );
  40. $reddit->get_token(
  41.         client_id => "client_id",
  42.         secret => "Secret",
  43.         username => "RedditUsername",
  44.         password => "RedditPassword"
  45.     );
  46. #Set up Reddit API
  47.  
  48.  
  49. my $ua = LWP::UserAgent->new();
  50. $ua->agent("Beep Boop I'm a sneaky bot");
  51. $ua->timeout(15);
  52. $ua->ssl_opts( verify_hostname => 0);
  53. #LWP::UserAgent for grabbing HTML files
  54.  
  55.  
  56. while(1){
  57.     %Books = ();
  58.     #reset books array
  59.  
  60.     $file_data = "";
  61.     {
  62.         open(INFOFILE,"<",$ChapterInfoFile) or die "Cannot open ChapterInfoFile file";
  63.         local $/ = undef;
  64.         $file_data = <INFOFILE>;
  65.         close INFOFILE;
  66.         #Get all books from Chapter Info File
  67.  
  68.     }
  69.     $file_data =~ s/\r/\n/g;
  70.     $file_data =~ s/\v+/\n/g;
  71.     my @BookList = split /\n/,$file_data;
  72.     #One book per line
  73.  
  74.     foreach my $BookToGet (@BookList)
  75.     {
  76.         my ($BookNum,$ChapterNum) = split '\t',$BookToGet;
  77.         $Books{$BookNum} = "$ChapterNum";
  78.         #Set up Books array
  79.         #It's in this format for easy manipulation of Character Info File
  80.         #To add/remove books to grab depending on your preferences
  81.     }
  82.  
  83.  
  84.     my $url = "https://www.webnovel.com/feed/";
  85.     #RSS Feed Website To Crawl
  86.    
  87.     my $response = "";
  88.  
  89.     my $info = "";
  90.  
  91.     ### Send URL request Through proxy for fun :)
  92.     #$ua->proxy( 'http', 'ProxyURL']);
  93.     $response = $ua->get("$url");
  94.  
  95.  
  96.     if($response->is_success)#Success
  97.     {
  98.         $info = $response->content;
  99.         $pass = 1;
  100.     }
  101.     else#website or internet down
  102.     {
  103.         print STDERR "Failed to Reach RSS Feed\n";
  104.                            
  105.         my $email = Email::Simple->create(
  106.             header => [
  107.                 From    => 'FromAddress',
  108.                 To      => 'ToAddress',
  109.                 Subject => "Failed to get RSS Feed",
  110.             ],
  111.             body => "Failed to Reach RSS Feed\nFix me plz",
  112.         );
  113.         $sender->send($email);
  114.         #Send E-mail saying it failed :(
  115.     }
  116.     while ($info =~ m/<item>.*?<link>(.*?)<\/link>.*?\[CDATA\[(.*?), (.*?),(.*?),/gis)
  117.     {
  118.         #REGEX Matching for valid RSS Feed URL that goes through every update posted
  119.    
  120.         my $ChapterURL = $1;
  121.         my $BookName = $2;
  122.         my $ChapterName = $3;
  123.         my $temp = $4;
  124.         #Grabs the necessary information for each update
  125.         if ($BookName =~ m/Full Marks Hidden/)
  126.         {
  127.             $BookName .= ", $ChapterName";
  128.             $ChapterName = $temp;
  129.             #Full marks hidden marriage has an extra , in the Book Name
  130.             #Which means we have to go one extra capture group = $temp = $4
  131.         }
  132.        
  133.         my @tempContents = split(' ',$ChapterName);
  134.         my $ChapterNumber = $tempContents[1];
  135.         @tempContents = split('/',$ChapterURL);
  136.         my $Book = $tempContents[-2];
  137.         $ChapterURL =~ s/rssbook/book/gis;
  138.         $BookName =~ s/&\#39\;/\'/g;
  139.         $ChapterName =~ s/&\#39\;/\'/g;
  140.         #Fix some formatting stuff and get BookID number and Chapter Number
  141.        
  142.         if (exists $Books{$Book} && ($Books{$Book} == $ChapterNumber))
  143.         {
  144.             #NEW Chapter!
  145.                
  146.             my $newurl = "$ChapterURL";
  147.             my $ChapterResponse = "";
  148.             $ChapterResponse = $ua->get($newurl);
  149.             #Try to get chapter html file
  150.             if($ChapterResponse->is_success)
  151.             {
  152.                 my $ChapterContent = $ChapterResponse->content;
  153.                 #Basically set the html file to read through
  154.                 if ($ChapterContent =~ m/<div class="cha-words">(.*?)<\/div>/s)
  155.                 {
  156.                     my $Contents = $1;
  157.                     $Contents =~ s/<p>//g;
  158.                     $Contents =~ s/<\/p>//g;
  159.                     $Contents =~ s/&#39;/'/g;
  160.                     $Contents =~ s/&#34;/"/g;
  161.                     $Contents =~ s/\h+/ /g;
  162.                     $Contents =~ s/\v+/\n\t/g;
  163.                     #Remove excess whitespace and format better
  164.                    
  165.                    
  166.                     my $PasteURL = $bin->paste(
  167.                         "$BookName $ChapterName \n$Contents",
  168.                         title => "$BookName $ChapterName",
  169.                         owned => 1
  170.                     );
  171.                     #Paste it to pastebin
  172.            
  173.                     if (defined $PasteURL) #If paste to pastebin successful
  174.                     {
  175.                    
  176.                         $reddit->get_token(
  177.                                 client_id => "client",
  178.                                 secret => "ThisHereIsSecret",
  179.                                 username => "RedditUserName",
  180.                                 password => "RedditPassword"
  181.                             );
  182.                         my $redditPost = $reddit->submit_text(
  183.                                 subreddit => 'QidianUnderground',
  184.                                 title => "$BookName - Chapter $ChapterNumber",
  185.                                 text => "\n[Chapter $ChapterNumber]($PasteURL)\n"
  186.                             );
  187.                         #Post to reddit with various Formatting stuff
  188.                        
  189.                         #To Be Implemented Soon
  190.                         #set_post_flair(
  191.                         #       subreddit=>QidianUnderground,
  192.                         #       post_id => $redditPost,
  193.                         #       flair_template_id => WAITING FOR THIS);
  194.                    
  195.                         my $email = Email::Simple->create(
  196.                                 header => [
  197.                                     From    => 'FromAddress',
  198.                                     To      => "ToAddress",
  199.                                     Subject => "New Chapter! $BookName $ChapterName",
  200.                                 ],
  201.                                 body => "$BookName $ChapterName\n$PasteURL",
  202.                             );
  203.                         $sender->send($email);
  204.                         #Inform Whomever by e-mail we have a new post
  205.                         print STDERR "New Chapter of $BookName $ChapterName\n";
  206.                         $Books{$Book}++;
  207.                         #Update Books array to look for the new chapter
  208.                     }
  209.                     else
  210.                     {
  211.                         print STDERR "Failed at PasteBin :(";
  212.                         #SadFace
  213.                     }
  214.                 }
  215.                 else
  216.                 {
  217.                     print STDERR "They changed the format of their pages again :(\n";
  218.                     #More SadFace
  219.                 }
  220.             }      
  221.         }
  222.     }      
  223.  
  224.     open(my $fh, '>',$ChapterInfoFile) or die "Cannot open Chapter Info File";
  225.     foreach my $key (keys %Books)
  226.     {
  227.         print $fh "$key\t$Books{$key}\n";
  228.     }
  229.     close $fh;
  230.     #Update Character Info File with new chapters to look for
  231.    
  232.     sleep(5*60+int(rand(100)));
  233.     #Wait ~5-6:40 minutes so were "not" DDoS-ing webnovel.com/feed/ ;)
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement