Guest User

tomoV1.ps1

a guest
Aug 14th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function Refresh ($uri, $search){
  3.     $returnvalue = @{}
  4.     $header = @{}
  5.     $header.Add("cache-control","no-cache")
  6.     $pagehtml = Invoke-RestMethod -uri $uri -Method GET -Headers $header
  7.     $position = $pagehtml.IndexOf($search)
  8.     $htmlextract = $pagehtml.Substring($position - 100, 1000);
  9.     $mtch = $rgx.Match($htmlextract)
  10.     $currentchapter = $mtch.Groups[1].Value
  11.     $url = $urlrgx.Match($htmlextract)
  12.  
  13.     $returnvalue.Add("currentchapter", $currentchapter)
  14.     $returnvalue.Add("url", $url)
  15.     return $returnvalue
  16. }
  17.  
  18. function Submit ($currentchapter, $url){
  19.     $currenttime = (Get-Date -UFormat "%H:%M:%S")
  20.     Write-Host ("New chapter available, {0}! Submitting to /r/manga [{1}]" -f $currentchapter, $currenttime)
  21.  
  22.     $body = ("sr={2}&title=[DISC] Tomo-chan wa Onnanoko! Ch. {0}&kind=link&url={1}" -f $currentchapter, $url, $subreddit)
  23.     Write-Host $body
  24.     if($success)
  25.     {
  26.         return
  27.     }
  28.     $accesstoken = Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri https://www.reddit.com/api/v1/access_token -Method POST -Body 'grant_type=password&username=3932695&password=###RedditPassword###'
  29.     $submission = Invoke-RestMethod -Headers @{Authorization=("bearer {0}" -f $accesstoken.access_token)} -Method POST -Uri https://oauth.reddit.com/api/submit -Body $body
  30.     if($submission.success){
  31.         $currenttime = (Get-Date -UFormat "%H:%M:%S")
  32.         Write-Host ("Submit success![{0}]" -f $currenttime)
  33.     }else{
  34.         $currenttime = (Get-Date -UFormat "%H:%M:%S")
  35.         Write-Host ("Submission failed! Impossible... we were too slow? [{0}]" -f $currenttime)
  36.         if($url.ToString() -eq $prevurl.ToString())
  37.         {
  38.             $body = ("sr={2}&title=[DISC] Tomo-chan wa Onnanoko! Ch. {0}&kind=link&resubmit={3}&url={1}" -f $currentchapter, $url, $subreddit, $true)
  39.             $submission = Invoke-RestMethod -Headers @{Authorization=("bearer {0}" -f $accesstoken.access_token)} -Method POST -Uri https://oauth.reddit.com/api/submit -Body $body
  40.             $currenttime = (Get-Date -UFormat "%H:%M:%S")
  41.             Write-Host ("Resubmit {0} [{1}]" -f $submission.success, $currenttime)
  42.         }
  43.     }
  44. }
  45.  
  46.  
  47. $header = @{}
  48. $header.Add("cache-control","no-cache")
  49. $rgx = [regex]"<h2>([0-9]*)"
  50. $urlrgx = [regex]"https:\/\/dropoutmanga.wordpress.com\/[0-9]+\/[0-9]+\/[0-9]+\/tomo-chan-.*?\/"
  51. $clientid = '###RedditAPIAccess_ClientId###'
  52. $secret = '###RedditAPIAccess_Secret###'
  53. $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $clientid,$secret)))
  54. $subreddit = "manga"
  55. $info = Refresh 'https://dropoutmanga.wordpress.com/' "/tomo-chan-"
  56. $prevurl = $info["url"]
  57.  
  58. $oldchapter = $info["currentchapter"]
  59. $useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
  60.  
  61. $success = $false
  62. $test = $false
  63. #$test = $true
  64. if($test){
  65.     $subreddit = "3932695"
  66.     [int]$intNum = [convert]::ToInt32($oldchapter, 10)
  67.     $intNum--
  68.     $oldchapter = $intNum.ToString()
  69. }
  70.  
  71.  
  72. while($true){
  73.     $currenthour = (Get-Date -UFormat "%H").ToString()
  74.     [int]$intNum = [convert]::ToInt32($oldchapter, 10)
  75.     $intNum++
  76.     $nextchapter = $intNum.ToString()
  77.    
  78.     while( ($currenthour -eq "12") -or ($currenthour -eq "13") -or $test){
  79.         while(($success -eq $false) -and (($currenthour -eq "12") -or ($currenthour -eq "13") -or $test)){
  80.            
  81.             Write-Host "wordpress.com" -fore "green"
  82.             $info = Refresh 'https://dropoutmanga.wordpress.com/' "/tomo-chan-"
  83.             $actualchapter = $info["currentchapter"]
  84.             if($actualchapter -eq $nextchapter){
  85.                 Submit $actualchapter $info["url"]
  86.                 $success = $true
  87.                
  88.             }else{
  89.                 $currenttime = (Get-Date -UFormat "%H:%M:%S")
  90.                 Write-Host ("Standing by for sequel to chapter {0}...[{1}]" -f $oldchapter, $currenttime)
  91.             }
  92.            
  93.             if($success){
  94.                 $oldchapter = $nextchapter
  95.             }
  96.            
  97.             Write-Host ""
  98.             $currenthour = (Get-Date -UFormat "%H").ToString()
  99.             Start-Sleep -m 100
  100.         }
  101.         $currenthour = (Get-Date -UFormat "%H").ToString()
  102.         $currenttime = (Get-Date -UFormat "%H:%M")
  103.  
  104.         Write-Host ("It's {0}, but the latest chapter {1} has already been submitted." -f $currenttime, $oldchapter)
  105.         Start-Sleep 60
  106.        
  107.     }
  108.  
  109.     $currenttime = (Get-Date -UFormat "%H:%M")
  110.  
  111.     Write-Host ("Not quite time yet, it's only {0}" -f $currenttime)
  112.     $success = $false
  113.    
  114.  
  115.     Start-Sleep 60
  116. }
Add Comment
Please, Sign In to add comment