Amazon Hacks Free Open Book

Amazon Hacks

Previous Section Next Section

Hack 25 Create Several Birthday Reminders at Once

figs/beginner.giffigs/hack25.gif

You probably have dozens of birthdays to track. You can speed up the process of adding Amazon event reminders with a script.

If you have an entire address book of people's birthdays that you'd like to receive reminders about, it could be a long process to enter them one by one into Amazon's event reminder form. Instead, you can speed up the process considerably with some scripting.

This ASP page accepts a text list of names and birth dates and enters them all as Amazon events. This script runs on Windows servers running IIS.

25.1 The Code

As with other services that require you to be logged in, the event reminder service requires an Amazon session ID that is tied to your account. This script first logs in as you via SSL and sets the session ID. Then it loops through the birthdays, calling the AddEvent subroutine, which sends a form post to Amazon with the event information.

<%
' add_reminders.asp
' Turns a supplied list of names and birthdates into Amazon events
' Usage: An ASP page called from any web browser

Const YOUR_EMAIL = "insert email address"
Const AMZN_PASSWORD = "insert Amazon password"
Const WinHttpRequestOption_EnableRedirects = 6

Sub AddEvent(sid,name,e_month,e_day)
    strURL = "https://www.amazon.com/exec/obidos/reminder-edit-done/" 
    strURL = strURL & strSessionID
    strPostData = "reminder-id=" & _
                  "&reminder-frequency=on" & _
                  "&sort-by=reminder-date" & _
                  "&customer-email=" & YOUR_EMAIL & _
                  "&occasion-id=3" & _
                  "&smart-send-options-enabled=yes" & _
                  "&time-zone-name=US/Pacific" & _
                  "&7-days-before=no" & _
                  "&recipient-customer-id=" & _
                  "&recipient-name=" & name & _
                  "&recipient-lower-email=" & _
                  "&gift-recipient-customer-id=" & _
                  "&gift-recipient-age-range=00-00" & _
                  "&gift-recipient-gender=" & _
                  "&month=" & e_month & _
                  "&day-of-month=" & e_day & _
                  "&14-days-before=on" & _
                  "&0-days-before=no" & _
                  "&1-days-before=no" & _
                  "&interest1=" & _
                  "&30-days-before=no" & _
                  "&x=63" & _
                  "&y=7"
    
    Set httppost = Server.CreateObject("Msxml2.SERVERXMLHTTP")
    httppost.Open "POST", strURL, false
    httppost.setRequestHeader "Content-Type",[RETURN]
        "application/x-www-form-urlencoded"
    httppost.Send(strPostData)
    If Err.Number <> 0 Then
        'WScript.Echo httppost.Error
    End If    
    strText = httppost.ResponseText
    strHeaders = httppost.GetAllResponseHeaders
    strStatus = httppost.status
    Set httppost = Nothing
End Sub

If Request("txaBirthdays") <> "" Then
    'Start an Amazon Session
    strURL = "https://www.amazon.com/exec/obidos/flex-sign-in-done/"
    strPostData = "email=" & YOUR_EMAIL & _
                  "&password=" & AMZN_PASSWORD & _
                  "&method=get" & _
                  "&opt=an" & _
                  "&cont-page=cm/reminders-signed-in-continue" & _
                  "&cont-type=add-reminder" & _
                  "&response=reminder-add" & _
                  "&response=" & _
                  "stores/gifts/gifts-sign-in-secure.html" & _
                  "&action=sign-in" & _
                  "&next-page=" & _
                  "stores/gifts/gifts-register-secure.html"
    
    Set httppost = Server.CreateObject("WinHttp.WinHttpRequest.5")
    httppost.Open "POST", strURL, false
    'Turn off redirects
    httppost.Option(WinHttpRequestOption_EnableRedirects) = False
    httppost.setRequestHeader "Content-Type", [RETURN]
"application/x-www-form-urlencoded"
    httppost.setRequestHeader "User-Agent", [RETURN]
"(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)"
    httppost.setRequestHeader "Accept", [RETURN]
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"
    httppost.Send strPostData
    If Err.Number <> 0 Then
        response.write httppost.Error
    End If    
    strHeaders = httppost.GetAllResponseHeaders
    strStatus = httppost.status
    'response.write "<xmp>" & strStatus & Chr(13) & strHeaders & "</xmp>"
    
    Set objRegExpr = New regexp
    objRegExpr.Pattern = "session-id=(.*?);"
    objRegExpr.Global = True
    objRegExpr.IgnoreCase = True
    Set objMatches = objRegExpr.Execute(strHeaders)
    If objMatches.Count = 0 Then
        response.write "Amazon session couldn't be started."
        response.end
    Else
        For Each objMatch In objMatches
            strSessionID = objMatch.SubMatches(0)
        Next
    End If
    Set objMatches = Nothing
    Set objRegExpr = Nothing
    Set httppost = Nothing
    
    'Loop through the Birthdays
    cntEvent = 0
    arBDays = Split(Request("txaBirthdays"),Chr(13))
    For x = 0 To UBound(arBDays)
        arNameDate = Split(arBDays(x),",")
        strName = arNameDate(0)
        strDate = arNameDate(1)
        arMonthDay = Split(strDate,"/")
        strMonth = arMonthDay(0)
        strDay = arMonthDay(1)
        AddEvent strSessionID, strName, strMonth, strDay
        cntEvent = cntEvent + 1
    Next
    response.write cntEvent & [RETURN]
" events added! Check your email for confirmation."
Else
%>
<html>
<head>
    <title>Add Event Reminders</title>
</head>

<body>
Add a list of birthdays below, one on each line:<br>
Format: [Name], [Birthday mm/dd]
<br>
<form action="add_reminders.asp" method="post">
    <textarea cols="35" rows="6" name="txaBirthdays"></textarea>
<br><input type="submit" value="Add Items">
</form>
</body>
</html>
<% End If %>

25.2 Running the Hack

Add the code to an ASP file, add_reminders.asp. Upload the file to your server and point your browser at it:

http://your.server/add_reminders.asp

Because your Amazon password is stored in the file, make sure that you're the only one with access to the source code.

You'll see the simple HTML form waiting for birthdays. Add a list of names and dates separated by carriage returns. If you happen to store your birthdays in a spreadsheet or other electronic format, it should be fairly easy to export them in this format. Click "Add Items," and the script should let you know how many events were added at Amazon. Log in and check your events list [Hack #24] to verify that the script worked.

25.3 Hacking the Hack

To understand the form variables that are sent in the AddEvent subroutine, view the source HTML of Amazon's event reminder [Hack #24] form and take a look at the form fields and their values. By playing with values set in strPostData, you could easily turn this script into an anniversary reminder, or change the notification time of the reminders from the default 14 days to any other available value.

    Previous Section Next Section
    Index: [SYMBOL][A][B][C][D][E][F][G][H][I][J][L][M][N][O][P][Q][R][S][T][U][V][W][X][Z]


         Main Menu
    Main Page
    Table of content
    Copyright
    Credits
    Foreword
    Preface
    Chapter 1. Browsing and Searching
    Chapter 2. Controlling Your Information
    2.1 Hacks #13-26
    Hack 13 Understand Identity at Amazon
    Hack 14 Fine-Tune Your Recommendations
    Hack 15 Enable 1-Click Buying
    Hack 16 Set Up a Group Account
    Hack 17 Create an 'About You' Area
    Hack 18 Create a Wish List
    Hack 19 Add Items to a Wish List Remotely
    Hack 20 Add Multiple Items to a Wish List at Once
    Hack 21 Organize Your Wish List by Priority
    Hack 22 Set Email and Messages Preferences
    Hack 23 Get Movie Showtimes
    Hack 24 Create an Amazon Event Reminder
    Hack 25 Create Several Birthday Reminders at Once
    Hack 26 Best Practices for Your Amazon Account
    Chapter 3. Participating in the Amazon Community
    Chapter 4. Selling Through Amazon
    Chapter 5. Associates Program
    Chapter 6. Amazon Web Services
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele