create account

PythonによるSteemSQLの利用方法 by shogo

View this thread on: hive.blogpeakd.comecency.com
· @shogo · (edited)
$4.35
PythonによるSteemSQLの利用方法
こんにちは、 @shogoです。

本日はPythonによるSteemSQLの利用方法について書いてみます。

日本語情報はなく、ほんの少し大変なので参考になりましたら幸いです。

# [SteemSQL](https://steemsql.com/)

<center>
![steemsql.PNG](https://cdn.steemitimages.com/DQmT7QDBhrQQTmb3tjUWKFaCFMrRyyCRxM34rKkiLHtg4Zu/steemsql.PNG)
</center>

以前は無料で使えたのですが、現在はサブスクリプションモデルに移行しました。

10SBD/月 OR 1SBD/日 を選ぶことができます。

<center>
![steemsql1.PNG](https://cdn.steemitimages.com/DQmT3aGj26nj858YyrefkrKHwdLJSim6iacUTt7SrEWXmkY/steemsql1.PNG)
</center>

登録方法は簡単で、 @steemsqlにSBDを送るだけです。

メモは必要ありません。

<center>
![steemsql2.PNG](https://cdn.steemitimages.com/DQmaK3yDyMfkmvXN5bYaB8DinDRBXoAiciiKugSd1bbg9ja/steemsql2.PNG)
</center>

<center>
![steemsql3.PNG](https://cdn.steemitimages.com/DQmSxvvc8146J3LiimxS5eEZp7n2opcJPb4UcFSiNxqyxoy/steemsql3.PNG)
</center>

送信後、すぐに0.001SBDが返ってきます。

メモに、サーバー名、データベース名、ユーザーID、パスワードが記載されているので保存しておきます。

<center>
![Inkedsteemsql5_LI.jpg](https://cdn.steemitimages.com/DQmU4JFMvUqSry5ntB98PcxBnLfFsMDtwFkGYqt5xGycVHC/Inkedsteemsql5_LI.jpg)
</center>

### 準備

① ODBCドライバーをインストールします。

https://docs.microsoft.com/ja-jp/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-2017

② pypyodbcを次のコマンドでInstallします。

```
pip install pypyodbc
```

<br>
以下は[こちら](https://steemsql.com/steemsql-for-python-programmers/)に記載されている、SteemSQLに接続するサンプルコードです。

サーバー名、データベース名、ユーザーID、パスワードを送られてきたメモ通りに入力します。

### connect.py
```
import pypyodbc

connection = pypyodbc.connect('Driver={ODBC Driver 13 for SQL Server};'
                              'Server=************;'
                              'Database=**********;'
                              'uid=***************;pwd=****************')

cursor = connection.cursor()
SQLCommand = ("SQLクエリを入力する(Microsoft SQL)”)

cursor.execute(SQLCommand)

connection.close()
```

<br>
次は、実際にクエリを書いてみます。

### example.py
```
import pypyodbc
import pprint

connection = pypyodbc.connect('Driver={ODBC Driver 13 for SQL Server};'
                              'Server=***************;'
                              'Database=************;'
                              'uid=******************;pwd=*******************')

cursor = connection.cursor()
SQLCommand = ("SELECT author, permlink FROM TxVotes WHERE voter = 'shogo';")

result = cursor.execute(SQLCommand)
result = result.fetchmany(100)
pprint.pprint(result)

connection.close()
```

###  実行結果

<center>
![result.PNG](https://cdn.steemitimages.com/DQmb2AgQzBWMH5oyuBxycJp2T5B67gw6pKQXwvM6XN2Y5Kz/result.PNG)
</center>

---

いかがでしたでしょうか??

細かいところは端折りましたが、分からない部分が御座いましたらご連絡ください!

Steem On!, @shogo
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 3 others
properties (23)
authorshogo
permlinkpython-steemsql
categoryjapanese
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["japanese","busy","steem","steemit","steemsql"],"users":["shogo","steemsql"],"links":["/@shogo","https://steemsql.com/","/@steemsql","https://docs.microsoft.com/ja-jp/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-2017","https://steemsql.com/steemsql-for-python-programmers/","/@shogo"],"image":["https://cdn.steemitimages.com/DQmT7QDBhrQQTmb3tjUWKFaCFMrRyyCRxM34rKkiLHtg4Zu/steemsql.PNG","https://cdn.steemitimages.com/DQmT3aGj26nj858YyrefkrKHwdLJSim6iacUTt7SrEWXmkY/steemsql1.PNG","https://cdn.steemitimages.com/DQmaK3yDyMfkmvXN5bYaB8DinDRBXoAiciiKugSd1bbg9ja/steemsql2.PNG","https://cdn.steemitimages.com/DQmSxvvc8146J3LiimxS5eEZp7n2opcJPb4UcFSiNxqyxoy/steemsql3.PNG","https://cdn.steemitimages.com/DQmU4JFMvUqSry5ntB98PcxBnLfFsMDtwFkGYqt5xGycVHC/Inkedsteemsql5_LI.jpg","https://cdn.steemitimages.com/DQmb2AgQzBWMH5oyuBxycJp2T5B67gw6pKQXwvM6XN2Y5Kz/result.PNG"]}
created2018-12-08 17:42:06
last_update2018-12-08 17:54:18
depth0
children4
last_payout2018-12-15 17:42:06
cashout_time1969-12-31 23:59:59
total_payout_value3.422 HBD
curator_payout_value0.930 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,519
author_reputation63,776,063,283,749
root_titlePythonによるSteemSQLの利用方法
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id76,553,092
net_rshares7,396,507,719,812
author_curate_reward""
vote details (67)
@fukako ·
$0.04
なるほど!
ありがとうショウゴくん<3
まだまだですけど、めっちゃ参考になるの
👍  
properties (23)
authorfukako
permlinkre-shogo-python-steemsql-20181208t194243201z
categoryjapanese
json_metadata{"tags":["japanese"],"app":"steemit/0.1"}
created2018-12-08 19:42:42
last_update2018-12-08 19:42:42
depth1
children1
last_payout2018-12-15 19:42:42
cashout_time1969-12-31 23:59:59
total_payout_value0.028 HBD
curator_payout_value0.009 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length39
author_reputation26,713,387,748,220
root_titlePythonによるSteemSQLの利用方法
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id76,557,100
net_rshares62,080,711,716
author_curate_reward""
vote details (1)
@shogo ·
参考になったら嬉しいです!!
僕もまだまだですが、勉強します :)
properties (22)
authorshogo
permlinkre-fukako-re-shogo-python-steemsql-20181209t072816019z
categoryjapanese
json_metadata{"tags":["japanese"],"app":"steemit/0.1"}
created2018-12-09 07:28:18
last_update2018-12-09 07:28:18
depth2
children0
last_payout2018-12-16 07:28:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length33
author_reputation63,776,063,283,749
root_titlePythonによるSteemSQLの利用方法
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id76,576,543
net_rshares0
@sho-t ·
ありがとうございます!
参考になります!

ちなみに、Steem Trackedというのも気になっているのですが、リンクが切れてしまっているようです^^;
https://steemit.com/@steemtracked
properties (22)
authorsho-t
permlinkre-shogo-python-steemsql-20181209t083842094z
categoryjapanese
json_metadata{"tags":["japanese"],"links":["https://steemit.com/@steemtracked"],"app":"steemit/0.1"}
created2018-12-09 08:38:42
last_update2018-12-09 08:38:42
depth1
children1
last_payout2018-12-16 08:38:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length111
author_reputation4,284,977,069,948
root_titlePythonによるSteemSQLの利用方法
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id76,578,532
net_rshares0
@shogo ·
ありがとうございます :)
Steem Trackedは初めて知りました!
少し触ってみたかったです :D
properties (22)
authorshogo
permlinkre-sho-t-re-shogo-python-steemsql-20181210t151014329z
categoryjapanese
json_metadata{"tags":["japanese"],"app":"steemit/0.1"}
created2018-12-10 15:10:15
last_update2018-12-10 15:10:15
depth2
children0
last_payout2018-12-17 15:10:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length53
author_reputation63,776,063,283,749
root_titlePythonによるSteemSQLの利用方法
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id76,641,214
net_rshares0