Python

Use Python to build a automatic scheduling process for OpenID login facebook and interactions with website

Recently, have had some scheduling tasks that need to execute on the website. This will cause high effort for this manually routine job.

For reducing the effort, I build an automation mechanism to replace the routine job, here will record the process for anyone who needs refer.

This article will use an example as a case to demonstrate how to build this automation process, and the following are this example of system processing:

Continue Reading

理解 Python package & module 入門 - Getting Start With Python Module

理解 Python package & module 入門

Python 簡單易學,並且 Python 扮演了非常好的膠水的角色,將大量功能強的大模組整合在一起,讓他成為如今火熱的程式碼。

在這裡主要會說明 Package, Module 的組成。

首先聊聊 Module

在 python 來說,我們主要都會透過 module 來將建構我們的程式碼,一個 module 簡單來說,就是一個 .py 檔案。

├── mymodule.py

例如,建立一個 saymodule.py

class sayHello():
    name = ''
    message = 'hello world'
    def To(self):
        if self.name == '':

if __name__ == '__main__':
    sayhello = sayHello()
    sayhello.name = 'adam'
    sayhello.To()

接著在 main.py 導入

from saymodule import sayHello

sayhello = sayHello()
sayhello.name = 'brother'
sayhello.To()

Python, package 與 module 的關係

在前面提到,我們可以獨立建立 module 方式來引入使用,

但是,為了可以更好的將 package 區隔開,會再透過 package,將多個 module 整合成一個 package,這個打包好的 package,就可以很方便地被拿來使用,並且,package 必須包含 __init__.py,結構如下:

Continue Reading

Python 運行 Selenium 入門

Python 運行 Selenium 入門

這裡支援 Python 2.7, 3.4+

安裝 Driver

下載瀏覽器 driver ,請依照你瀏覽器目前的版本下載對應的 Driver

Chrome: https://sites.google.com/a/chromium.org/chromedriver/downloads
Edge: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Firefox: https://github.com/mozilla/geckodriver/releases
Safari: https://webkit.org/blog/6900/webdriver-support-in-safari-10/

在這裡,我們目前 Chrome 版本是 79.x,因此下載的是 chromedriver 79.x版本,

下載完成後,將 driver 放置環境變數,並且給予執行的權限

sudo cp chromedriver /usr/local/bin
sudo chmod +x /usr/local/bin/chromedriver

Python 安裝 selenium

安裝

pip install -U selenium
//or
pip3 install -U selenium

建立專案

vim test.py

建立爬蟲腳本,前往奇摩首頁,搜尋欄輸入 seleniumhq 後,送出搜尋

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome()

browser.get('http://www.yahoo.com')
assert 'Yahoo' in browser.title

elem = browser.find_element_by_name('p')  # Find the search box
elem.send_keys('seleniumhq' + Keys.RETURN)

browser.quit()

執行

Continue Reading

推薦幾個 Python 深度學習入門 Libraries

推薦幾個 Python 深度學習入門 Libraries

最近在研究語音辨識,順帶看了一下 Python,這裡大概就介紹一下在學習 Python 深度學習推薦入門的幾個 Libraries。

簡介

Python 運用在深度學習算相當具有優勢,支援的 libraries 相當豐富,在這裡推薦幾個 Libraries ,進行介紹。

在了解及初次熟悉這些 Libraries 時,建議可以透過以下方式:

  • 透過 Jupyter Notebook 來引入 Library
  • 一步步的跟著文檔中的快速起步流程,先理解方向
  • 用30分鐘來閱讀文檔,來確實理解 Library 的 modules 用法

如果是透過 Anaconda 啟用 Jupyther Notebook ,則可以參考這部影片 https://www.youtube.com/watch?v=-MyjG00la2k

Continue Reading

推薦幾個 Python 資料科學計算入門 Libraries

推薦幾個 Python 資料科學計算入門 Libraries

最近在研究語音辨識,順帶看了一下 Python,這裡大概就介紹一下在學習 Python 資料科學計算推薦入門的幾個 Libraries。

簡介

Python 運用在科學資料計算相當具有優勢,支援的 libraries 相當豐富,在這裡推薦幾個 Libraries ,進行介紹。

在了解及初次熟悉這些 Libraries 時,建議可以透過以下方式:

  • 透過 Jupyter Notebook 來引入 Library
  • 一步步的跟著文檔中的快速起步流程,先理解方向
  • 用30分鐘來閱讀文檔,來確實理解 Library 的 modules 用法

如果是透過 Anaconda 啟用 Jupyther Notebook ,則可以參考這部影片 https://www.youtube.com/watch?v=-MyjG00la2k

Continue Reading

No module named Keras.models 錯誤的幾種解決方式

No module named Keras.models 錯誤的幾種解決方式

在執行 Python Keras過程,如果出現錯誤提示:

ModuleNotFoundError: No module named ‘keras.models’; ‘keras’ is not a package

解決方式一

如果中間過程提示缺少套件,缺什麼就安裝什麼

pip3 install keras

可以查看自己目前安裝的套件有哪些

pip3 list

解決方式二

如果安裝後仍出現 No module named 'eras.models'… 那這時請確認一下是否你有將檔案名稱命名為 keras.py

如果有,這表示 Python 在執行過程會認為你是要將這個檔案 import

因此,解決方式是將檔案名稱更換掉就可以

Continue Reading

MFCC 音波比對實測結果

MFCC 音波比對實測結果

最近在嘗試幾種音波比對的方向,大致測試過幾種技術,

這裡主要紀錄音波轉成 MFCC 之後,進行實測的一些過程及觀察數據,

首先,根據不同狀況錄製了不同的音頻,接著就直接針對音頻進行比較,

(免責聲明!以下測試並無使用正規統計方式評測,僅供參考)

Continue Reading

AudioDiff 實測

本篇主要針對 AudioDiff 在音檔比對的實測

Continue Reading

AudioCompare (base on Shazam ) 實測

下載AudioCompare

git clone https://github.com/charlesconnell/AudioCompare.git

進行比對

./audiomatch -f howareudoing.wav -f howareudo.wav
# MATCH howareudoing.wav howareudo.wav (39)

./audiomatch -f howareudoing.wav -f howsgoingtoday.wav
# MATCH howareudoing.wav howsgoingtoday.wav (13)

./audiomatch -f howareudoing.wav -f howareudoing.wav
# MATCH howareudoing.wav howareudoing.wav (112)

./audiomatch -f application.wav -f howareudo.wav
# NO MATCH

目前測試結果,準確性相當低

透過文字自動生成的音檔,可比對出匹配指數 但是透過實際發音的檔案,同樣唸法仍無法匹配出來

Continue Reading

CentOS7 安裝 ffmpeg

CentOS7 安裝 ffmpeg

安裝 EPEL 來使用其他 repo 資源

yum install -y epel-release

sudo rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

sudo rpm –import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro

sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm

yum repolist 

接著執行

yum install -y ffmpeg

查看版本

ffmpeg -version 

Continue Reading

[解決] CentOS7 - PocketSphinx 安裝過程狀況排解

##[解決] CentOS7 - PocketSphinx 安裝過程狀況排解

在安裝 PocketSphinx 過程中

pip install PocketSphinx

發生了安裝錯誤訊息:

error: command ‘swig’ failed with exit status

這部分處理很簡單,缺什麼安裝什麼:

先來安裝 swig

yum  install swig -y

接著再進行安裝,出現另一個錯誤:

**include <pulse/pulseaudio.h>

解決方式:

CVT2HUGO: error: command 'gcc' failed with exit status 1**
yum install python34-devel -y
yum install alsa-lib-devel alsa-utils

最後執行安裝~完成

pip install PocketSphinx

Continue Reading

解決 Python [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

解決 Python [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

最近在測試 wit.ai 語音辨識過程出現 CERTIFICATE_VERIFY_FAILED 錯誤,原因是 Python 3.6 之後的版本更改了 OpenSSL 協定,因此需要手動進行更新

Could not request results ; recognition connection failed: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056) Could not request results from Wit.ai service; recognition connection failed: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)

Continue Reading

CentOS7 安裝 PyAudio 發生錯誤[解決]

CentOS7 安裝 PyAudio 發生錯誤[解決]

執行

pip install PyAudio

如果出現以下次錯誤


Collecting PyAudio
  Downloading https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Building wheels for collected packages: PyAudio
  Building wheel for PyAudio (setup.py) ... error
  ERROR: Complete output from command /opt/rh/rh-python36/root/usr/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-aqdgoicv/PyAudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-3dqdycqf --python-tag cp36:
  ERROR: running bdist_wheel
  running build
  running build_py

原因在於,需要安裝 portaudio ,解決方式如下:

wget http://portaudio.com/archives/pa_stable_v190600_20161030.tgz
tar -xvf pa_stable_v190600_20161030.tgz
cd portaudio
./configure

接著在執行安裝,應該就會正常

pip install PyAudio

Continue Reading

CentOS7 安裝 Python3

CentOS7 安裝 Python3

在這裡紀錄如何在 CentOS7 安裝 Python3 ,主要透過 Software Collections(SCL)來安裝 python3

vim  /etc/yum.repos.d/CentOS-Base.repo

尋找 extras

Continue Reading

Mac OS 安裝 Python 3 方法及建議

Mac OS 安裝 Python 3 方法及建議

Mac OS X 預設安裝了 Python 2.7.10 版本

$ python --version
Python 2.7.10

這裡說明如何安裝 python3

Continue Reading