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) -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)
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.
Using BeautifulSoup
With the release of version 1.6 the script will use BeautifulSoup if available. BeautifulSoup is a Python HTML/XML parser that greatly simplifies screen-scraping web pages. BeautifulSoup is not required to use the AppDailySales script. However, if used then there is a less likely chance the AppDailySales script will break if and when Apple decides to change the layout of the web page.
Change History
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
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.
Other Useful Projects
For more useful projects visit the OtherUsefulProjects wiki page.