f11: Pythonista で ベル打ち メール送信


.

---
### **[ おまとめ ]**

※メール本文で、ベル打ち (2 touch) 変換を行いメール送信します

※ベル打ち は、かなカナ英数字、一部記号対応です
　漢字非対応 ( IME候補変換的な機能無し ) です

---
### **[ 1. 買い出し ]**

＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊
1. メール部

※メール送信部分の基本の仕組みは、以下同様です

　f5: Pythonista でメール送信
　https://qiita.com/cxfgp/items/4849a856be57646bcf34

※テキストアプリにて、ベル入力 or 通常入力
　-> open in (Run Pythonista Script) で、テキストファイルを読み込み、
　-> gmail + oauth -> メール送信

「テキストファイル」
　1行目：送信元メールアドレス
　2行目：送信先メールアドレス
　3行目：CC (カンマ区切り) 
　4行目：件名
　5行目以降：本文

　※FROM / TO / CC ( CC はカンマ区切り) は 短縮入力可能です

＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊
2. ベル部

_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
「テキストファイル例」

from1
mai
ccc:
Re: あなたと私
@2503046103618201413255
517114618268
.(259542048103(.044433

_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
「本文変換後」

From: from1@gmail.com
To: mai2020mai@gmail.com
CC: 
件名: Re: あなたと私

本文: 
こんばんは、わたしのなまえは、
コロチャンです

_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

※テキストファイル 5行目の[本文]先頭に 半角@ があれば ベル変換されます

ベル打ち と 通常入力 と混在は出来ませんが、
[本文]先頭の 半角@ がなければ、通常入力も出来ます

ベル入力における文中の改行は自由です
(改行は 68 で指定してます)

かなカナ変換などのスイッチキーを iphone IME 用にしてます
(. -> かな
.( -> カナ

濁点は、先に入力
04 21 -> が
05 61 -> ぱ

英小文字 は、かな側:　(. 16 -> a
英大文字 は、カナ側:　.( 16 -> A

以下はかなカナ共通で使用可能
67 = '?'
68 = '\n'
69 = 'ー'
70 = ' '
82 = '、'
84 = '。'

iphone IME の場合、半角固定にならない為、候補表示で、
数字 -> マークなどにされてしまいますが、
半角数字、または、スイッチキー記号のみに対応してます
(マークなどの変換候補を無視して、半角候補を選択する)

＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊


---
### **[ 2. キッチン ]**

gmail + google oauth

iphone SE / ios 13.2.3
iphone 8 / ios 12.3.1
iphone 11 / ios 13.3.1

Pythonista3 - v3.3

stash
$ pip list
oauth2client (4.1.3) - OAuth 2.0 client library
oauth2 (1.9.0.post1) - library for OAuth version 1.9
google-api-python-client (1.7.11) - Google API Client Library for Python
google-auth (1.11.0) - Google Authentication Library
google-auth-httplib2 (0.0.3) - Google Authentication Library: httplib2 transport


txt-open-mail-2.py - 本体
beput.py - ベル変換
※ beput.py は、txt-open-mail-2.py の同階層に設置しておく


---
### **[ 3. 調理 ]**

```txt-open-mail-2.py

# coding: utf-8

# txt-open-mail - gmail + oauth + 2 touch
vers = '1.1.0'

# ベル変換 スクリプト定義(beput.py)
import beput

import os
import appex
import shutil
import console

import sys
import datetime

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
from email.utils import formatdate

import base64
import imaplib
import json
import urllib.parse
import urllib.request

# =============================
# gmail oauth key - 送信アドレス1

ux10 = 'xxxx1.apps.googleusercontent.com'
ux11 = 'aaaa'
ux12 = '1//04cccc'

# =============================
# gmail oauth key - 送信アドレス2

ux20 = 'xxxx2.apps.googleusercontent.com'
ux21 = 'bbbb'
ux22 = '1//04dddd'

# =============================

# FROM 送信元 アドレス - BCC グループ 1
# from1
dk01 = 'from1@gmail.com'
# from2
dk05 = 'from2@gmail.com'

# TO 送信先アドレス マイちゃん - BCC グループ 2
kv07 = 'mai2020mai@gmail.com'

# TO 送信先アドレス ケンちゃん - BCC グループ 3
kv12 = 'ken2020ken@gmail.com'

# =============================
# oauth 認証 1

def refresh_authorization(dg1n, oix2, rtok):
	
	params = {}
	params['client_id'] = dg1n
	params['client_secret'] = oix2
	params['refresh_token'] = rtok
	params['grant_type'] = 'refresh_token'
	request_url = 'https://accounts.google.com/o/oauth2/token'
	raw_response = urllib.request.urlopen(request_url, urllib.parse.urlencode(params).encode('UTF-8')).read().decode('UTF-8')
	response = json.loads(raw_response)
	return response['access_token'], response['expires_in']

# =============================
# oauth 認証 2

def generate_oauth2_string(urnam, atok):
	
	auth_string = 'user=%s\1auth=Bearer %s\1\1' % (urnam, atok)
	auth_string = base64.b64encode(auth_string.encode('ascii')).decode('ascii')
	return auth_string

# =============================
# メール送信

def send_mals(FRM2, TOO2, CAD2, BCC2, TTL2, HBN2, LST2, FLC2):
	
	if FLC2 == 1:
		dg1n = ux10
		oix2 = ux11
		s3dp = ux12
	elif FLC2 == 2:
		dg1n = ux20
		oix2 = ux21
		s3dp = ux22
		
	atok, expires_in = refresh_authorization(dg1n, oix2, s3dp)
	auth_string = generate_oauth2_string(FRM2, atok)
	
	ENCOD = 'utf-8'
	
	msg = MIMEText(HBN2.encode(ENCOD), 'plain', _charset=ENCOD)
	msg['Subject'] = str(Header(TTL2, ENCOD))
	msg['From'] = FRM2
	msg['To'] = TOO2
	msg['Cc'] = CAD2
	msg['Date'] = formatdate()
	
	server = smtplib.SMTP('smtp.gmail.com:587')
	server.ehlo(dg1n)
	server.starttls()
	server.docmd('AUTH', 'XOAUTH2 ' + auth_string)
	server.sendmail(FRM2, LST2, msg.as_string())
	server.close()

# =============================
# 短縮名、フルアドレス変換
# (gh03 = 送信フラグ, gh04 = BCC グループフラグ)

def mal_addr(gh01, gh02, gh03):
	
	if gh01 == 'from1':
		gh02 = dk01
		gh03 = 1
		gh04 = 1
	elif gh01 == 'from2':
		gh02 = dk05
		gh03 = 1
		gh04 = 1
	# マイちゃんの短縮名: mai
	elif gh01 == 'mai':
		gh02 = kv07
		gh03 = 1
		gh04 = 2
	# ケンちゃんの短縮名: ken
	elif gh01 == 'ken':
		gh02 = kv12
		gh03 = 1
		gh04 = 3
	# マイちゃん ケンちゃん以外は フルメールアドレス代入
	else:
		gh02 = gh01
		gh03 = 2
		gh04 = 4
	return gh02, gh03, gh04

# =============================
# YES / NO 選択

def yes_no_input():
	
	while True:
	
		choice = input("'yes' or 'no' [y/n]: ").lower()
		
		if choice in ['y', 'ye', 'yes']:
			return True
		elif choice in ['n', 'no']:
			return False

# =============================
# テキストファイル コピー処理

# エディタアプリ xxxx.txt -> open in
# -> Run Pythonista Script -> 本スクリプト 呼び出し
# -> Pythonista3 - /Shared/xxxx.txt

def main0():
	
	FILE = appex.get_file_paths()
	PYPATH = os.path.abspath(os.path.dirname(__file__))
	
	while os.path.basename(PYPATH) != 'Documents':
		PYPATH = os.path.abspath(os.path.join(PYPATH, os.pardir))
	PYPATH = os.path.join(PYPATH, 'Shared')
	
	if not os.path.isdir(PYPATH):
		os.mkdir(PYPATH)
	
	for i in FILE:
		if os.path.isfile(i):
			NAME = os.path.basename(i)
			shutil.copyfile(i, os.path.join(PYPATH, NAME))
			global cpedf1
			cpedf1 = NAME
			# print(i+'->'+os.path.join(PYPATH, NAME))
		if os.path.isdir(i):
			shutil.copytree(i, PYPATH)

# =============================
# 処理メイン

if __name__ == '__main__':
	
	now1 = datetime.datetime.now()
	now2 = '{0:%Y/%m/%d %H:%M:%S}'.format(now1)
	
	cpedf1 = ''
	cpedf3 = ''

	# ファイルコピー処理呼び出し
	if appex.is_running_extension():
		main0()
	else:
		console.alert('Error Occured', 'Please launch from extension', 'ok', hide_cancel_button=True)
	
	print('')
	print('取得テキストファイル名: ' + cpedf1)
	print('')
	
	ie1 = 0
	ie2 = ''
	ie9 = ''
	
	iu1 = 0
	iu2 = ''
	iu4 = 0
	iu5 = ''
	iu6 = 0
	iu7 = ''
	iu8 = ''
	iu9 = ''
	iu10 = 0
	
	cc01 = ''
	cc05 = ''
	xb01 = 0
	xb02 = ''
	
	im1 = ''
	im2 = ''
	im3 = ''
	im4 = ''
	im5 = ''
	im6 = ''
	im7 = ''
	im8 = ''
	im9 = ''
	im10 = ''
	
	TTL1 = ''
	HBN1 = ''
	
	# テキストファイル開く
	cpedf3 = './Shared/'
	with open(cpedf3 + cpedf1, encoding='utf-8') as linef:

		# 1行ずつ読み込み
		for linm in linef:
		
			iu8 = iu8 + linm
			iu3 = linm.strip()
			
			# from - 1行目
			if iu1 == 0:
			
				im1 = type(iu1)
				im2 = type(iu3)
				
				if iu3 == 'from1':
				
					ie1 = 1
					ie9 = 'OK: FROM ' + iu3
					ie2 = dk01
					
				elif iu3 == 'from2':
				
					ie1 = 2
					ie9 = 'OK: FROM ' + iu3
					ie2 = dk05
				
				else:
				
					ie9 = 'NG: FROM addr: ' + iu3
					ie2 = iu3
					
			# to - 2行目
			elif iu1 == 1:
			
				im3 = type(iu3)

				# 空チェック
				if iu3 != '':
				
					# メールアドレスの @ マークチェック(フルアドレスケース)
					iu6 = linm.find("@")
					
					if iu6 != -1:
					
						iu4 = 1
						iu9 = 'OK: TO addr'
						iu2 = iu3
						xu01 = 2
						
					else:
					
						vc01, vc02, vc03 = mal_addr(iu3, 0, 0)
						iu4 = vc02
						iu2 = vc01
						xu01 = vc03
						
						if iu4 == 1:
							iu9 = 'OK: TO ' + iu3
						else:
							iu9 = 'NG: TO addr without @: ' + iu3
							
				else:
				
					iu4 = 3
					iu9 = 'NG: TO addr blank: ' + iu3
					iu2 = iu3
					xu01 = 1
					
			# cc - 3行目
			elif iu1 == 2:
			
				im4 = type(iu3)
				cc01 = iu3[4:].strip()

				# 固定文字列 ccc: 以降の空チェック
				if cc01 != '':
				
					# cc02 = len(cc01)
					cc03 = cc01.count(',')
					print('cc01: ' + cc01)
					print('cc03: ' + str(cc03))
					
					# cc 1つ のみ
					if cc03 == 0:
					
						vf01, vf02, vf03 = mal_addr(cc01, 0, 0)
						cc05 = vf01
						
					# cc 複数 (カンマ区切り)
					else:
					
						cc_lst = cc01.split(',')
						
						for cc_odd in cc_lst:
						
							ee_odd = cc_odd.strip()
							print('ee_odd: ' + ee_odd)
							vd01, vd02, vd03 = mal_addr(ee_odd, 0, 0)
							cc05 = cc05 + ', ' + vd01
							
						cc05 = cc05[1:].strip()
						
				else:
				
					# CC 指定なし
					xb01 = 1
					cc05 = 'No CC: '
					
				print('cc05: ' + cc05)
				print('')
				
			# 件名 - 4行目
			elif iu1 == 3:
			
				im5 = type(iu3)
				iu7 = iu3
				
			# 本文 - 5行目以降
			else:
			
				iu5 = iu5 + linm
				
			iu1 = iu1 + 1
			
	linef.close()

	im6 = type(ie1)
	im7 = type(iu4)
	im8 = type(xb01)
	im9 = type(xu01)

	# cc セット
	if xb01 != 1:
		xb02 = cc05
	else:
		xb02 = ''

	# bcc 振り分け
	# from1 from2 (自身アドレス)への送信は BCC 無し
	if xu01 == 1:
		xu02 = ''
	# マイちゃんの場合は from1 へ BCC バックアップ
	elif xu01 == 2:
		xu02 = dk01
	# ケンちゃんの場合は from2 へ BCC バックアップ
	elif xu01 == 3:
		xu02 = dk05
	# その他は from1 へ BCC バックアップ
	else:
		xu02 = dk01


	at1 = '@'
	hon2 = ''
	hon3 = ''
	top1 = iu5[0:1].strip()
	top2 = 0
	sdata = ''

	# 本文の先頭が @ の場合、ベル変換 呼び出し(beput.py)
	if top1 == at1:
		top2 = 1
		hon2 = iu5
		hon2.encode('utf-8')
		hon3 = beput.func01(sdata, hon2)

		print('')
		print('hon3: ' + hon3)
		print('')

		iu5 = hon3

	print('top1: ' + str(top1))
	print('top2: ' + str(top2))

	iu5.encode('utf-8')

	print('')
	print('iu5-B: ' + iu5)
	print('')

	# from フラグ (ie1) と to フラグ (iu4) をチェック
	if ie1 != 0 and iu4 == 1:

		# 通常メール送信
		TTL1 = iu7
		HBN1 = '\n' + iu5 + '\n'
		FRM1 = ie2
		TOO1 = iu2
		CAD1 = xb02
		BCC1 = xu02

	else:

		# 入力不備などエラー時 アラートメール送信
		TTL1 = 'ALERT: txt-open-mail.py: ' + now2
		HBN1 = '\n' + ie9 + '\n' + iu9 + '\n\n' + iu8 + '\n' 
		FRM1 = dk05
		TOO1 = dk05
		CAD1 = ''
		BCC1 = ''
		ie1 = 1
	
	LST1 = TOO1.split(',') + CAD1.split(',') + BCC1.split(',')
	FLC1 = ie1

	# 型確認
	print('')
	print('im1(iu1/loop counter): ' + str(im1))
	print('')
	print('im2(iu3/txt 1st from): ' + str(im2))
	print('im3(iu3/txt 2nd to): ' + str(im3))
	print('im4(iu3/txt 3rd cc): ' + str(im4))
	print('im5(iu3/txt 4th subject): ' + str(im5))
	print('')
	print('im6(ie1): ' + str(im6))
	print('im7(iu4): ' + str(im7))
	print('im8(xb01): ' + str(im8))
	print('im9(xu01): ' + str(im9))
	print('')

	print('subject(iu7): ' + iu7)
	print('')

	print('body(iu5): ' + '\n' + iu5)
	print('body end')
	print('')

	print('sendLists: ' + str(LST1))
	print('')

	print('FM/ie1: ' + str(ie1) + ' ' + ie9)
	print('TO/iu4: ' + str(iu4) + ' ' + iu9)
	print('BC/xu1: ' + str(xu01))
	print('')

	print('FROM: ' + FRM1)
	print('TO(iu2): ' + TOO1)
	print('CC: ' + CAD1)
	print('BCC: ' + BCC1)
	print('')

	if yes_no_input():

		print('yes case: 送信')
		print('')

		# メール送信 呼び出し
		send_mals(FRM1, TOO1, CAD1, BCC1, TTL1, HBN1, LST1, FLC1)

		print('送信完了')
		print('')
		sys.exit()

	else:

		print('no case: キャンセル終了')
		print('')
		sys.exit()

# =============================


```

---
### **[ 4. 和え物 ]**

```beput.py

# coding: utf-8

# =============================
# left
def lefts(text, n):
	return text[:n]

# right
def rights(text, n):
	return text[-n:]

# mid
def mids(text, n, m):
	return text[n-1:n+m-1]
# =============================

def chgcr(bms, dble, dblg):

	# ひらがな
	if bms == '(.':
		anz2 = ''
		dble = 0

	# カタカナ
	elif bms == '.(':
		anz2 = ''
		dble = 1

	# 濁点 1
	elif bms == '04':
		anz2 = ''
		dblg = 1

	# 濁点 2
	elif bms == '05':
		anz2 = ''
		dblg = 2

	else:

		if dble == 0:

			if dblg == 0:

				if bms == '01':
					anz2 = 'わ'
				elif bms == '02':
					anz2 = 'を'
				elif bms == '03':
					anz2 = 'ん'

				elif bms == '11':
					anz2 = 'あ'
				elif bms == '12':
					anz2 = 'い'
				elif bms == '13':
					anz2 = 'う'
				elif bms == '14':
					anz2 = 'え'
				elif bms == '15':
					anz2 = 'お'

				elif bms == '21':
					anz2 = 'か'
				elif bms == '22':
					anz2 = 'き'
				elif bms == '23':
					anz2 = 'く'
				elif bms == '24':
					anz2 = 'け'
				elif bms == '25':
					anz2 = 'こ'

				elif bms == '31':
					anz2 = 'さ'
				elif bms == '32':
					anz2 = 'し'
				elif bms == '33':
					anz2 = 'す'
				elif bms == '34':
					anz2 = 'せ'
				elif bms == '35':
					anz2 = 'そ'

				elif bms == '41':
					anz2 = 'た'
				elif bms == '42':
					anz2 = 'ち'
				elif bms == '43':
					anz2 = 'つ'
				elif bms == '44':
					anz2 = 'て'
				elif bms == '45':
					anz2 = 'と'

				elif bms == '51':
					anz2 = 'な'
				elif bms == '52':
					anz2 = 'に'
				elif bms == '53':
					anz2 = 'ぬ'
				elif bms == '54':
					anz2 = 'ね'
				elif bms == '55':
					anz2 = 'の'

				elif bms == '61':
					anz2 = 'は'
				elif bms == '62':
					anz2 = 'ひ'
				elif bms == '63':
					anz2 = 'ふ'
				elif bms == '64':
					anz2 = 'へ'
				elif bms == '65':
					anz2 = 'ほ'

				elif bms == '71':
					anz2 = 'ま'
				elif bms == '72':
					anz2 = 'み'
				elif bms == '73':
					anz2 = 'む'
				elif bms == '74':
					anz2 = 'め'
				elif bms == '75':
					anz2 = 'も'

				elif bms == '81':
					anz2 = 'や'
				elif bms == '82':
					anz2 = '、'
				elif bms == '83':
					anz2 = 'ゆ'
				elif bms == '84':
					anz2 = '。'
				elif bms == '85':
					anz2 = 'よ'

				elif bms == '91':
					anz2 = 'ら'
				elif bms == '92':
					anz2 = 'り'
				elif bms == '93':
					anz2 = 'る'
				elif bms == '94':
					anz2 = 'れ'
				elif bms == '95':
					anz2 = 'ろ'

				elif bms == '16':
					anz2 = 'a'
				elif bms == '17':
					anz2 = 'b'
				elif bms == '18':
					anz2 = 'c'
				elif bms == '19':
					anz2 = 'd'
				elif bms == '10':
					anz2 = 'e'

				elif bms == '26':
					anz2 = 'f'
				elif bms == '27':
					anz2 = 'g'
				elif bms == '28':
					anz2 = 'h'
				elif bms == '29':
					anz2 = 'i'
				elif bms == '20':
					anz2 = 'j'

				elif bms == '36':
					anz2 = 'k'
				elif bms == '37':
					anz2 = 'l'
				elif bms == '38':
					anz2 = 'm'
				elif bms == '39':
					anz2 = 'n'
				elif bms == '30':
					anz2 = 'o'

				elif bms == '46':
					anz2 = 'p'
				elif bms == '47':
					anz2 = 'q'
				elif bms == '48':
					anz2 = 'r'
				elif bms == '49':
					anz2 = 's'
				elif bms == '40':
					anz2 = 't'

				elif bms == '56':
					anz2 = 'u'
				elif bms == '57':
					anz2 = 'v'
				elif bms == '58':
					anz2 = 'w'
				elif bms == '59':
					anz2 = 'x'
				elif bms == '50':
					anz2 = 'y'

				elif bms == '66':
					anz2 = 'z'

				elif bms == '67':
					anz2 = '?'
				elif bms == '68':
					anz2 = '\n'
				elif bms == '69':
					anz2 = 'ー'
				elif bms == '70':
					anz2 = ' '

				elif bms == '96':
					anz2 = '1'
				elif bms == '97':
					anz2 = '2'
				elif bms == '98':
					anz2 = '3'
				elif bms == '99':
					anz2 = '4'
				elif bms == '90':
					anz2 = '5'

				elif bms == '06':
					anz2 = '6'
				elif bms == '07':
					anz2 = '7'
				elif bms == '08':
					anz2 = '8'
				elif bms == '09':
					anz2 = '9'
				elif bms == '00':
					anz2 = '0'

				else:
					anz2 = 'e1'

			elif dblg == 1:

				if bms == '11':
					anz2 = 'ぁ'
				elif bms == '12':
					anz2 = 'ぃ'
				elif bms == '13':
					anz2 = 'ぅ'
				elif bms == '14':
					anz2 = 'ぇ'
				elif bms == '15':
					anz2 = 'ぉ'

				elif bms == '21':
					anz2 = 'が'
				elif bms == '22':
					anz2 = 'ぎ'
				elif bms == '23':
					anz2 = 'ぐ'
				elif bms == '24':
					anz2 = 'げ'
				elif bms == '25':
					anz2 = 'ご'

				elif bms == '31':
					anz2 = 'ざ'
				elif bms == '32':
					anz2 = 'じ'
				elif bms == '33':
					anz2 = 'ず'
				elif bms == '34':
					anz2 = 'ぜ'
				elif bms == '35':
					anz2 = 'ぞ'

				elif bms == '41':
					anz2 = 'だ'
				elif bms == '42':
					anz2 = 'ぢ'
				elif bms == '43':
					anz2 = 'づ'
				elif bms == '44':
					anz2 = 'で'
				elif bms == '45':
					anz2 = 'ど'

				elif bms == '61':
					anz2 = 'ば'
				elif bms == '62':
					anz2 = 'び'
				elif bms == '63':
					anz2 = 'ぶ'
				elif bms == '64':
					anz2 = 'べ'
				elif bms == '65':
					anz2 = 'ぼ'

				elif bms == '81':
					anz2 = 'ゃ'
				elif bms == '82':
					anz2 = '、'
				elif bms == '83':
					anz2 = 'ゅ'
				elif bms == '84':
					anz2 = '。'
				elif bms == '85':
					anz2 = 'ょ'

				else:
					anz2 = 'e2'

				dblg = 0

			elif dblg == 2:

				if bms == '43':
					anz2 = 'っ'

				elif bms == '61':
					anz2 = 'ぱ'
				elif bms == '62':
					anz2 = 'ぴ'
				elif bms == '63':
					anz2 = 'ぷ'
				elif bms == '64':
					anz2 = 'ぺ'
				elif bms == '65':
					anz2 = 'ぽ'
				else:
					anz2 = 'e3'

				dblg = 0

		elif dble == 1:

			if dblg == 0:

				if bms == '01':
					anz2 = 'ワ'
				elif bms == '02':
					anz2 = 'ヲ'
				elif bms == '03':
					anz2 = 'ン'

				elif bms == '11':
					anz2 = 'ア'
				elif bms == '12':
					anz2 = 'イ'
				elif bms == '13':
					anz2 = 'ウ'
				elif bms == '14':
					anz2 = 'エ'
				elif bms == '15':
					anz2 = 'オ'

				elif bms == '21':
					anz2 = 'カ'
				elif bms == '22':
					anz2 = 'キ'
				elif bms == '23':
					anz2 = 'ク'
				elif bms == '24':
					anz2 = 'ケ'
				elif bms == '25':
					anz2 = 'コ'

				elif bms == '31':
					anz2 = 'サ'
				elif bms == '32':
					anz2 = 'シ'
				elif bms == '33':
					anz2 = 'ス'
				elif bms == '34':
					anz2 = 'セ'
				elif bms == '35':
					anz2 = 'ソ'

				elif bms == '41':
					anz2 = 'タ'
				elif bms == '42':
					anz2 = 'チ'
				elif bms == '43':
					anz2 = 'ツ'
				elif bms == '44':
					anz2 = 'テ'
				elif bms == '45':
					anz2 = 'ト'

				elif bms == '51':
					anz2 = 'ナ'
				elif bms == '52':
					anz2 = 'ニ'
				elif bms == '53':
					anz2 = 'ヌ'
				elif bms == '54':
					anz2 = 'ネ'
				elif bms == '55':
					anz2 = 'ノ'

				elif bms == '61':
					anz2 = 'ハ'
				elif bms == '62':
					anz2 = 'ヒ'
				elif bms == '63':
					anz2 = 'フ'
				elif bms == '64':
					anz2 = 'ヘ'
				elif bms == '65':
					anz2 = 'ホ'

				elif bms == '71':
					anz2 = 'マ'
				elif bms == '72':
					anz2 = 'ミ'
				elif bms == '73':
					anz2 = 'ム'
				elif bms == '74':
					anz2 = 'メ'
				elif bms == '75':
					anz2 = 'モ'

				elif bms == '81':
					anz2 = 'ヤ'
				elif bms == '82':
					anz2 = '、'
				elif bms == '83':
					anz2 = 'ユ'
				elif bms == '84':
					anz2 = '。'
				elif bms == '85':
					anz2 = 'ヨ'

				elif bms == '91':
					anz2 = 'ラ'
				elif bms == '92':
					anz2 = 'リ'
				elif bms == '93':
					anz2 = 'ル'
				elif bms == '94':
					anz2 = 'レ'
				elif bms == '95':
					anz2 = 'ロ'

				elif bms == '16':
					anz2 = 'A'
				elif bms == '17':
					anz2 = 'B'
				elif bms == '18':
					anz2 = 'C'
				elif bms == '19':
					anz2 = 'D'
				elif bms == '10':
					anz2 = 'E'

				elif bms == '26':
					anz2 = 'F'
				elif bms == '27':
					anz2 = 'G'
				elif bms == '28':
					anz2 = 'H'
				elif bms == '29':
					anz2 = 'I'
				elif bms == '20':
					anz2 = 'J'

				elif bms == '36':
					anz2 = 'K'
				elif bms == '37':
					anz2 = 'L'
				elif bms == '38':
					anz2 = 'M'
				elif bms == '39':
					anz2 = 'N'
				elif bms == '30':
					anz2 = 'O'

				elif bms == '46':
					anz2 = 'P'
				elif bms == '47':
					anz2 = 'Q'
				elif bms == '48':
					anz2 = 'R'
				elif bms == '49':
					anz2 = 'S'
				elif bms == '40':
					anz2 = 'T'

				elif bms == '56':
					anz2 = 'U'
				elif bms == '57':
					anz2 = 'V'
				elif bms == '58':
					anz2 = 'W'
				elif bms == '59':
					anz2 = 'X'
				elif bms == '50':
					anz2 = 'Y'

				elif bms == '66':
					anz2 = 'Z'

				elif bms == '67':
					anz2 = '?'
				elif bms == '68':
					anz2 = '\n'
				elif bms == '69':
					# anz2 = '-'
					anz2 = 'ー'
				elif bms == '70':
					anz2 = ', '

				elif bms == '96':
					anz2 = '1'
				elif bms == '97':
					anz2 = '2'
				elif bms == '98':
					anz2 = '3'
				elif bms == '99':
					anz2 = '4'
				elif bms == '90':
					anz2 = '5'

				elif bms == '06':
					anz2 = '6'
				elif bms == '07':
					anz2 = '7'
				elif bms == '08':
					anz2 = '8'
				elif bms == '09':
					anz2 = '9'
				elif bms == '00':
					anz2 = '0'

				else:
					anz2 = 'e4'

			elif dblg == 1:

				if bms == '11':
					anz2 = 'ァ'
				elif bms == '12':
					anz2 = 'ィ'
				elif bms == '13':
					anz2 = 'ゥ'
				elif bms == '14':
					anz2 = 'ェ'
				elif bms == '15':
					anz2 = 'ォ'

				elif bms == '21':
					anz2 = 'ガ'
				elif bms == '22':
					anz2 = 'ギ'
				elif bms == '23':
					anz2 = 'グ'
				elif bms == '24':
					anz2 = 'ゲ'
				elif bms == '25':
					anz2 = 'ゴ'

				elif bms == '31':
					anz2 = 'ザ'
				elif bms == '32':
					anz2 = 'ジ'
				elif bms == '33':
					anz2 = 'ズ'
				elif bms == '34':
					anz2 = 'ゼ'
				elif bms == '35':
					anz2 = 'ゾ'

				elif bms == '41':
					anz2 = 'ダ'
				elif bms == '42':
					anz2 = 'ヂ'
				elif bms == '43':
					anz2 = 'ヅ'
				elif bms == '44':
					anz2 = 'デ'
				elif bms == '45':
					anz2 = 'ド'

				elif bms == '61':
					anz2 = 'バ'
				elif bms == '62':
					anz2 = 'ビ'
				elif bms == '63':
					anz2 = 'ブ'
				elif bms == '64':
					anz2 = 'ベ'
				elif bms == '65':
					anz2 = 'ボ'

				elif bms == '81':
					anz2 = 'ャ'
				elif bms == '82':
					anz2 = '、'
				elif bms == '83':
					anz2 = 'ュ'
				elif bms == '84':
					anz2 = '。'
				elif bms == '85':
					anz2 = 'ョ'

				else:
					anz2 = 'e5'

				dblg = 0

			elif dblg == 2:

				if bms == '43':
					anz2 = 'ッ'

				elif bms == '61':
					anz2 = 'パ'
				elif bms == '62':
					anz2 = 'ピ'
				elif bms == '63':
					anz2 = 'プ'
				elif bms == '64':
					anz2 = 'ペ'
				elif bms == '65':
					anz2 = 'ポ'

				else:
					anz2 = 'e6'

				dblg = 0

	print('bms: ' + str(bms))
	print('dble: ' + str(dble))
	print('dblg: ' + str(dblg))
	print('')

	return anz2, dble, dblg

# =============================
def func01(udata, hon2):
	
	hon1 = hon2
	
	print('')
	print(hon1)
	print('')

	# OK
	hon1 = hon1.replace('\n', '')
	hon1 = hon1.replace('\r', '')
	hon1 = hon1.replace('\n\r', '')

	print('')
	print(hon1)
	print('')

	hon2b = ''
	ans0a = ''
	ans0b = ''
	
	double1 = 0
	double2 = 0
	kana1 = '(.'
	kana2 = '.('

	kugi0 = ''
	kugi1 = ''
	kugi2 = 0
	kugi3 = 0
	
	for ii in range(1, len(hon1), 2):

		ii = ii + 1

		anz0a = mids(hon1, ii, 2)

		kugi1, kugi2, kugi3 = chgcr(anz0a, double1, double2)

		print ('kugi1: ' + str(kugi1))
		print ('kugi2: ' + str(kugi2))
		print ('kugi3: ' + str(kugi3))
		print ('')

		hon2b = hon2b + kugi1

		double1 = kugi2
		double2 = kugi3

	print('')
	print('hon2func: ' + hon2b)

	return hon2b

# =============================

```

---

.