[PYTHON] Extract the product name and price from the product list in the Yodobashi.com purchase statement email.

As the title suggests, I wrote a program in Python to get the combination of product name and price from the purchase details email of Yodobashi.com. I hope you can think of how to use the clipboard history tool and examples of using Python modules, PyPerclip and zip functions.

If you don't need an explanation, please click here.

Motivation etc.

I use Zaim to create a household account book. In addition to taking a receipt and registering details, it is convenient because you can automatically register purchase information on some sites such as Amazon.

However, this Zaim, unfortunately, does not support cooperation with Yodobashi.com. For this reason, I, who make heavy use of Yodobashi.com, struggled every time to register my shopping history.

Therefore, I decided to read the product details written in the "Yodobashi.com: Thank you for your order" email that you received when you purchased the product at Yodobashi.com and extract the product name and price with Python. ..

[Ordered items]
---------------------------------------------------------------
・ "[Product name(With line breaks)]」

Desired delivery date:[Date and time]

total[Quantity]point[price]Circle

・ "[Product name(With line breaks)]」

Desired delivery date:[Date and time]

total[Quantity]point[price]Circle
・ ・ ・

・ Delivery fee: 0 yen

Implementation policy for the time being

It is convenient to use the stack clipboard function of the clipboard history tool.

The stack clipboard function is a function that many clipboard history tools such as Clipboard-History have, and it is a function to paste the text stored in the stack in order by copy operation.

Of course, this is convenient when used alone, but it is quite convenient when used in combination with a script. For this reason, we use it to store goods and prices on the clipboard stack.

Implementation example

For the time being, like this. Create a list of product names and price names with regular expressions, combine them with the zip function, and transfer them to the clipboard. Before running the script, you need to do the following:

import re
import pyperclip
import sys
n = []
p = []
text = pyperclip.paste()
for m in re.finditer(r"「([^」]*)」", text, re.MULTILINE):
  n.append(re.sub("\\n\\s*", "", m[1]))
for m in re.finditer("([\\d,]+)\\s*Circle", text, re.MULTILINE):
  p.append(re.sub("\\n\\s*", "", m[1]))
ret = ""
for a, r in zip(n, p):
  pyperclip.copy(a)
  pyperclip.copy(r)

Use the pyperclip module to access the clipboard from a Python script. Install it in advance with pip install pyperclip.

When you run it, the names and prices of the items you bought will be copied alternately to the clipboard stack, and you can paste them into Zaim's spending form one by one.

Programming is convenient even for non-professionals

Programming can be used in fields that are not related to work. Simplify or automate routine work. Even when using automatic processing services such as IFTTT, the range of things that can be done by those who have a sense of programming knowledge will expand.

So, I would like to say that it is plausible that people who are not in the main job or who do not plan to do such things at work may be able to do it without loss.

Well, hopefully there is an environment like a launcher where you can easily create such scripts and execute them easily.

Recommended Posts

Extract the product name and price from the product list in the Yodobashi.com purchase statement email.
Extract and list personal names and place names in the text
From the AWS cloud product page, put the AWS service name in csv
Change the list in a for statement
Extract every n elements from an array (list) in Python and Ruby
Extract only the file name excluding the directory in the directory
I compared the speed of the reference of the python in list and the reference of the dictionary comprehension made from the in list.
Extract each Location from Stargazers in the Github repository
Read the function name from the DB and execute it dynamically
Sort and output the elements in the list as elements and multiples in Python.
Predict gender from name using Gender API and Pykakasi in Python
Get product name and lowest price using Amazon Product Advertising API
Extract the value closest to a value from a Python list element