YouTube Bots, web automation tools Facebook Bots Twitter Bots Pinterest Bots...

Tuesday 2 December 2014

Amazon Gift Code Redeemer

04:16 Posted by Unknown No comments
Below is an Autohotkey script that enters Amazon gift codes from AmazonCodes.txt (1 per line). Save the code below in an Autohotkey script file and run the script. It will open Internet Explorer. Login to the Amazon account you want to add the codes to, navigate to the gift code entry form, and press and hold the Alt key and then press the z key to activate the hotkey that enters the codes. Requires Autohotkey.

Code:

#NoEnv
SetWorkingDir %A_ScriptDir%
;=============================

Pwb := ComObjCreate("InternetExplorer.Application")
Pwb.Visible := True
Return

;=============================

!z::
;==============
IfNotExist, AmazonCodes.txt
  Return
FileRead, e, EnteredCodes.txt
FileRead, c, AmazonCodes.txt
StringReplace, c, c, `r`n, ^, All
StringSplit, ca, c, ^

Loop, %ca0%
{
  d := ca%A_Index%
  StringSplit, da, d, |
  Code := da1

  If A_Index = 1
    Msgbox, %Code%

  IfInString, e, %Code%
    Continue

  Pwb.Document.getElementsByName("claimCode")[0].value := Code
  Pwb.Document.getElementsByName("applytoaccount")[0].click()
  IELoad(Pwb)
  Sleep, 1000

  filedelete, html.txt
  html := Pwb.Document.DocumentElement.innerHTML
  fileappend, %html%, html.txt
  IfNotInString, html, gift card has been applied to your account
  {
    Msgbox, 64, Amazon Enterer, Failed to enter the code...

    Pwb.Navigate("https://www.amazon.com/gp/gc/payment")
    IELoad(Pwb)

    Continue
  }

  FileAppend, %Code%`r`n, EnteredCodes.txt

  Pwb.Navigate("https://www.amazon.com/gp/css/gc/payment/view-gc-balance?ie=UTF8&ref_=gc_lp_wl3_atya_red_new2")
  IELoad(Pwb)

  Sleep, 1000
}

Return

;=============================

IELoad(Pwb)    ;You need to send the IE handle to the function unless you define it as global.
{
    If !Pwb    ;If Pwb is not a valid pointer then quit
        Return False
    Loop    ;Otherwise sleep for .1 seconds untill the page starts loading
        Sleep,100
    Until (Pwb.busy)
    Loop    ;Once it starts loading wait until completes
        Sleep,100
    Until (!Pwb.busy)
    Loop    ;optional check to wait for the page to completely load
        Sleep,100
    Until (Pwb.Document.Readystate = "Complete")
Return True
}

0 comments:

Post a Comment