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.
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
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.
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 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