authorsight-export
v0.0.2
Published
A CLI utility that allows you to export books sales data from Packt AuthorSight for your own historic backup and analysis
Maintainers
Readme
authorsight-export 📦
A CLI tool to fetch and export book sales and revenue data from the Packt AuthorSight portal in Hive-compatible format.
Rationale 💡
Hi there, fellow Packt author! 👋
Chances are, if you’ve landed here, you’re looking for a way to make better use of the data in the AuthorSight portal. Same here!
I’m Luciano Mammino, a software engineer and co-author of Node.js Design Patterns. (Shameless plug, but it might be useful if you're looking to improve your Node.js game!)
As authors, we get access to Packt AuthorSight: a handy dashboard with our sales and royalty data, but sometimes you just want that information in a more flexible format. Maybe you want to run your own analysis, generate custom reports, integrate it with other tools, or just keep a tidy archive.
That’s exactly why I built this little tool. If you're looking to export your Packt sales data quickly and cleanly, you're in the right place.
Hope it helps and happy hacking! 🚀
Features ✨
- Fetch Kindle and Print sales data (Amazon, Direct, Other)
- Supports multiple data types:
amazon_units_dailydirect_units_dailyrevenue_monthlyrevenue_quarterlyrevenue_annual
- Exports data in a directory structure by book and year (hive-compatible for supporting tools like Apache Hive, DuckDB, AWS Athena, etc.)
- Progress bars, retry and robust error handling
Installation 🛠️
You can use this tool directly with npx (recommended):
npx authorsight-export --session <cookie> [options]Or, install globally:
npm install -g authorsight-exportOr, clone the repository and install dependencies:
git clone https://github.com/yourusername/authorsight-export.git
cd authorsight-export
npm installUsage 🚀
With npx (recommended)
export AUTHORSIGHT_SESSION=<cookie>[!IMPORTANT]
Make sure to replace<cookie>with your actual Packtauthorsight_sessionand that the value is URL-decoded (e.g., no%20for spaces). You can find this cookie in your browser's developer tools under the "Application" tab after logging in on the Packt AuthorSight portal.
Then run:
npx authorsight-export [options][!CAUTION]
You can also pass your session cookie inline using the--sessionoption. This is discouraged, and it is instead recommended setting your session cookie using theAUTHORSIGHT_SESSIONenvironment variable. This is more secure and avoids leaking sensitive information in shell history.
Options ⚙️
-s, --session <cookie>: Packtauthorsight_sessioncookie (discouraged; use theAUTHORSIGHT_SESSIONenvironment variable instead)-o, --output <directory>: Output directory (default:.)-b, --books <bookIds>: Comma-separated list of book IDs (default: all books)-t, --types <types>: Comma-separated list of data types to fetch (default: all)-V, --version: Show CLI version-h, --help: Show help message
Example 💡
AUTHORSIGHT_SESSION=YOUR_SESSION_COOKIE npx authorsight-export -b B05259,C09167 -t revenue_monthly,revenue_annual -o ./outputData Types 📊
| Type | Endpoint | Description | | ------------------ | ------------ | ------------------ | | amazon_units_daily | amazon-daily | Daily Amazon units | | direct_units_daily | direct-daily | Daily Direct units | | revenue_monthly | monthly | Monthly revenue | | revenue_quarterly | quarterly | Quarterly revenue | | revenue_annual | annual | Annual revenue |
DuckDB query example 🦆
Just to provide an example of how you can query the exported data using DuckDB, the following SQL query sums the total print and digital units across all books and data types (amazon and direct):
SELECT SUM(print_units + digital_units) FROM (
SELECT book, date, month, year, print_units, kindle_units AS digital_units FROM read_csv('amazon_units_daily/**/*.csv')
UNION
SELECT book, date, month, year, print_units, digital_units FROM read_csv('direct_units_daily/**/*.csv')
)Contributing 🤝
Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub. PRs are also very welcome.
License 📄
Licensed under MIT License. © Luciano Mammino.
