gbrodman / order-tracking

Automated Amazon and Best Buy order tracking for buying groups
GNU Affero General Public License v3.0
33 stars 13 forks source link

Order Tracking

This is a set of Python scripts meant for streamlining and automating the process of reconciling one's orders with buying groups. In a basic sense, it automates the retrieval of tracking information, upload to buying groups' sites, and order reconciliation after reimbursement. The main purposes of these scripts is so that one can look at a single Google Sheet and immediately know what orders have been properly tracked and reimbursed by the buying groups, and to give the user the tools to fix any issues that may arise.

What This Does

There are two main tasks. They are:

get_order_tracking.py:

This script does the following:

If it cannot parse an email for some reason, it will mark the email as unread so that you can look at it manually later. This sometimes happens if Amazon is being slow -- in these cases, there is no harm in running the script again.

reconcile.py

This is the script for reconciliation. It does the following:

Limitations

Prerequisites

Instructions

If you are on Windows, use this guide instead of these instructions, as Windows is a bit difficult and this guide is clear.

If you are on a Mac (OSX):

Open up a terminal and run the following commands. These install Homebrew (a package manager), then they use Homebrew to install Git+Python, download the project, then set up the Python environment.

cd ~
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install pyenv
brew install git
git clone https://github.com/gbrodman/order-tracking.git
cd order-tracking
pyenv install 3.7.4
pyenv global 3.7.4
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
source ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
pip install -r requirements.txt

In all operating systems:

Configuration

Here are details of the fields on config.yml:

Sheets / Drive Configuration and Permissions

We need to create and use an automated Google Cloud account to write to Drive and to Sheets. Here's how we do that:

That should be it -- the "creds.json" file will give the scripts the ability to run as the service account, and we've given the service account permissions to the things it needs to write to.

Arguments

Sheets Output

The reconciliation task has output that consists of two tabs in the Google Sheet that we configured earlier. The tabs are:

Reconciliation

This is the main spreadsheet. Because a single tracking number can consist of multiple orders and a single order can contain multiple tracking numbers, we group them into orders based on how the shipments were divided up. The columns are:

Trackings

Each row on this sheet corresponds to a tracking number. It contains order(s) for that tracking and other information about it, including the reimbursed amount if we could find one. This tab is most useful in figuring out exactly where a problem occurred, if a group has mis-scanned some item.

Amazon Report Import

First, export an Amazon business shipments report as CSV (through the Business Analytics section of the site). Then, upload that CSV file to Google Drive and open it as a Sheets file. Note the sheet ID, which can be retrieved from the sheet URL the same way as before, i.e. "https://docs.google.com/spreadsheets/d/SHEET_ID". Also note the tab name.

Then, run python import_report.py. It will ask you for the aforementioned sheet ID and tab name -- put them in. It will print out information about the trackings it is importing, and it will also print any rows for which it could not find a valid group (note: the address is not formatted like "City, STATE" so for this section I recommend using the beginnings of addresses as your group keys, e.g. '123 Fake St' (without the quotes) in your group config).

Manual Order Import

Sometimes, one may wish to manually add a tracking object to the datastore. To do so, run the manual_input.py script. If you run it without arguments, it will ask you for a series of inputs (it also allows you to delete existing tracking objects). Most arguments are optional and it will try to fill out sane defaults, but the tracking number, order number, and group fields are required.

If you wish to run the input all in one step adding a new tracking object in the simplest form, simply run as one command:

python manual_input.py -a -t TRACKING_NUMBER -g GROUP -o ORDER_NUMBER

e.g.

python manual_input.py -a -t TBA1234567890 -g mysbuyinggroup -o 123-1234567-1234567

Donations

This software is completely free, licensed under the GNU Affero General Public License. However, if you feel like you wish to donate some money to me, feel free to send any amount of money through Paypal to https://paypal.me/GustavBrodman