SHOW:
|
|
- or go back to the newest paste.
| 1 | def get_kindle_sales(cs_user,cs_pass) | |
| 2 | session = Mechanize.new | |
| 3 | session.user_agent_alias = 'Mac Safari' | |
| 4 | session.get 'https://www.amazon.com/ap/signin?openid.assoc_handle=amzn_dtp&openid.identity=' #...etc. | |
| 5 | form = session.get('https://www.amazon.com/ap/signin?openid.assoc_handle=amzn_dtp&openid.=' + # ...etc.
| |
| 6 | '...').form_with(:name => 'signIn') | |
| 7 | - | params = {'email' => cs_user, 'password' => cs_pass}
|
| 7 | + | params = {'email' => cs_user, 'password' => cs_pass}
|
| 8 | - | %w(appActionToken appAction openid.pape.max_auth_age openid.ns).each do |field| # there's more, actually |
| 8 | + | %w(appActionToken appAction openid.pape.max_auth_age openid.ns).each do |field| # there's more, actually |
| 9 | - | params[field] = form[field] |
| 9 | + | params[field] = form[field] |
| 10 | - | end |
| 10 | + | end |
| 11 | - | session.post('https://www.amazon.com/ap/signin', params)
|
| 11 | + | session.post('https://www.amazon.com/ap/signin', params)
|
| 12 | - | response = session.get('https://kdp.amazon.com/self-publishing/reports/transactionReport?_=1326589411161&previousMonthReports=false&marketplaceID=ATVPDKIKX0DER')
|
| 12 | + | response = session.get('https://kdp.amazon.com/self-publishing/reports/transactionReport?_=1326589411161&previousMonthReports=false&marketplaceID=ATVPDKIKX0DER')
|
| 13 | - | # note non-RESTful concept of "previousMonthReports" in URI |
| 13 | + | # note non-RESTful concept of "previousMonthReports" in URI |
| 14 | - | hash = JSON.parse(response.body) |
| 14 | + | hash = JSON.parse(response.body) |
| 15 | - | kindle_units = hash['aaData'][0][5] |
| 15 | + | kindle_units = hash['aaData'][0][5] |
| 16 | end |