2021年5月31日

再生圖龍

 有一天發現clonezilla可以用apt的方式安裝起來,讓我産生做圖形界面的動力。剛開始使用zenity刻,雖然可以,但總是不是很理想。後來發現gparted.iso中不但有圖形界面,iso檔也不大,又支援python3.9,於是花了一點時間調校安裝套件,寫python程式,再重新打包,産出第一版的gpartedclonezilla。下載點:https://drive.google.com/drive/folders/1ZdVZQZt75gTMxi7A836uddk49GTrvSre?usp=sharing

建議下載gpcl1100531以後的版本。

使用方式:

uefi的電腦(現在多數電腦為uefi開機)

找一支4G以上隨身碟,格式化成fat32,把iso檔使用7zip解壓縮到隨身碟中。

mbr的電腦(較老舊電腦通常使用mbr方式開機)

除了要做上述動作外,還到補做開機程式,在utils資料夾中有各系統需要的開機程式安裝。例如win10 64位元電腦,就到utils\win64中用最高權限執行makeboot64.bat,這樣這支隨身碟就可以開機了。

開機後會看到選單,使用預設選單(to ram)進入。

 

再來按下enter進入圖形界面(這裡可以選擇文字界面,給專業的人士使用的)

進入系統,預設會開啟gparted,如果不需使用,按右上角x,關閉gparted。


 

 如果你要使用專業的再生龍系統請按clonezilla,如果要使用再生圖龍請按clonezilla-e。 

clonezilla再生龍的使用很多人都熟悉在此不多述,很好用強大的備份還原系統。

clonezilla-e再生圖龍,是簡化版的再生龍,差別在它是用python3做圖形界面,讓初學者會更順利熟悉些。

最左邊是資料儲存區/home/gpartimag位置設定,可以選擇網路nfs samba ssh 分割區 等方式做為儲存位置,如果你是資訊組長,強列建議你把儲存區放在網路上,這樣可以在學校任何一台電腦進行網路還原。

中間是映像檔位列表,中間下面為映像檔中的分割區列表。

右邊是你想要的功能,上面是還原選項,下面是備份為映像檔按鈕


 

基本上是來源選擇和目的選擇,即可完成工作。例如要備份硬碟為映像檔,在左邊來源為硬碟中選擇硬碟,再到右邊確定映像檔名(預設使用日期+時為檔名),按下備份硬碟。

要還原時在來源選擇映像檔,右邊選擇還原硬碟或分割區,再按下還原按鈕。




scratch3增加擴充積木

 scratch3增加擴充積木

下載scratch3原始碼

網址:https://github.com/LLK/scratch-gui

 linux 下可以用git下載,win可以下載zip後解壓縮

git clone https://github.com/LLK/scratch-gui.git

註:linux下如果缺少git套件請自行安裝(sudo apt install git)

打開下載或解壓縮資料夾


安裝必要軟體 nodejs git nopad++

windows install npm 、git 和 nopad++

下載https://nodejs.org/en/download/
安裝64 bit msi
下載:http://git-scm.com/download/win
安裝git 
在win下編輯器個人使用nopad++
https://notepad-plus-plus.org/downloads/
安裝visualstudio code 
https://code.visualstudio.com/
 

安裝scratch gui

git clone https://github.com/LLK/scratch-gui.git
cd scratch-gui
npm install
npm install也可以一個指令解決npm install https://github.com/LLK/scratch-gui.git

 

啟動scratch3-gui

在scratch-gui資料夾下執行
npm start
在瀏覽器的網址列中輸入http://0.0.0.0:8601/就可以看到畫面
如果沒有成功可以嘗試輸入http://127.0.0.1:8601/ 
增加擴充積木
擴充積木的位置在scratch-gui目錄下的node_modules/scratch-vm資料夾中
原始檔要放在src/extensions資料夾中

試做範例

1.copy scratch3_microbit 成為scratch3_mybit

 
2.編輯node_modules/scratch-vm/src/extension-support/extension-manager.js
找到gdxfor: () => require('../extensions/scratch3_gdx_for')
在行尾加上,和mybit: () => require('../extensions/scratch3_mybit')
3.編輯src/lib/libraries/extensions/index.jsx
複製
import microbitIconURL from './microbit/microbit.png';
import microbitInsetIconURL from './microbit/microbit-small.svg';
import microbitConnectionIconURL from './microbit/microbit-illustration.svg';
import microbitConnectionSmallIconURL from './microbit/microbit-small.svg';
修改為
import mybitIconURL from './mybit/microbit.png';
import mybitInsetIconURL from './mybit/microbit-small.svg';
import mybitConnectionIconURL from './mybit/microbit-illustration.svg';
import mybitConnectionSmallIconURL from './mybit/microbit-small.svg'; 

往下找,找到
ame: 'micro:bit',
extensionId: 'microbit',
把整段大括號複製起來,在下面貼上並修改
4.複製microbit資料夾為mybit資料夾
5.回到瀏覽器中輸入網址http://0.0.0.0:8601,再按左下角的+號,就可以看到修改完的擴充積木
 

 

打包成離線版

 執行指令npm run build
會多build dist兩個資料夾,build資夾中為打包好的檔案,使用瀏覽器開啟index.html。
 

打包成應用程式

使用的是新北市育林國中林士立老師的打包方法
github下載:https://github.com/t301000/my-scratch3-offline
打包方式詳如github說明檔
1.npm install 安裝套件
2.把scratch-gui下的build資料夾複製到my-scratch3-offline中並改名為app
3.npm run package:win32 打包成exe應用程式
這時會有一個scratch3-win32-x64資料夾産生,裡面會有一個scratch3.exe的應用程式。
 
 如果要打包mac版,需要修改package.json
加入
"compress:mac": "rimraf osep_scratch3-darwin-x64-*.7z && 7z a scratch3-darwin-x64-`date '+%Y%m%d%H%M%S'`.7z osep_scratch3-darwin-x64"
打包指令
npm run package:mac
會産生一個scratch3-darwin-x64的資料夾
 
 
extensions內容探究
 const 是定義一些事情
class name是物件
最後一行要
module.exports = name;
積木前的圖示可以用blockiconURI來指定
const blockIconURI = 'data:image
積木是使用{}包起來描述
積木內容在
blocks: []
 
以下列範例示範
                {
                    opcode: 'displayText',
                    text: formatMessage({
                        id: 'microbit.displayText',
                        default: 'display text [TEXT]',
                        description: 'display text on the micro:bit display'
                    }),
                    blockType: BlockType.COMMAND,
                    arguments: {
                        TEXT: {
                            type: ArgumentType.STRING,
                            defaultValue: formatMessage({
                                id: 'microbit.defaultTextToDisplay',
                                default: 'Hello!',
                                description: `default text to display.
                                IMPORTANT - the micro:bit only supports letters a-z, A-Z.
                                Please substitute a default word in your language
                                that can be written with those characters,
                                substitute non-accented characters or leave it as "Hello!".
                                Check the micro:bit site documentation for details`
                            })
                        }
                    }
                },
 
opcode:是每個積木執行時要執行的副程式,後面的文字都對應一個function
blockType: BlockType.COMMAND,是積木型態,可以參考
https://medium.com/@hiroyuki.osaki/scratch-3-block-types-you-can-develop-and-samples-191b0d769b91
text:是描述內容,裡面用formatMessage()來表述時可以做多國語言id default和description,當然可以不寫,直接接一串文字 
menus:是選單,每個選單也都是用陣列表示
touchPins: {
acceptReporters: true,
items: ['0', '1', '2']
 
教學影片清單
osep github:https://github.com/ys-fang/OSEP

2021年5月14日

exe數位簽章

 用pyinstaller編輯成exe,結果被判讀成病毒。查了一下是因為沒有數位簽章。

參考文章:http://limitx5.blogspot.com/2017/05/windows-exe.html

 依文章下載sdk,安裝,並執行指令,要注意的是指令位置是很深。

C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64

 makecert -a sha1 -b 01/01/2003 -e 12/31/2099 -cy authority -eku 1.3.6.1.5.5.7.3.3 -sv myCA.pvk -r -n "CN=my_name, E=mail@domain.com" myCA.cer

cert2spc myCA.cer myCA.spc
pvk2pfx -pvk myCA.pvk -spc myCA.spc -po 1234 -pfx myCA.pfx -f
 
做好簽章後,pfx檔是重要的。
再來為程式加入憑證做二次 
signtool sign /f myCA.pfx /p 1234 /t http://timestamp.verisign.com/scripts/timstamp.dll /v "filename.exe"
signtool sign /fd sha256 /f myCA.pfx /p 1234 /as /tr http://sha256timestamp.ws.symantec.com/sha256/timestamp /v "filename.exe"

 


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月10日

gparted and clonezilla iso

 忽然發現可以把gparted iso中加入clonezilla,這樣要實現clonezilla圖形化界面和解決網路設定不方便問題,這樣好像也是一種解法。

1.下載了ggparted-live-1.3.0-1-amd64.iso (https://downloads.sourceforge.net/gparted/gparted-live-1.3.0-1-amd64.iso)

2.把它解壓縮打開

3.加入clonezilla,並修改了桌面圖示、開機選單、預設語系....

4.重新打包成iso.

使用方式:

uefi的電腦:把隨身碟格式化為fat32,再把iso解壓縮到隨身碟,即可開機

grub的電腦:把隨身碟格式化為fat32,再把iso解壓縮到隨身碟,再執行utils\win64\makeboot64.bat批次檔。linux系統則是在utils/linux下打開終端機執行sudo bash makeboot.sh /dev/sdx1

下載:iso:https://drive.google.com/drive/folders/1ZdVZQZt75gTMxi7A836uddk49GTrvSre?usp=sharing





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