Spring Festival, Winter Break

Translated from Simplified Chinese by AI.Read the original

Automating the bargain hunting!

The Wallace around here has big spend-and-save discounts from time to time, like this:

wallace-discount.jpg

Spend 100, get 80 off!

Even though it doesn't taste great, spend 100 get 80 off is just impossible to resist—so tempting!

But when these discounts show up is unpredictable. To grab capitalism's wool in time, I had the idea to write a program to monitor it automatically.

Every store on Meituan Waimai has a POI page with the discount info on it. I originally thought I could just download the page and regex-match it, but the content loads asynchronously.. Later I tried to find the API that gets the discount info, and I didn't expect Meituan's anti-scraping measures to be so extensive. Requests to the API have to carry a token, and the numbers in the API response are obfuscated with fonts, with a different font each time..

With the mindset of never complicating simple problems (I just want to catch a bargain, why is it so hard (ノ` Д´)ノ彡 ┻━┻), I decided to screenshot the page with puppeteer and then call Tencent Cloud's OCR API to recognize the discount text.

To avoid forgetting (or not having the money) to renew the server, I put the program on Tencent Cloud's Cloud Functions. Thanks to Cloud Functions' random outbound IPs, I don't have to worry about getting IP-banned.

There was a little hiccup while messing with Cloud Functions: Cloud Functions in the Guangzhou region couldn't bind a cloud disk (because I needed persistent storage for the discount info to compare against). I opened a ticket and asked; they said it was because they were short on HAVIP quota (I don't understand it either), and later it was resolved internally. Strange—such a usage-affecting issue wasn't discovered in time; it felt like "I'm the only one binding a cloud disk to Cloud Functions"..

Then I had to solve the message push problem. I originally wanted to use "Server 酱" for notifications, but WeChat's push is really lousy, so I had to find another way.

Later I found DingTalk is a pretty good choice—it has Webhook bots available, and message push is timely enough, so the final effect looks like this:

discount-bot.jpg

Finally I set up the scheduled trigger, and that's it.


Miscellany

  • Got a little money out of Uncle Chen's pocket (read: won an early-bird deal, final payment -200)
  • ‌ HiWiFi has completely gone under. Recently I found the cloud plugin center was inaccessible, so I flashed the router with Padavan. The 5Ghz wireless rate that used to cap at 200Mbps can now reach 500Mbps—awesome (
  • The red maple I planted in a pot at the beginning of the month has sprouted
  • Went to the cinema to see a movie for the first time since the second half of 2019
  • The Meizu DAC cable has really poor interference resistance, so I got a Sonata HD Pro. If the chip part is farther from the phone, it should be less affected (the Meizu cable sits right against the phone, and there's noise when using mobile data)

Spring Festival

I always feel the New Year atmosphere gets weaker every year.. Fortunately, you can still buy fireworks back in my hometown

2021-fireworks.jpg

I'll secretly set off just a few—no one should notice, right?


Gallery

shenshanhanxiao.jpg

Mountain magnolia

misty-bamboo.jpg

Worshipping ancestors in the countryside

lantern-in-fog.jpg

Lantern in the fog (what kind of cropping is this, WordPress)


Finally

School starts soon (2/28), so I have to rush my homework again..