Git Product home page Git Product logo

appdailysales's Introduction

This Script has Retired

As of now the script works with iTunes Connect. However, Apple can and will make changes that will cause the script to break. I can no longer maintain this script due to other commitments. However, the script remains in good working order thanks to fixes provided by others. The script will continue to work as long as others are able and willing to provide pull requests with fixes.

Here are some suggested alternatives for those looking for a more "guaranteed to work" option:

So Long, and Thanks for all the Fish

I originally wrote the script in the Fall of 2008. I needed an automated way to download daily sales reports from iTC. Over the years I have maintained the script to ensure it works with each unexpected change made to the iTC website. However, I stopped using the script a while ago, and I simply don't have the time to continue maintaining it. It's been a good run, but it's time to retire this puppy.

Thanks to the users, and bigger thanks to those who have contributed to the script over the years.

Introduction

AppDailySales is a Python script that will download daily sales report files from the iTunes Connect web site.

How to Use

AppDailySales can be used as a stand-alone program or as part of another script.

Use as Stand-alone Program

Download the script appdailysales.py and run the command line:

python appdailysales.py

usage: appdailysales.py [options]
Options and arguments:
-h     : print this help message and exit (also --help)
-a uid : your apple id (also --appleId)
-p pwd : your password (also --password)
-P     : read the password from stdin (also --passwordStdin)
-o dir : directory where download file is stored, default is the current working directory (also --outputDirectory)
-v     : verbose output, default is off (also --verbose)
-u     : unzip download file, default is off (also --unzip)
-d num : number of days to download, default is 1 (also --days)
-D mm/dd/yyyy : report date to download, -d option is ignored when -D is used (also --date)
-f format : output file name format (see strftime; also --format)
-n      : used with -f, skips downloading of report files that already exist (also --noOverWriteFiles)
--proxy : URL of the proxy
--debug : debug output, default is off

You can also change the option variables located towards the top of the script file if you prefer to not use the command line options. However, this approach is not recommended with version 1.2 and greater of the script file.

Note: The script will return the exit code 0 if successful, otherwise exit code 1 is returned.

Use as Part of Another Script

As of Version 1.3 the AppDailySales script can be used as part of another script. Simply import appdailysales, set the report options, and call the downloadFile function. Here is a sample script file to help you get started:

#!/usr/bin/python

import sys
import traceback
import appdailysales

def main():
  options = appdailysales.ReportOptions()
  options.appleId = 'Your Apple Id'
  options.password = 'Your Password'
  options.outputDirectory = ''
  options.unzipFile = False
  options.verbose = False
  try:
    filename = appdailysales.downloadFile(options)
    print 'Report file downloaded: ', filename
  except:
    traceback.print_exc()

if __name__ == '__main__':
  main()

The function appdailysales.downloadFile will return the name of the last file downloaded. Be sure to include a try..except block around the call to gracefully handle any errors that might occur during the download.

Download Reports Multiple Days

As of version 1.6, there is a -d (also --days) option that is used to specify the number of days to download. The default is 1, which will download yesterday's report and keeps the script backwards compatible with the previous versions. Any value can be used for this option. However please note that as of now Apple only stores the last 7 days of daily sales reports. Using a value greater than 7 will result in a "report not available" error.

Why not add a check in the script to prevent values greater than 7? I decided not to include the check on the off chance Apple decides to provide access to reports older than 7 days.

Report File Name Formatting

Version 2.1 introduces the new -f (also --format) option. This option allows you to reformat the report file name. The format is specific as per strftime (see man page), e.g. "%Y-%m-%d-daily.txt.gz" would give you "2010-09-16-daily.txt.gz".

By default, the report file is compressed. When using the -f option, be sure to include the appropriate file name extension, e.g., ".gz". Use the -u option to have the script uncompress the file for you. The script will automatically strip the .gz extension if present.

What Version of Python

The script was written for and has been tested with Python version 2.5.x, 2.6.x, and 2.7.x. It is doubtful the script will work with Python 3.x without some tweaking.

Debugging the Script

Version 2.4 introduces the new --debug flag. This flag will display additional verbose output for debugging and troubleshooting the script. Also, when this flag is turned on and the script encounters a screen scraping error, a file named temp.html is created and stored in the output directory. This file contains the HTML downloaded in the last web request.

Change History

Version 2.9.3

  • Updated script to work with latest iTC changes (Thanks aaarrrggh).

Version 2.9.2

  • Updated script to work with latest iTC changes.

Version 2.9

  • Automatically creates nested directories added to format (-f) strings (eg. -f %Y/%Y-%m/Daily-%Y-%m-%d.txt). Works with outputDirectory (-o). (Thanks Mike Kasprzak)
  • New command line option "-n". Used with format (-f), any file that already exists isn't downloaded. (Thanks Mike Kasprzak)
  • Added proxy support. (Thanks stakemura)

Version 2.8

Version 2.7

  • Modified the script to make multiple attempts at loading the vendor default page before reporting an error.
  • Changed how content-disposition is checked to avoid attempts of unzipping HTML.

Version 2.6

  • Updated the script to support the new URL to the Sales and Trends web site. (Thanks ferenc.vehmann)
  • Enabled RFC2965 cookie support. (Thanks troegenator)

Version 2.5

  • Updated to display notification messages, if any, from Apple displayed on the sales and trends dashboard. Must use the -v or --verbose flag to see the notification message.

Version 2.4

  • Updated to support the latest iTC web site changes.
  • Updated -v (--verbose) flag to display user friendlier messages.
  • Added --debug flag. Provides addition verbose output for debugging and troubleshooting.
  • Updated to scrape the vendor page and make the default vendor setting.
  • Updated to scrape for the list of available report dates.
  • Updated to download only available reports. A message is displayed when a requested report is not available.

Version 2.3

  • Update to screen scrape for the sales and trends URL.

Version 2.2

  • Replaced the "with" statement, which was causing problems on different platforms and with different version of python, with more compatible code.

Version 2.1

  • Adds new -f (also --format) option to reformat the report file name. (Thanks Daniel Dickison.)
  • Updated to display invalid login credential message if the login process fails. (Thanks Daniel Dickison.)
  • The -v (also --verbose) will save the last retrieved html to the file temp.html. This is helpful when troubling a problem with screen scraping the web site. The temp.html is automatically deleted when the script successfully downloads the report. (Thanks Daniel Dickison.)
  • The -P (also --passwordStdin) now displays the prompt "Password:"

Version 2.0.2

  • Removed invalid parameter used to focus an error and test new error reporting.

Version 2.0.1

  • Improved error reporting

Version 2.0

  • Updated to support September 9, 2010 iTunes Connect changes.
  • Dropped BeautifulSoup support. I don't have the time to support two separate screen scraping approaches.

Version 1.10

  • Fixed bugs caused by recent iTunes Connect changes.

Version 1.9

  • Applied patch that adds new option to read the password from the stdin (thanks Maarten Billemont).

Version 1.8.1

  • Modified code to work with latest iTunes Connect changes (thanks Andrew de los Reyes).

Version 1.8

  • Now uses os.path.join to avoid problems with trailing slash or the lack of when specifying the output directory (thanks Keith Simmons).

Version 1.7

  • Removed code that received available report dates from the HTML. This broke backwards compatibility when using BeautifulSoup and was misleading when Apple delayed "yesterday's" reports.
  • Added in -D (also --date) option that allows the download of a specific date. Note: date must be in mm/dd/yyyy format.

Version 1.6

  • Modified to use BeautifulSoup is available (thanks Rogue Amoeba Software, LLC)
  • Modified unzip logic to work in memory only, making it faster and less error prone (thanks Rogue Amoeba Software, LLC)
  • Added days to download option (-d or --days), can be used to download all available reports

Version 1.5

  • Updated script to work with latest web site changes
  • Removed trackback output when usage is displayed

Version 1.4

  • Modified to use itts.apple.com as the starting point; eliminates 2 HTTP calls (thanks to Leon Ho for providing the change)
  • Added error check for download file; prints 'report not available' message if detected

Version 1.3

  • Modified script to run as stand-alone program or as part of another script

Version 1.2

  • Added command line options (editing script file no longer needed)
  • Added option to unzip download file

Version 1.1

  • Initial release

Contributors

Special thanks goes out to the following individuals for contributing to this project:

  • Leon Ho
  • Rogue Amoeba Software, LLC
  • Keith Simmons
  • Andrew de los Reyes
  • Maarten Billemont
  • Daniel Dickison
  • Mike Kasprzak
  • Shintaro TAKEMURA
  • aaarrrggh (Paul)

Code License

MIT License

Some Final Words

I created this script with the iPhone developer in mind. Being an iPhone developer myself I don't want to remember to download the daily sales report from yesterday's activity so I wrote this script. I have a cron job scheduled on a server that will download each day's report for me so I don't have to. Ain't automation great.

appdailysales's People

Contributors

aaarrrggh avatar kirbyt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

appdailysales's Issues

Custom filename format results in error

When I try to use the script like this:

appdailysales.py -a USERNAME -p PASSWORD -d 7 -f "%Y-%m-%d.txt.gz" -u -n

It produces this bunch of error message:

Traceback (most recent call last):
  File "./kirbyt-appdailysales-eea5ce6/appdailysales.py", line 540, in <module>
    sys.exit(main())
  File "./kirbyt-appdailysales-eea5ce6/appdailysales.py", line 533, in main
    downloadFile(options)
  File "./kirbyt-appdailysales-eea5ce6/appdailysales.py", line 483, in downloadFile
    os.makedirs(fileDirectory)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 2] No such file or directory: ''

I don't speak Python much but as far as I can see the issue lies in the fact that in the following line (479 in the current version) fileDirectory becomes an empty string. This path does not exist, neither can it be created.

fileDirectory = os.path.dirname(filename)

I tried commenting out the directory check and it works fine. When I add -o "./" to the script call, it also works perfectly.

My guess is that it's just a missing "is empty" check on fileDirectory, but I may be wrong.

Not working anymore

the login page has changed, and unfortunatly the script is not working anymore since a few days. can you take a look ?

best regards,
Anthony

weekly report fetched instead of daily report

Interestingly, my daily call to appdailysales.py resulted in apple's weekly report being downloaded (starts with 'S_W' instead of 'S_D'). Nothing has changed in my cron job, so I'm assuming Apple is mucking with their HTML.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.