基於台灣相關法令, 台灣 Uber 在每趟租車服務後,都會寄出兩份 email 收據,一封主要收據,另外一封是租車資訊。 這 python 程式可將 Gmail 帳號內的收據讀取出來,取出租車資訊,並且將對應的兩封收據信合併存成一份 pdf 檔案。 非常適合公司報帳用 XD。
This program is designed for processing receipts sent by Uber Taiwan, the text processing only works with Taiwanese language. Uber Taiwan sends out two emails after each ride, which is required by Taiwanese law. One is the main receipt and the other contains car rental informations. This python program collects Uber receipts from Gmail acccount, parses infomation, and combines ("staples") the two matching emails (of each ride) into one pdf file. Great for applying travel reimbursements :).
Make sure follow instructions below:
Install wkhtmltopdf, for macOS,
brew install caskroom/cask/wkhtmltopdf
Other OS, see https://wkhtmltopdf.org/
Install dependencies
pip install -r requirement.txt
To enable Gmail API:
- Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. Click Continue, then Go to credentials.
- On the Add credentials to your project page, click the Cancel button.
- At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.
- Select the Credentials tab, click the Create credentials button and select OAuth client ID.
- Select the application type Other, enter the name "Gmail API Quickstart", and click the Create button.
- Click OK to dismiss the resulting dialog.
- Click the download icon (Download JSON) button to the right of the client ID.
- Move this file to your working directory and rename it client_secret.json.
or Read Step 1 in https://developers.google.com/gmail/api/quickstart/python
Place client_secret.json under this folder.
Fill this variable at uberSlipStapler.py file
GMAIL_USER_ID = None
with your own gmail address.
OR
Create settings.py file, with GMAIL_USER_ID = <your gmail address>.
python uberSlipStapler.py
First time running this program will ask you to login with google account,
Search for uber slip in 2018/6
/Library/Python/2.7/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access credentials.json: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.readonly&redirect_ur........
Enter verification code:
follow the instructions .
For more options:
usage: uberSlipStapler.py [-h] [-m MONTH] [-y YEAR]
optional arguments:
-h, --help show this help message and exit
-m MONTH, --month MONTH
month to search in number, Jan=1, default: current
month
-y YEAR, --year YEAR year to search, default: current year