# Python Fintech 學習筆記 : 用 twder 模組擷取台銀外匯報價
直接用 pip3 安裝卻出現找不到相依套件 libxml2 與 libxslt 的錯誤 :
pi@raspberrypi:~ $ pip3 install twder
Collecting twder
Downloading https://files.pythonhosted.org/packages/79/44/9d25944c500732f10cde648b86be297449eb3d2c9608699f744e75d9361f/twder-0.1.4-py3-none-any.whl
Collecting requests (from twder)
Using cached https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl
Collecting lxml (from twder)
Using cached https://files.pythonhosted.org/packages/7d/29/174d70f303016c58bd790c6c86e6e86a9d18239fac314d55a9b7be501943/lxml-4.3.3.tar.gz
Collecting idna<2.9,>=2.5 (from requests->twder)
Using cached https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl
Collecting urllib3<1.25,>=1.21.1 (from requests->twder)
Using cached https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests->twder)
Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests->twder)
Using cached https://files.pythonhosted.org/packages/60/75/f692a584e85b7eaba0e03827b3d51f45f571c2e793dd731e598828d380aa/certifi-2019.3.9-py2.py3-none-any.whl
Building wheels for collected packages: lxml
Running setup.py bdist_wheel for lxml ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-x2ow03f4/lxml/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/tmpijs4zby1pip-wheel- --python-tag cp35:
Building lxml version 4.3.3.
Building without Cython.
ERROR: b'/bin/sh: 1: xslt-config: not found\n'
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.5
creating build/lib.linux-armv7l-3.5/lxml
.... (略) ....
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6waWnr/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -Isrc -Isrc/lxml/includes -I/usr/include/python3.5m -c src/lxml/etree.c -o build/temp.linux-armv7l-3.5/src/lxml/etree.o -w
In file included from src/lxml/etree.c:687:0:
src/lxml/includes/etree_defs.h:14:31: fatal error: libxml/xmlversion.h: 沒有此一檔案或目錄
#include "libxml/xmlversion.h"
^
compilation terminated.
Compile failed: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
creating tmp
cc -I/usr/include/libxml2 -c /tmp/xmlXPathInit3sx4_qt3.c -o tmp/xmlXPathInit3sx4_qt3.o
/tmp/xmlXPathInit3sx4_qt3.c:1:26: fatal error: libxml/xpath.h: 沒有此一檔案或目錄
#include "libxml/xpath.h"
^
compilation terminated.
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
----------------------------------------
Failed building wheel for lxml
Running setup.py clean for lxml
Failed to build lxml
Installing collected packages: idna, urllib3, chardet, certifi, requests, lxml, twder
Running setup.py install for lxml ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-x2ow03f4/lxml/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-jxkmwzj0-record/install-record.txt --single-version-externally-managed --compile --user --prefix=:
Building lxml version 4.3.3.
Building without Cython.
ERROR: b'/bin/sh: 1: xslt-config: not found\n'
** make sure the development packages of libxml2 and libxslt are installed **
Using build configuration of libxslt
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.5
creating build/lib.linux-armv7l-3.5/lxml
copying src/lxml/sax.py -> build/lib.linux-armv7l-3.5/lxml
.... (略) ....
building 'lxml.etree' extension
creating build/temp.linux-armv7l-3.5
creating build/temp.linux-armv7l-3.5/src
creating build/temp.linux-armv7l-3.5/src/lxml
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6waWnr/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -Isrc -Isrc/lxml/includes -I/usr/include/python3.5m -c src/lxml/etree.c -o build/temp.linux-armv7l-3.5/src/lxml/etree.o -w
In file included from src/lxml/etree.c:687:0:
src/lxml/includes/etree_defs.h:14:31: fatal error: libxml/xmlversion.h: 沒有此一檔案或目錄
#include "libxml/xmlversion.h"
^
compilation terminated.
Compile failed: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
cc -I/usr/include/libxml2 -c /tmp/xmlXPathInitzd492hbe.c -o tmp/xmlXPathInitzd492hbe.o
/tmp/xmlXPathInitzd492hbe.c:1:26: fatal error: libxml/xpath.h: 沒有此一檔案或目錄
#include "libxml/xpath.h"
^
compilation terminated.
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-x2ow03f4/lxml/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-jxkmwzj0-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-x2ow03f4/lxml/
總之就是缺了 libxml2 與 libxslt 這兩個相依模組.
直接用 pip3 安裝 libxml2 結果找不到此套件 :
pi@raspberrypi:~ $ pip3 install libxml2
Collecting libxml2
Could not find a version that satisfies the requirement libxml2 (from versions: )
No matching distribution found for libxml2
搜尋 "fatal error: libxml/xmlversion.h: 沒有此一檔案或目錄" 找到下面文章 :
原來 libxml2 與 libxslt 的安裝指令是 :
sudo apt-get install libxml2-dev libxslt-dev
pi@raspberrypi:~ $ sudo apt-get install libxml2-dev libxslt-dev
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
Note, selecting 'libxslt1-dev' instead of 'libxslt-dev'
libxml2-dev is already the newest version (2.9.4+dfsg1-2.2+deb9u2).
下列【新】套件將會被安裝:
libxslt1-dev
升級 0 個,新安裝 1 個,移除 0 個,有 0 個未被升級。
需要下載 488 kB 的套件檔。
此操作完成之後,會多佔用 2,246 kB 的磁碟空間。
是否繼續進行 [Y/n]? [Y/n] Y
下載:1 http://mirror.ossplanet.net/raspbian/raspbian stretch/main armhf libxslt1-dev armhf 1.1.29-2.1 [488 kB]
取得 488 kB 用了 2s (173 kB/s)
選取了原先未選的套件 libxslt1-dev:armhf。
(讀取資料庫 ... 目前共安裝了 134098 個檔案和目錄。)
Preparing to unpack .../libxslt1-dev_1.1.29-2.1_armhf.deb ...
Unpacking libxslt1-dev:armhf (1.1.29-2.1) ...
Processing triggers for man-db (2.7.6.1-2) ...
設定 libxslt1-dev:armhf (1.1.29-2.1) ...
然後再次安裝 twder 即可 :
pi@raspberrypi:~ $ pip3 install twder
Collecting twder
Using cached https://files.pythonhosted.org/packages/79/44/9d25944c500732f10cde648b86be297449eb3d2c9608699f744e75d9361f/twder-0.1.4-py3-none-any.whl
Collecting lxml (from twder)
Using cached https://files.pythonhosted.org/packages/7d/29/174d70f303016c58bd790c6c86e6e86a9d18239fac314d55a9b7be501943/lxml-4.3.3.tar.gz
Collecting requests (from twder)
Using cached https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl
Collecting idna<2.9,>=2.5 (from requests->twder)
Using cached https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl
Collecting urllib3<1.25,>=1.21.1 (from requests->twder)
Using cached https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests->twder)
Using cached https://files.pythonhosted.org/packages/60/75/f692a584e85b7eaba0e03827b3d51f45f571c2e793dd731e598828d380aa/certifi-2019.3.9-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests->twder)
Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Building wheels for collected packages: lxml
Running setup.py bdist_wheel for lxml ... | (這部分跑很久, 要耐心等)
done
Stored in directory: /home/pi/.cache/pip/wheels/e4/d1/de/8e0e572dddb1a0e96c480b2a01ef9dbbc4fa86456cdd5a303a
Successfully built lxml
Installing collected packages: lxml, idna, urllib3, certifi, chardet, requests, twder
Successfully installed certifi-2019.3.9 chardet-3.0.4 idna-2.8 lxml-4.3.3 requests-2.21.0 twder-0.1.4 urllib3-1.24.1
安裝過程跑很久, 會讓人誤以為是當機了, 但只要耐心等待, 最後會顯示成功訊息. 其實還有一個做法是, 乾脆在 PyPi 網站下載原始程式來編譯會比較快 (注意, libxml2 與 libxslt 還是要先安裝, 再編譯 twder 原始碼) :
pi@raspberrypi:~ $ wget https://files.pythonhosted.org/packages/d9/f6/c8c8683aa1c3599d0168bb9476d94af43f0248c0be86b53e2c796614a120/twder-0.1.4.tar.gz
下載的壓縮檔是 twder-0.1.4.tar.gz, 用 tar 解壓 :
pi@raspberrypi:~ $ tar -xvf twder-0.1.4.tar.gz
twder-0.1.4/
twder-0.1.4/PKG-INFO
twder-0.1.4/LICENSE
twder-0.1.4/requirements.txt
twder-0.1.4/MANIFEST.in
twder-0.1.4/README.md
twder-0.1.4/setup.py
twder-0.1.4/setup.cfg
twder-0.1.4/twder.egg-info/
twder-0.1.4/twder.egg-info/PKG-INFO
twder-0.1.4/twder.egg-info/SOURCES.txt
twder-0.1.4/twder.egg-info/requires.txt
twder-0.1.4/twder.egg-info/top_level.txt
twder-0.1.4/twder.egg-info/dependency_links.txt
twder-0.1.4/twder/
twder-0.1.4/twder/__init__.py
twder-0.1.4/twder/api.py
可見解壓後的目錄 twder-0.1.4 內有安裝程式 setup.py, 切換至此目錄, 用 sudo 執行安裝, 注意, 一定要用 sudo 安裝, 否則會有權限問題 :
pi@raspberrypi:~ $ cd twder-0.1.4
pi@raspberrypi:~/twder-0.1.4 $ sudo python3 setup.py install
/usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
warnings.warn(msg)
running install
running bdist_egg
running egg_info
writing top-level names to twder.egg-info/top_level.txt
writing twder.egg-info/PKG-INFO
writing dependency_links to twder.egg-info/dependency_links.txt
writing requirements to twder.egg-info/requires.txt
reading manifest file 'twder.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'twder.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
creating build/lib
creating build/lib/twder
copying twder/api.py -> build/lib/twder
copying twder/__init__.py -> build/lib/twder
creating build/bdist.linux-armv7l/egg
creating build/bdist.linux-armv7l/egg/twder
copying build/lib/twder/api.py -> build/bdist.linux-armv7l/egg/twder
copying build/lib/twder/__init__.py -> build/bdist.linux-armv7l/egg/twder
byte-compiling build/bdist.linux-armv7l/egg/twder/api.py to api.cpython-35.pyc
byte-compiling build/bdist.linux-armv7l/egg/twder/__init__.py to __init__.cpython-35.pyc
creating build/bdist.linux-armv7l/egg/EGG-INFO
copying twder.egg-info/PKG-INFO -> build/bdist.linux-armv7l/egg/EGG-INFO
copying twder.egg-info/SOURCES.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying twder.egg-info/dependency_links.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying twder.egg-info/requires.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying twder.egg-info/top_level.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/twder-0.1.4-py3.5.egg' and adding 'build/bdist.linux-armv7l/egg' to it
removing 'build/bdist.linux-armv7l/egg' (and everything under it)
Processing twder-0.1.4-py3.5.egg
Copying twder-0.1.4-py3.5.egg to /usr/local/lib/python3.5/dist-packages
Adding twder 0.1.4 to easy-install.pth file
Installed /usr/local/lib/python3.5/dist-packages/twder-0.1.4-py3.5.egg
Processing dependencies for twder==0.1.4
Searching for requests==2.12.4
Best match: requests 2.12.4
Adding requests 2.12.4 to easy-install.pth file
Using /usr/lib/python3/dist-packages
Searching for lxml==3.7.1
Best match: lxml 3.7.1
Adding lxml 3.7.1 to easy-install.pth file
Using /usr/lib/python3/dist-packages
Finished processing dependencies for twder==0.1.4
Bingo! 終於搞定 twder 安裝了!
接下來測試一下資料擷取功能 :
pi@raspberrypi:~ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import twder #匯入套件
>>> twder.currencies() #列出台銀可交易之外幣代號
['MYR', 'JPY', 'GBP', 'NZD', 'VND', 'ZAR', 'HKD', 'USD', 'CHF', 'KRW', 'SGD', 'IDR', 'CNY', 'CAD', 'AUD', 'EUR', 'SEK', 'THB', 'PHP']
>>> twder.currency_name_dict() #列出台銀可交易之外幣代號
{'MYR': '馬來幣 (MYR)', 'JPY': '日圓 (JPY)', 'GBP': '英鎊 (GBP)', 'NZD': '紐元 (NZD)', 'VND': '越南盾 (VND)', 'ZAR': '南非幣 (ZAR)', 'HKD': '港幣 (HKD)', 'USD': '美金 (USD)', 'CHF': '瑞士法郎 (CHF)', 'KRW': '韓元 (KRW)', 'SGD': '新加坡幣 (SGD)', 'IDR': '印尼幣 (IDR)', 'CNY': '人民幣 (CNY)', 'CAD': '加拿大幣 (CAD)', 'AUD': '澳幣 (AUD)', 'EUR': '歐元 (EUR)', 'SEK': '瑞典幣 (SEK)', 'THB': '泰幣 (THB)', 'PHP': '菲國比索 (PHP)'}
>>> twder.now('USD') #查詢指定貨幣即時報價
('2019/04/08 16:00', '30.41', '31.1', '30.78', '30.88')
>>> twder.now_all() #查詢全部貨幣即時報價
{'MYR': ('2019/04/08 16:00', '6.426', '8.056', '-', '-'), 'JPY': ('2019/04/08 16:00', '0.2674', '0.2802', '0.2747', '0.2787'), 'GBP': ('2019/04/08 16:00', '39.06', '41.18', '40.06', '40.48'), 'SGD': ('2019/04/08 16:00', '22.16', '23.07', '22.65', '22.83'), 'IDR': ('2019/04/08 16:00', '0.00183', '0.00253', '-', '-'), 'NZD': ('2019/04/08 16:00', '20.29', '21.14', '20.67', '20.87'), 'CAD': ('2019/04/08 16:00', '22.55', '23.46', '22.94', '23.16'), 'KRW': ('2019/04/08 16:00', '0.02517', '0.02907', '-', '-'), 'ZAR': ('2019/04/08 16:00', '-', '-', '2.13', '2.21'), 'AUD': ('2019/04/08 16:00', '21.51', '22.29', '21.78', '22.01'), 'THB': ('2019/04/08 16:00', '0.8413', '1.0293', '0.9499', '0.9899'), 'CNY': ('2019/04/08 16:00', '4.489', '4.651', '4.561', '4.611'), 'HKD': ('2019/04/08 16:00', '3.761', '3.977', '3.897', '3.957'), 'EUR': ('2019/04/08 16:00', '33.8', '35.14', '34.42', '34.82'), 'PHP': ('2019/04/08 16:00', '0.5178', '0.6508', '-', '-'), 'USD': ('2019/04/08 16:00', '30.41', '31.1', '30.78', '30.88'), 'VND': ('2019/04/08 16:00', '0.00096', '0.00146', '-', '-'), 'CHF': ('2019/04/08 16:00', '30.03', '31.23', '30.69', '30.98'), 'SEK': ('2019/04/08 16:00', '2.93', '3.45', '3.27', '3.37')}
>>> twder.past_day('USD') #查詢指定貨幣昨日全部報價
[('2019/04/08 09:00:50', '30.395', '31.085', '30.765', '30.865'), ('2019/04/08 09:05:23', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 09:14:08', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 09:25:06', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 09:34:23', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 09:35:29', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 09:41:51', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 09:47:12', '30.395', '31.085', '30.765', '30.865'), ('2019/04/08 09:57:28', '30.395', '31.085', '30.765', '30.865'), ('2019/04/08 10:00:25', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 10:02:58', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 10:10:48', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 10:15:11', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 10:16:55', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 10:18:39', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 10:23:17', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 10:25:13', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 10:32:03', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 10:32:37', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 10:35:07', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 10:54:25', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 10:55:51', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 11:03:38', '30.395', '31.085', '30.765', '30.865'), ('2019/04/08 11:10:30', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 11:14:39', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 11:20:59', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 11:26:03', '30.395', '31.085', '30.765', '30.865'), ('2019/04/08 11:27:28', '30.395', '31.085', '30.765', '30.865'), ('2019/04/08 11:32:35', '30.395', '31.085', '30.765', '30.865'), ('2019/04/08 11:35:21', '30.395', '31.085', '30.765', '30.865'), ('2019/04/08 11:45:02', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 11:57:11', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 12:21:05', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 12:39:39', '30.4', '31.09', '30.77', '30.87'), ('2019/04/08 12:46:18', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 12:58:35', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 13:14:20', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 13:43:19', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 13:59:57', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 14:00:42', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 14:23:52', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 14:25:16', '30.41', '31.1', '30.78', '30.88'), ('2019/04/08 14:33:11', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 15:03:18', '30.405', '31.095', '30.775', '30.875'), ('2019/04/08 15:12:05', '30.41', '31.1', '30.78', '30.88'), ('2019/04/08 15:32:12', '30.41', '31.1', '30.78', '30.88'), ('2019/04/08 15:39:11', '30.41', '31.1', '30.78', '30.88'), ('2019/04/08 15:42:54', '30.415', '31.105', '30.785', '30.885'), ('2019/04/08 16:00:10', '30.41', '31.1', '30.78', '30.88')]
>>> twder.past_six_month('USD') #查詢指定貨幣近半年收盤價
[('2019/04/08', '30.41', '31.1', '30.78', '30.88'), ('2019/04/03', '30.39', '31.08', '30.76', '30.86'), ('2019/04/02', '30.415', '31.105', '30.785', '30.885'), ('2019/04/01', '30.375', '31.065', '30.745', '30.845'), ('2019/03/29', '30.4', '31.09', '30.77', '30.87'), ('2019/03/28', '30.425', '31.115', '30.795', '30.895'), ('2019/03/27', '30.43', '31.12', '30.8', '30.9'), ('2019/03/26', '30.41', '31.1', '30.78', '30.88'), ('2019/03/25', '30.4', '31.09', '30.77', '30.87'), ('2019/03/22', '30.375', '31.065', '30.745', '30.845'), ('2019/03/21', '30.39', '31.08', '30.76', '30.86'), ('2019/03/20', '30.41', '31.1', '30.78', '30.88'), ('2019/03/19', '30.41', '31.1', '30.78', '30.88'), ('2019/03/18', '30.41', '31.1', '30.78', '30.88'), ('2019/03/15', '30.455', '31.145', '30.825', '30.925'), ('2019/03/14', '30.47', '31.16', '30.84', '30.94'), ('2019/03/13', '30.48', '31.17', '30.85', '30.95'), ('2019/03/12', '30.48', '31.17', '30.85', '30.95'), ('2019/03/11', '30.48', '31.17', '30.85', '30.95'), ('2019/03/08', '30.475', '31.165', '30.845', '30.945'), ('2019/03/07', '30.445', '31.135', '30.815', '30.915'), ('2019/03/06', '30.425', '31.115', '30.795', '30.895'), ('2019/03/05', '30.42', '31.11', '30.79', '30.89'), ('2019/03/04', '30.4', '31.09', '30.77', '30.87'), ('2019/02/27', '30.35', '31.04', '30.72', '30.82'), ('2019/02/26', '30.36', '31.05', '30.73', '30.83'), ('2019/02/25', '30.37', '31.06', '30.74', '30.84'), ('2019/02/23', '30.4', '31.09', '30.77', '30.87'), ('2019/02/22', '30.4', '31.09', '30.77', '30.87'), ('2019/02/21', '30.405', '31.095', '30.775', '30.875'), ('2019/02/20', '30.405', '31.095', '30.775', '30.875'), ('2019/02/19', '30.415', '31.105', '30.785', '30.885'), ('2019/02/18', '30.42', '31.11', '30.79', '30.89'), ('2019/02/15', '30.43', '31.12', '30.8', '30.9'), ('2019/02/14', '30.41', '31.1', '30.78', '30.88'), ('2019/02/13', '30.41', '31.1', '30.78', '30.88'), ('2019/02/12', '30.41', '31.1', '30.78', '30.88'), ('2019/02/11', '30.38', '31.07', '30.75', '30.85'), ('2019/02/01', '30.315', '31.005', '30.685', '30.785'), ('2019/01/31', '30.315', '31.005', '30.685', '30.785'), ('2019/01/30', '30.34', '31.03', '30.71', '30.81'), ('2019/01/29', '30.39', '31.08', '30.76', '30.86'), ('2019/01/28', '30.37', '31.06', '30.74', '30.84'), ('2019/01/25', '30.4', '31.09', '30.77', '30.87'), ('2019/01/24', '30.46', '31.15', '30.83', '30.93'), ('2019/01/23', '30.47', '31.16', '30.84', '30.94'), ('2019/01/22', '30.47', '31.16', '30.84', '30.94'), ('2019/01/21', '30.425', '31.115', '30.795', '30.895'), ('2019/01/19', '30.415', '31.105', '30.785', '30.885'), ('2019/01/18', '30.42', '31.11', '30.79', '30.89'), ('2019/01/17', '30.425', '31.115', '30.795', '30.895'), ('2019/01/16', '30.405', '31.095', '30.775', '30.875'), ('2019/01/15', '30.395', '31.085', '30.765', '30.865'), ('2019/01/14', '30.42', '31.11', '30.79', '30.89'), ('2019/01/11', '30.375', '31.065', '30.745', '30.845'), ('2019/01/10', '30.36', '31.05', '30.73', '30.83'), ('2019/01/09', '30.375', '31.065', '30.745', '30.845'), ('2019/01/08', '30.415', '31.105', '30.785', '30.885'), ('2019/01/07', '30.385', '31.075', '30.755', '30.855'), ('2019/01/04', '30.435', '31.125', '30.805', '30.905'), ('2019/01/03', '30.455', '31.145', '30.825', '30.925'), ('2019/01/02', '30.365', '31.055', '30.735', '30.835'), ('2018/12/28', '30.295', '30.985', '30.665', '30.765'), ('2018/12/27', '30.37', '31.06', '30.74', '30.84'), ('2018/12/26', '30.39', '31.08', '30.76', '30.86'), ('2018/12/25', '30.38', '31.07', '30.75', '30.85'), ('2018/12/24', '30.41', '31.1', '30.78', '30.88'), ('2018/12/22', '30.4', '31.09', '30.77', '30.87'), ('2018/12/21', '30.375', '31.065', '30.745', '30.845'), ('2018/12/20', '30.41', '31.1', '30.78', '30.88'), ('2018/12/19', '30.385', '31.075', '30.755', '30.855'), ('2018/12/18', '30.44', '31.13', '30.81', '30.91'), ('2018/12/17', '30.445', '31.135', '30.815', '30.915'), ('2018/12/14', '30.435', '31.125', '30.805', '30.905'), ('2018/12/13', '30.42', '31.11', '30.79', '30.89'), ('2018/12/12', '30.445', '31.135', '30.815', '30.915'), ('2018/12/11', '30.47', '31.16', '30.84', '30.94'), ('2018/12/10', '30.445', '31.135', '30.815', '30.915'), ('2018/12/07', '30.41', '31.1', '30.78', '30.88'), ('2018/12/06', '30.42', '31.11', '30.79', '30.89'), ('2018/12/05', '30.38', '31.07', '30.75', '30.85'), ('2018/12/04', '30.28', '30.97', '30.65', '30.75'), ('2018/12/03', '30.31', '31', '30.68', '30.78'), ('2018/11/30', '30.41', '31.1', '30.78', '30.88'), ('2018/11/29', '30.41', '31.1', '30.78', '30.88'), ('2018/11/28', '30.48', '31.17', '30.85', '30.95'), ('2018/11/27', '30.47', '31.16', '30.84', '30.94'), ('2018/11/26', '30.455', '31.145', '30.825', '30.925'), ('2018/11/23', '30.475', '31.165', '30.845', '30.945'), ('2018/11/22', '30.465', '31.155', '30.835', '30.935'), ('2018/11/21', '30.465', '31.155', '30.835', '30.935'), ('2018/11/20', '30.48', '31.17', '30.85', '30.95'), ('2018/11/19', '30.48', '31.17', '30.85', '30.95'), ('2018/11/16', '30.465', '31.155', '30.835', '30.935'), ('2018/11/15', '30.42', '31.11', '30.79', '30.89'), ('2018/11/14', '30.49', '31.18', '30.86', '30.96'), ('2018/11/13', '30.475', '31.165', '30.845', '30.945'), ('2018/11/12', '30.46', '31.15', '30.83', '30.93'), ('2018/11/09', '30.38', '31.07', '30.75', '30.85'), ('2018/11/08', '30.275', '30.965', '30.645', '30.745'), ('2018/11/07', '30.33', '31.02', '30.7', '30.8'), ('2018/11/06', '30.35', '31.04', '30.72', '30.82'), ('2018/11/05', '30.335', '31.025', '30.705', '30.805'), ('2018/11/02', '30.3', '30.99', '30.67', '30.77'), ('2018/11/01', '30.495', '31.185', '30.865', '30.965'), ('2018/10/31', '30.535', '31.225', '30.905', '31.005'), ('2018/10/30', '30.555', '31.245', '30.925', '31.025'), ('2018/10/29', '30.57', '31.26', '30.94', '31.04'), ('2018/10/26', '30.575', '31.265', '30.945', '31.045'), ('2018/10/25', '30.565', '31.255', '30.935', '31.035'), ('2018/10/24', '30.52', '31.21', '30.89', '30.99'), ('2018/10/23', '30.54', '31.23', '30.91', '31.01'), ('2018/10/22', '30.495', '31.185', '30.865', '30.965'), ('2018/10/19', '30.53', '31.22', '30.9', '31'), ('2018/10/18', '30.53', '31.22', '30.9', '31'), ('2018/10/17', '30.41', '31.1', '30.78', '30.88'), ('2018/10/16', '30.485', '31.175', '30.855', '30.955'), ('2018/10/15', '30.5', '31.19', '30.87', '30.97'), ('2018/10/12', '30.44', '31.13', '30.81', '30.91'), ('2018/10/11', '30.68', '31.37', '31.05', '31.15')]
>>> twder.specify_month('USD', 2018, 10) #查詢指定月份收盤價
[('2018/10/31', '30.535', '31.225', '30.905', '31.005'), ('2018/10/30', '30.555', '31.245', '30.925', '31.025'), ('2018/10/29', '30.57', '31.26', '30.94', '31.04'), ('2018/10/26', '30.575', '31.265', '30.945', '31.045'), ('2018/10/25', '30.565', '31.255', '30.935', '31.035'), ('2018/10/24', '30.52', '31.21', '30.89', '30.99'), ('2018/10/23', '30.54', '31.23', '30.91', '31.01'), ('2018/10/22', '30.495', '31.185', '30.865', '30.965'), ('2018/10/19', '30.53', '31.22', '30.9', '31'), ('2018/10/18', '30.53', '31.22', '30.9', '31'), ('2018/10/17', '30.41', '31.1', '30.78', '30.88'), ('2018/10/16', '30.485', '31.175', '30.855', '30.955'), ('2018/10/15', '30.5', '31.19', '30.87', '30.97'), ('2018/10/12', '30.44', '31.13', '30.81', '30.91'), ('2018/10/11', '30.68', '31.37', '31.05', '31.15'), ('2018/10/09', '30.54', '31.23', '30.91', '31.01'), ('2018/10/08', '30.505', '31.195', '30.875', '30.975'), ('2018/10/05', '30.405', '31.095', '30.775', '30.875'), ('2018/10/04', '30.36', '31.05', '30.73', '30.83'), ('2018/10/03', '30.24', '30.93', '30.61', '30.71'), ('2018/10/02', '30.245', '30.935', '30.615', '30.715'), ('2018/10/01', '30.11', '30.8', '30.48', '30.58')]
嗯, 大功告成!
總結以上經驗, 樹莓派安裝 twder 的程序是 :
$ sudo apt-get install libxml2-dev libxslt-dev (相依套件)
$ pip3 install twder (比較久)
或安裝好 libxml2 與 libxslt 後編譯 twder 原始碼 :
$ wget https://files.pythonhosted.org/packages/d9/f6/c8c8683aa1c3599d0168bb9476d94af43f0248c0be86b53e2c796614a120/twder-0.1.4.tar.gz (下載原始碼)
$ tar -xvf twder-0.1.4.tar.gz (解壓縮)
$ cd twder-0.1.4 (切換目錄)
$ sudo python3 setup.py install (安裝)
總結以上經驗, 樹莓派安裝 twder 的程序是 :
$ sudo apt-get install libxml2-dev libxslt-dev (相依套件)
$ pip3 install twder (比較久)
或安裝好 libxml2 與 libxslt 後編譯 twder 原始碼 :
$ wget https://files.pythonhosted.org/packages/d9/f6/c8c8683aa1c3599d0168bb9476d94af43f0248c0be86b53e2c796614a120/twder-0.1.4.tar.gz (下載原始碼)
$ tar -xvf twder-0.1.4.tar.gz (解壓縮)
$ cd twder-0.1.4 (切換目錄)
$ sudo python3 setup.py install (安裝)
沒有留言:
張貼留言