Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Refresh ($uri, $search){
- $returnvalue = @{}
- $header = @{}
- $header.Add("cache-control","no-cache")
- $pagehtml = Invoke-RestMethod -uri $uri -Method GET -Headers $header
- $position = $pagehtml.IndexOf($search)
- $htmlextract = $pagehtml.Substring($position - 100, 1000);
- $mtch = $rgx.Match($htmlextract)
- $currentchapter = $mtch.Groups[1].Value
- $url = $urlrgx.Match($htmlextract)
- $returnvalue.Add("currentchapter", $currentchapter)
- $returnvalue.Add("url", $url)
- return $returnvalue
- }
- function Submit ($currentchapter, $url){
- $currenttime = (Get-Date -UFormat "%H:%M:%S")
- Write-Host ("New chapter available, {0}! Submitting to /r/manga [{1}]" -f $currentchapter, $currenttime)
- $body = ("sr={2}&title=[DISC] Tomo-chan wa Onnanoko! Ch. {0}&kind=link&url={1}" -f $currentchapter, $url, $subreddit)
- Write-Host $body
- if($success)
- {
- return
- }
- $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###'
- $submission = Invoke-RestMethod -Headers @{Authorization=("bearer {0}" -f $accesstoken.access_token)} -Method POST -Uri https://oauth.reddit.com/api/submit -Body $body
- if($submission.success){
- $currenttime = (Get-Date -UFormat "%H:%M:%S")
- Write-Host ("Submit success![{0}]" -f $currenttime)
- }else{
- $currenttime = (Get-Date -UFormat "%H:%M:%S")
- Write-Host ("Submission failed! Impossible... we were too slow? [{0}]" -f $currenttime)
- if($url.ToString() -eq $prevurl.ToString())
- {
- $body = ("sr={2}&title=[DISC] Tomo-chan wa Onnanoko! Ch. {0}&kind=link&resubmit={3}&url={1}" -f $currentchapter, $url, $subreddit, $true)
- $submission = Invoke-RestMethod -Headers @{Authorization=("bearer {0}" -f $accesstoken.access_token)} -Method POST -Uri https://oauth.reddit.com/api/submit -Body $body
- $currenttime = (Get-Date -UFormat "%H:%M:%S")
- Write-Host ("Resubmit {0} [{1}]" -f $submission.success, $currenttime)
- }
- }
- }
- $header = @{}
- $header.Add("cache-control","no-cache")
- $rgx = [regex]"<h2>([0-9]*)"
- $urlrgx = [regex]"https:\/\/dropoutmanga.wordpress.com\/[0-9]+\/[0-9]+\/[0-9]+\/tomo-chan-.*?\/"
- $clientid = '###RedditAPIAccess_ClientId###'
- $secret = '###RedditAPIAccess_Secret###'
- $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $clientid,$secret)))
- $subreddit = "manga"
- $info = Refresh 'https://dropoutmanga.wordpress.com/' "/tomo-chan-"
- $prevurl = $info["url"]
- $oldchapter = $info["currentchapter"]
- $useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
- $success = $false
- $test = $false
- #$test = $true
- if($test){
- $subreddit = "3932695"
- [int]$intNum = [convert]::ToInt32($oldchapter, 10)
- $intNum--
- $oldchapter = $intNum.ToString()
- }
- while($true){
- $currenthour = (Get-Date -UFormat "%H").ToString()
- [int]$intNum = [convert]::ToInt32($oldchapter, 10)
- $intNum++
- $nextchapter = $intNum.ToString()
- while( ($currenthour -eq "12") -or ($currenthour -eq "13") -or $test){
- while(($success -eq $false) -and (($currenthour -eq "12") -or ($currenthour -eq "13") -or $test)){
- Write-Host "wordpress.com" -fore "green"
- $info = Refresh 'https://dropoutmanga.wordpress.com/' "/tomo-chan-"
- $actualchapter = $info["currentchapter"]
- if($actualchapter -eq $nextchapter){
- Submit $actualchapter $info["url"]
- $success = $true
- }else{
- $currenttime = (Get-Date -UFormat "%H:%M:%S")
- Write-Host ("Standing by for sequel to chapter {0}...[{1}]" -f $oldchapter, $currenttime)
- }
- if($success){
- $oldchapter = $nextchapter
- }
- Write-Host ""
- $currenthour = (Get-Date -UFormat "%H").ToString()
- Start-Sleep -m 100
- }
- $currenthour = (Get-Date -UFormat "%H").ToString()
- $currenttime = (Get-Date -UFormat "%H:%M")
- Write-Host ("It's {0}, but the latest chapter {1} has already been submitted." -f $currenttime, $oldchapter)
- Start-Sleep 60
- }
- $currenttime = (Get-Date -UFormat "%H:%M")
- Write-Host ("Not quite time yet, it's only {0}" -f $currenttime)
- $success = $false
- Start-Sleep 60
- }
Add Comment
Please, Sign In to add comment