Display Matsuya coupon (QR code) with Pythonista for iOS

Introduction

Matsuya Do you like it? I love. Matsuya is a favorite of all such engineers, but smartphones official app and [on LINE](http://www. matsuyafoods.co.jp/line/) Did you know that coupons are being delivered?

You can use it by holding the QR code over the touch panel ticket vending machine [^ 1], but it is troublesome to start the application or LINE and display the QR code, and if the screen brightness is low, read it well. not. It is a well-known fact [^ 2] that people who spend 17 seconds or more to issue tickets at Matsuya are unavoidable, so ** display the latest QR code ** and ** screen brightness adjustment ** with one tap. I wrote a script for Pythonista for iOS that will do it with **.

Pythonista for iOS is a Python environment that runs on iOS, and even though python runs on iOS, it's dangerous, but you can also touch Objective-C objects from python, and so on. [^ 3]

[^ 1]: In the case of an old ticket vending machine, you can use it by presenting the coupon to the clerk. [^ 2]: Citation needed [^ 3]: This blog is detailed about dangerousness. Speaking of the appeal of the revolutionary manufacturing environment "Pythonista 3" that runs on iOS

How to use

script

First, save the following script in Pythonista. Pythonista comes with Python2 and Python3, but please run it on Python3. When executed, the latest QR code will be displayed after maximizing the screen brightness. Tap [Close] to restore the screen brightness.

Matsuya.py


import urllib.request
import re
import ui
from objc_util import *

def get_matsuya_qrcode_url_linecoupon():
	#LINE Coupon Example
	# http://www.matsuyafoods.co.jp/line/
	# http://www.matsuyafoods.co.jp/sp/line_cp/161115/
	#   http://www.matsuyafoods.co.jp/sp/line_cp/161115/qr_line.png
	
	line_url = 'http://www.matsuyafoods.co.jp/line/'
	with urllib.request.urlopen(line_url) as res:
		html = res.read()
	
	qr_date = re.findall(r"/line/images/cp_(\d{6}).jpg ", html.decode('utf-8'))[0]
	qr_url = 'http://www.matsuyafoods.co.jp/sp/line_cp/%s/qr_line.png' % qr_date
	
	return(qr_url)

def get_matsuya_qrcode_url_mobilecoupon():
	#Matsuya Mobile Coupon Example
	# http://www.matsuyafoods.co.jp/sp/coupon.html
	#   http://www.matsuyafoods.co.jp/coupon/161115/qr_sp.png
	
	#Matsuya Mobile Coupon Mobile Site Example
	# http://www.matsuyafoods.co.jp/mobile/coupon/
	#   http://www.matsuyafoods.co.jp/mobile/coupon/161115/qr_fp.png
	
	mobile_url = 'http://www.matsuyafoods.co.jp/sp/coupon.html'
	with urllib.request.urlopen(mobile_url) as res:
		html = res.read()
	
	qr_date = re.findall(r"/coupon/(\d{6})/qr_sp.png ", html.decode('utf-8'))[0]
	qr_url = 'http://www.matsuyafoods.co.jp/coupon/%s/qr_sp.png' % qr_date
	
	return(qr_url)


def get_matsuya_qrcode_image(url):
	qr_image, headers = urllib.request.urlretrieve(url)
	return(qr_image)

def show_view(qr_image):
	UIScreen = ObjCClass('UIScreen')
	screen = UIScreen.mainScreen()
	prev_brightness = screen.brightness()
	screen.setBrightness(1.0)

	view = ui.View()
	view.name = 'I want to be everyone's dining table.'
	view.background_color = 'white'

	image = ui.Image.named(qr_image)

	imageView = ui.ImageView()
	imageView.image = image
	imageView.flex = 'WH'
	imageView.content_mode = ui.CONTENT_SCALE_ASPECT_FIT

	def button_tapped(sender):
		screen.setBrightness(prev_brightness)
		view.close()

	button = ui.Button(title='[close]')
	button.flex = 'TRL'
	button.center = (view.width * 0.5, view.height * 0.5)
	button.action = button_tapped

	view.add_subview(imageView)
	view.add_subview(button)
	view.present(style='full_screen', hide_title_bar=True, orientations=('portrait',))


def main():
	#Shows Matsuya mobile coupons.
	url = get_matsuya_qrcode_url_mobilecoupon()
	#If you want to display the LINE coupon, comment out the next line
#	url = get_matsuya_qrcode_url_linecoupon()

	qr_image = get_matsuya_qrcode_image(url)
	show_view(qr_image)



main()

Execution screen

写真 2016-12-14 20 45 52.png

Place a shortcut on the home screen

Place a link on your iPhone's home screen to launch the above script with a single tap.

  1. Open the script in Pythonista and select "Home Screen" from the wrench icon in the upper right. 写真 2016-12-14 20 19 06.png

  2. The setting screen will be displayed. Check "Run Script" and make various settings [^ 4]. 写真 2016-12-14 20 20 19.png

  3. Tap Continue and follow the onscreen instructions to set the Matsuya icon on your home screen. 写真 2016-12-14 20 24 56.png

[^ 4]: Matsuya color is Icon Color: 014099 </ font>, Background Color: FCC929 </ font>.

in conclusion

What do you think. It's a crude script, but I think Pythonista, which allows you to easily create something for this purpose, is dangerous. Then everyone has a good Matsuya life!

Recommended Posts