顯示具有 python3 標籤的文章。 顯示所有文章
顯示具有 python3 標籤的文章。 顯示所有文章

2021年5月13日

python3 text to voice

 整理一下學習記錄

https://data-flair.training/blogs/python-text-to-speech/

https://yanwei-liu.medium.com/python%E6%96%87%E5%AD%97%E8%BD%89%E8%AA%9E%E9%9F%B3-text-to-speech-f16609f80df9

sudo pip3 install gTTS

sudo pip3 install playsound

這樣可以在python中直接說話

lang= "en" 英語   

2021年5月5日

phthon3讀取健保卡上的資料

有需求記錄姓名和身份證字號,找了一下資料,可以用python3做出來

1.確定電腦和讀卡機是正常的(驅動程式....)

2. 參考資料:https://ithelp.ithome.com.tw/questions/10198968

3.安裝python3 

4.安裝pyscard(https://pypi.org/project/pyscard/)

pip install pyscard

或pip3 install pyscard

5.記錄檔為日期.txt

py程式碼

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import winsound

from smartcard.System import readers

# define the APDUs used in this script
SelectAPDU = [ 0x00, 0xA4, 0x04, 0x00, 0x10, 0xD1, 0x58, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00 ]

ReadProfileAPDU = [ 0x00, 0xca, 0x11, 0x00, 0x02, 0x00, 0x00 ]

# get all the available readers
r = readers()

reader = r[0]

connection = reader.createConnection()
connection.connect()

data, sw1, sw2 = connection.transmit(SelectAPDU)
print ("Select Applet: %02X %02X" % (sw1, sw2))

data, sw1, sw2 = connection.transmit(ReadProfileAPDU)
'''卡片內容
print ("Command: %02X %02X" % (sw1, sw2))
print  ('Card Number : %s' % ''.join(chr(i) for i in data[0:12]))
print  ('Name : %s' % ''.join(chr(i) for i in data[12:18])) # Big5
print  ('ID Number : %s' % ''.join(chr(i) for i in data[32:42]))
print  ('Birthday : %s' % ''.join(chr(i) for i in data[43:49]))
print  ('Sex : %s' % ''.join(chr(i) for i in data[49:50]))
print  ('Card Date : %s' % ''.join(chr(i) for i in data[51:57]))
'''
#身份證字號
uid = '%s' % ''.join(chr(i) for i in data[32:42])

#姓名
name = "{}".format(bytes(data[12:32]).decode("big5"))
#寫入檔案
fo = open("output.txt", "r+")
str = uid +  name + '\n'
# Write a line at the end of the file.
fo.seek(0, 2)
line = fo.write( str )
fo.close()
#發出嗶聲顥示已記錄
winsound.Beep(600,500)
print(uid +  name +'已記錄')

下載我的.py檔https://drive.google.com/file/d/1I8uGrEiec7TJTLSr5uejaFdMZwD7V3lU/view?usp=sharing

編譯完的.exe檔:https://drive.google.com/file/d/1sIiEVUg_70c-hg0Ux2488cg3Qmk2tjsg/view?usp=sharing


2020年2月14日

py compile pyc

 https://medium.com/pyladies-taiwan/python-%E5%B0%87python%E6%89%93%E5%8C%85%E6%88%90exe%E6%AA%94-32a4bacbe351


sudo pip3 install pyinstaller
 
windows 
pyinstaller -F .\hello.py
  
linux 
python3 -m compileall file.py


常用參數介紹

1. pyinstaller -h 來查看參數
2. -F 打包成一個exe文件
3. --icon=圖標路徑
4. -w 使用視窗,無控制台
5. -c 使用控制台,無視窗
6. -D 創建一個目錄,包含exe以及其他一些依賴性文件