Parsing Uber bills

It’s the time of the year I have to generate expense reports and I need three details for the invoices. First the invoice number, second the invoice date and the third gross amount paid.

Now the Uber invoice is pdf as shown in figure below:2017-07-27 12_44_30-Clipboard

As opening PDF files and getting data from it manually was kind of painful, so I wrote a python script for my help. Here it is:

import PyPDF2
import os

dirPath = 'C:/path_to_directory_containing_invoices/'
fileList = os.listdir()

for fileName in fileList:

    f = open(dirPath+fileName, 'rb')
    reader = PyPDF2.PdfFileReader(f)
    contents = reader.getPage(0).extractText().split('\n')
    invoice_number = ""
    invoice_date = ""
    gross_amount = ""

    for i in range(len(contents)):
        if contents[i].find("Invoice Number") != -1:
            invoice_number = contents[i].split(': ')[1]
        if contents[i].find("Invoice Date") != -1:
            invoice_date = contents[i].split(': ')[1]
        if contents[i].find("Gross Amount") != -1:
            gross_amount = contents[i+1].split(' ')[0]

    print(invoice_number + ", " + invoice_date + ", " + gross_amount)

It uses PyPDF library. This link tells you how to install it and use it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s