這邊不教如何安裝,因為我根本就不想安裝…
因此我是直接啟用Heroku中的 mongoDB add-on
只要在已有專案按下 "install mlab MongoDB",很快就在雲端裝完了
可以看到 24/7 全時運作,免費版有快500MB的空間,對一般的專案使用來說很好用了
在專案的Settings中就有你的DB存取URL
把這一行放到你的專案就可以使用了!!
ok, 接著要用python連結了,我們使用pymongo來連結
要注意的是URL中的最後一個斜線 "/" 後面接著的就是你的 DB名稱,因能用這個DB名而已
因此client['db_name'] 中要填的東西是固定的
然後collection就沒有說可以存在幾個,我們就先命名一個「test_coll」放資料進去了
ok,打完收工,使用mongoDB不安裝,就是這麼簡單
ma's note
2017年8月11日 星期五
2017年8月10日 星期四
在anaconda安裝pymongo
anaconda的安裝指令為conda,安裝方式同pip
pip install pymongo
這邊我們改用
conda install pymongo
結果如下:
----
(C:\Users\Malo\Anaconda2) C:\Users\Malo>conda install pymongo
Fetching package metadata ...........
Solving package specifications: .
Package plan for installation in environment C:\Users\Malo\Anaconda2:
The following NEW packages will be INSTALLED:
pymongo: 3.4.0-py27_0
The following packages will be UPDATED:
conda: 4.3.21-py27_0 --> 4.3.24-py27_0
Proceed ([y]/n)?
pymongo-3.4.0- 100% |###############################| Time: 0:00:00 560.62 kB/s
conda-4.3.24-p 100% |###############################| Time: 0:00:04 131.37 kB/s
----
裝好了,測試如下
from pymongo import MongoClient
如果正常執行沒出錯,表示 pymongo就裝好了
pip install pymongo
這邊我們改用
conda install pymongo
結果如下:
----
(C:\Users\Malo\Anaconda2) C:\Users\Malo>conda install pymongo
Fetching package metadata ...........
Solving package specifications: .
Package plan for installation in environment C:\Users\Malo\Anaconda2:
The following NEW packages will be INSTALLED:
pymongo: 3.4.0-py27_0
The following packages will be UPDATED:
conda: 4.3.21-py27_0 --> 4.3.24-py27_0
Proceed ([y]/n)?
pymongo-3.4.0- 100% |###############################| Time: 0:00:00 560.62 kB/s
conda-4.3.24-p 100% |###############################| Time: 0:00:04 131.37 kB/s
----
裝好了,測試如下
from pymongo import MongoClient
如果正常執行沒出錯,表示 pymongo就裝好了
2017年8月8日 星期二
sqlalchemy連接mysql錯誤
要連到mysql測試如下
db_engine = create_engine('mysql://root:admin@123@localhost/testdb')
出現錯誤「ImportError: No module named MySQLdb」
是因為少了相對應的模組,安裝如下:
pip install pymysql
然後改為:
db_engine = create_engine('mysql+pymysql://root:admin@123@localhost/testdb')
就沒問題了
接著就可以create table
resultProxy = db_engine.execute("CREATE TABLE IF NOT EXISTS testdb(uuid text NOT NULL, time text NOT NULL, data text)")
插入資料:
uuid = '123456789012345'
my_time = time.strftime("%Y-%m-%d %H:%M:%S")
data = '{ "ai": [ 26, 115 ], "do": [ 1, 0 ] }'
resultProxy=db_engine.execute("insert into rtudb (uuid, time, data) values('%s', '%s', '%s')" %(uuid, my_time, data))
查資料
resultProxy=db_engine.execute("select * from rtudb where uuid = '%s' and time >= '%s'" %('123456789012345', '2017'))
userList = resultProxy.fetchall()
print(userList)
db_engine = create_engine('mysql://root:admin@123@localhost/testdb')
出現錯誤「ImportError: No module named MySQLdb」
是因為少了相對應的模組,安裝如下:
pip install pymysql
然後改為:
db_engine = create_engine('mysql+pymysql://root:admin@123@localhost/testdb')
就沒問題了
接著就可以create table
resultProxy = db_engine.execute("CREATE TABLE IF NOT EXISTS testdb(uuid text NOT NULL, time text NOT NULL, data text)")
插入資料:
uuid = '123456789012345'
my_time = time.strftime("%Y-%m-%d %H:%M:%S")
data = '{ "ai": [ 26, 115 ], "do": [ 1, 0 ] }'
resultProxy=db_engine.execute("insert into rtudb (uuid, time, data) values('%s', '%s', '%s')" %(uuid, my_time, data))
查資料
resultProxy=db_engine.execute("select * from rtudb where uuid = '%s' and time >= '%s'" %('123456789012345', '2017'))
userList = resultProxy.fetchall()
print(userList)
XAMPP5.6.31 mysql加入密碼後無法登入使用
之前都是使用XAMPP的舊版,最近改用新版發現一開始的引導設定密碼和安全性的提示不見了…
mysql也都是不用密碼就可以登入
所以一裝好一樣進到phpmyadmin去改root的密碼,改完後發現不能登入!!
它也不讓你使用密碼登入,就直接給你一個大大的錯誤畫面!!
後來找到這篇文章才解決,memo一下,下次才會記得…
==== 說明 ====
執行apache和MySQL後就點Admin開啟phpmyadmin修改密碼
mysql也都是不用密碼就可以登入
所以一裝好一樣進到phpmyadmin去改root的密碼,改完後發現不能登入!!
它也不讓你使用密碼登入,就直接給你一個大大的錯誤畫面!!
後來找到這篇文章才解決,memo一下,下次才會記得…
==== 說明 ====
執行apache和MySQL後就點Admin開啟phpmyadmin修改密碼
改好後就不能登入了
這時要修改「」檔,修改以下的部份:
/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'password';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
$cfg['Lang'] = '';
改完後,把Apache和mysql重新啟動,就可以進到phpmyadmin的登入畫面了
2017年6月14日 星期三
GCE, server2008 自動重開的問題
2017年3月20日 星期一
NodeMcu - ESP8266
總算拿到手了!
由外觀看起來chip是ESP8266MOD
接上USB後,因為CH340的USB chip, win10預設沒driver
直接選自動更新就可以取得driver,win10就是這一點好!
打開com port,發現下AT都沒反應 (115200)
按板子上的reset鍵發現是有資料出來的
如下:
??l????l,?@>?t? ?H>lt?E?@>l??? ?$?2b??? < >n ?KGaiZ CHX$?"E?? ??D?????l????l,?@:?t? ?@>?t?E?@>l??? ?$?2b??XY?
>n ?.? z h?,$? 6$`?D???{l? b??og?l'o??? # x??${l{$p?'? ? l c o?< l l??c??'o?` ? 'o $` g{???o ??l p?n? {????? c o?| ????c??g'?{??????l c g?| d?r? c??gn??$l` {l??n???gn?????{ 'og? d?c{sd?ldlg???? g??g ??ll??c ??llxc? c{???l 'd?p??d`cl d??g ?n???g$?| # l d` ;l?? ? ?o??;??g|? l l?? $??s?l?l ? l` ??{?d?l ? d` ??r?l ??ls?lb??o?? og? ?l?x l ? d??? ? ? ?d? $? '????c l ?cxsdrd
Ai-Thinker Technology Co. Ltd.
ready
後來把結尾字元改為"\r\n"就正常了
AT+GMR
AT version:1.2.0.0(Jul 1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
Ai-Thinker Technology Co. Ltd.
Dec 2 2016 14:21:16
OK
參考這邊的版本指令:
http://www.electrodragon.com/w/ESP8266_AT-Command_firmware
這邊有不少資源,但還未確認是否可用,真的很猛,連怎麼在WiFi的chip跑RTOS都有寫手冊
http://bbs.espressif.com/viewtopic.php?f=67&t=225
AT command手冊
http://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_cn.pdf
看手冊使用了幾個指令都OK,代表買回來的東西是可以用的,GOOD!
AT+RST
結果:
OK
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 1856, room 16
tail 0
chksum 0x63
load 0x3ffe8000, len 776, room 8
tail 0
chksum 0x02
load 0x3ffe8310, len 552, room 8
tail 0
chksum 0x79
csum 0x79
2nd boot version : 1.5
SPI Speed : 40MHz
SPI Mode : DIO
SPI Flash Size & Map: 32Mbit(512KB+512KB)
jump to run user1 @ 1000
?? ? ?'??{??n<? $ d?? l??;?$?d ? $` ??s?l?$ ? l` ??{?d ?? ld` ;l??;d????c d?#{| ?cp ?l?c d;?$c??g?? 'o? ?d?p $ ? l??? ? ? ?l? d? g????# $ ?cp;l{l
Ai-Thinker Technology Co. Ltd.
ready
WIFI STATION測試
AT+CWMODE_CUR=1
OK
AT+CWJAP_CUR="ABC","123456"
WIFI CONNECTED
WIFI GOT IP
OK
AT+CWLAP
+CWLAP:(3,"L.R-Foot-AA",-81,"78:44:76:97:70:80",1,16,0)
+CWLAP:(0,".1.Free Wi-Fi",-86,"70:62:b8:b7:d6:96",1,3,0)
+CWLAP:(0,"CHT Wi-Fi Auto",-88,"70:62:b8:b7:d6:90",1,3,0)
+CWLAP:(2,"P874",-80,"c8:6c:87:36:bc:79",1,-4,0)
+CWLAP:(0,"CHT Wi-Fi(HiNet)",-88,"70:62:b8:b7:d6:91",1,3,0)
+CWLAP:(0,"..YO! (Free)",-89,"70:62:b8:b7:d6:95",1,3,0)
+CWLAP:(2,"TOTOLINK N300RH",-85,"78:44:76:97:d0:74",1,20,0)
+CWLAP:(3,"8N5F2",-58,"cc:f3:a5:c6:9c:f6",11,20,0)
+CWLAP:(3,"MOTOROLA-A64B2",-63,"f8:35:dd:5d:9e:57",11,10,0)
+CWLAP:(4,"Hilda",-87,"1c:ab:c0:1d:78:f8",11,11,0)
+CWLAP:(4,"ASUS",-93,"c8:60:00:aa:c4:c0",7,28,0)
+CWLAP:(4,"D-Link_DIR-612",-91,"48:ee:0c:e4:fc:1d",11,21,0)
+CWLAP:(3,"6740C",-91,"cc:b2:55:ff:a8:39",11,3,0)
OK
AT+PING="8.8.8.8"
+56
OK
AT+PING="8.8.8.8"
+64
OK
由外觀看起來chip是ESP8266MOD
接上USB後,因為CH340的USB chip, win10預設沒driver
直接選自動更新就可以取得driver,win10就是這一點好!
打開com port,發現下AT都沒反應 (115200)
按板子上的reset鍵發現是有資料出來的
如下:
??l????l,?@>?t? ?H>lt?E?@>l??? ?$?2b??? < >n ?KGaiZ CHX$?"E?? ??D?????l????l,?@:?t? ?@>?t?E?@>l??? ?$?2b??XY?
>n ?.? z h?,$? 6$`?D???{l? b??og?l'o??? # x??${l{$p?'? ? l c o?< l l??c??'o?` ? 'o $` g{???o ??l p?n? {????? c o?| ????c??g'?{??????l c g?| d?r? c??gn??$l` {l??n???gn?????{ 'og? d?c{sd?ldlg???? g??g ??ll??c ??llxc? c{???l 'd?p??d`cl d??g ?n???g$?| # l d` ;l?? ? ?o??;??g|? l l?? $??s?l?l ? l` ??{?d?l ? d` ??r?l ??ls?lb??o?? og? ?l?x l ? d??? ? ? ?d? $? '????c l ?cxsdrd
Ai-Thinker Technology Co. Ltd.
ready
後來把結尾字元改為"\r\n"就正常了
AT+GMR
AT version:1.2.0.0(Jul 1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
Ai-Thinker Technology Co. Ltd.
Dec 2 2016 14:21:16
OK
參考這邊的版本指令:
http://www.electrodragon.com/w/ESP8266_AT-Command_firmware
這邊有不少資源,但還未確認是否可用,真的很猛,連怎麼在WiFi的chip跑RTOS都有寫手冊
http://bbs.espressif.com/viewtopic.php?f=67&t=225
AT command手冊
http://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_cn.pdf
看手冊使用了幾個指令都OK,代表買回來的東西是可以用的,GOOD!
AT+RST
結果:
OK
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 1856, room 16
tail 0
chksum 0x63
load 0x3ffe8000, len 776, room 8
tail 0
chksum 0x02
load 0x3ffe8310, len 552, room 8
tail 0
chksum 0x79
csum 0x79
2nd boot version : 1.5
SPI Speed : 40MHz
SPI Mode : DIO
SPI Flash Size & Map: 32Mbit(512KB+512KB)
jump to run user1 @ 1000
?? ? ?'??{??n<? $ d?? l??;?$?d ? $` ??s?l?$ ? l` ??{?d ?? ld` ;l??;d????c d?#{| ?cp ?l?c d;?$c??g?? 'o? ?d?p $ ? l??? ? ? ?l? d? g????# $ ?cp;l{l
Ai-Thinker Technology Co. Ltd.
ready
AT+CWMODE_CUR=1
OK
AT+CWJAP_CUR="ABC","123456"
WIFI CONNECTED
WIFI GOT IP
OK
AT+CWLAP
+CWLAP:(3,"L.R-Foot-AA",-81,"78:44:76:97:70:80",1,16,0)
+CWLAP:(0,".1.Free Wi-Fi",-86,"70:62:b8:b7:d6:96",1,3,0)
+CWLAP:(0,"CHT Wi-Fi Auto",-88,"70:62:b8:b7:d6:90",1,3,0)
+CWLAP:(2,"P874",-80,"c8:6c:87:36:bc:79",1,-4,0)
+CWLAP:(0,"CHT Wi-Fi(HiNet)",-88,"70:62:b8:b7:d6:91",1,3,0)
+CWLAP:(0,"..YO! (Free)",-89,"70:62:b8:b7:d6:95",1,3,0)
+CWLAP:(2,"TOTOLINK N300RH",-85,"78:44:76:97:d0:74",1,20,0)
+CWLAP:(3,"8N5F2",-58,"cc:f3:a5:c6:9c:f6",11,20,0)
+CWLAP:(3,"MOTOROLA-A64B2",-63,"f8:35:dd:5d:9e:57",11,10,0)
+CWLAP:(4,"Hilda",-87,"1c:ab:c0:1d:78:f8",11,11,0)
+CWLAP:(4,"ASUS",-93,"c8:60:00:aa:c4:c0",7,28,0)
+CWLAP:(4,"D-Link_DIR-612",-91,"48:ee:0c:e4:fc:1d",11,21,0)
+CWLAP:(3,"6740C",-91,"cc:b2:55:ff:a8:39",11,3,0)
OK
AT+PING="8.8.8.8"
+56
OK
AT+PING="8.8.8.8"
+64
OK
2016年11月17日 星期四
[python] imap
最近在做imap收信的功能,並把目標信件的附件存起來
沒想到發email這麼簡單,收email的處理卻是這麼的麻煩…
因為email中有太多種編碼方式了
我測試的code晚點po上來,先memo一下我找到不錯的code
https://gist.github.com/baali/2633554
沒想到發email這麼簡單,收email的處理卻是這麼的麻煩…
因為email中有太多種編碼方式了
我測試的code晚點po上來,先memo一下我找到不錯的code
https://gist.github.com/baali/2633554
訂閱:
文章 (Atom)