[개발] 스몬 카드 투자[15] 시간동기화, 파일리스트, 실행시 인자 그리고 스몬 API들 by tradingideas

View this thread on steempeak.com
· @tradingideas · (edited)
$21.88
[개발] 스몬 카드 투자[15] 시간동기화, 파일리스트, 실행시 인자 그리고 스몬 API들
휴일이었던 어제 파이썬 공부를 했습니다. 현재 스몬에 대하여 집중적으로 연구 중인데요. 그동안 찾은 API 들과 지금 개발 중인 프로젝트에 필요한 몇몇 기능을 구현하는 방법을 기술합니다.

### 스몬 API들

- 계정 정보
. https://steemmonsters.com/players/balances?username=tradingideas
![](https://cdn.steemitimages.com/DQmPLoMTvs6Ex9N1brdfoSEtoyUpRyBgh4FAdL1qDHLmGtQ/image.png)

. https://steemmonsters.com/players/details?name=tradingideas

- 게임 정보
. 계정의 최근 게임 정보 : https://steemmonsters.com/battle/history?player=tradingideas
. 특정 게임의 정보 : https://steemmonsters.com/battle/result?id=trx_id

- 토너먼트 리스트
  . 앞으로 있을 토너먼트 : https://steemmonsters.com/tournaments/upcoming
  . 현재 진행 중인 토너먼트 : https://steemmonsters.com/tournaments/in_progress
  . 끝난 토너먼트 : https://steemmonsters.com/tournaments/completed

- 카드 정보
 . 개별 카드 정보 : https://steemmonsters.com/cards/get_details
 . 특정인 보유 카드 : https://steemmonsters.com/cards/collection/tradingideas
 . 마켓정보 : https://steemmonsters.com/market/for_sale

- 기타
. 스팀, 스달, DEC 최신 가격: https://steemmonsters.com/purchases/settings

### 시간 동기화
게임은 실시간으로 동작하기 때문에 동작하는 컴퓨터의 시각이 정확해야 합니다. 컴퓨터의 시각이 정확할 것이라고 생각하시겠지만 의외로 틀립니다. 빠르기도 하고, 느리기도 합니다. 그래서 주기적으로 time server와 동기를 시켜주어야 합니다.

현재 본인의 컴퓨터가 표준시와 비교하여 어떤 상태인지는 아래 사이트에 가보시면 확인이 가능합니다.
https://time.is

![](https://cdn.steemitimages.com/DQmeAEh2d8kM2qmJm9i7kDsGzWCtqhBnC3GLcmhu9WVfzkt/image.png)

조금 전에 time server와 동기화를 해서 그런지 거의 맞군요. 만약 time server와 차이가 많이 난다면 동기화를 시키시기 바랍니다.

ms-windows를 사용하는 경우에는 아래 그림과 같이 날짜/시간 변경을 하는 곳에서 동기화를 시킬 수 있습니다. 인터넷 시간 서버와 동기화가 설정되어 있다면 주기적으로 시각을 맞춰 줍니다.
![](https://cdn.steemitimages.com/DQmamqbxHAB2PFjq12YeRsFwBkNcGNxQWX66wKrwjdRZ8Mf/image.png)

윈도우에서 주기적으로 맞춰주고 있더라도 순간적으로 시간이 틀릴 수 있습니다. 따라서 프로그램 내부에서 주기적으로 시간이 맞는지 확인하는 부분이 필요합니다.

time server와 연동을 위해서는 ntplib package를 이용하면 됩니다.
response.offset 부분에 현재 컴퓨터와 time server와의 시간차에 대한 정보가 들어있습니다.

~~~
import ntplib
from time import ctime
import time
from datetime import datetime

# https://stackoverflow.com/questions/36500197/python-get-time-from-ntp-server
def test_time() :
    c = ntplib.NTPClient()
    response = c.request('pool.ntp.org', version=3)
    
    print ("차이", response.offset, ctime(response.tx_time), response.tx_time)

~~~

### 폴더 내 파일 이름 얻기

지금 개발하고 있는 프로젝트는 폴더에 있는 파일을 많이 있습니다. 폴더에 있는 파일명을 정확하게 아는 경우에는 아는 이름을 사용하면 되지만, 불특정 파일들을 읽어들이기 위해서는 폴더에 있는 파일 명 전체를 읽을 수 있어야 합니다.

glob라는 패키를 사용하여 파일 명을 읽어올 수 있습니다. 폴더 아래에 있는 다른 폴더에 있는 파일명을 읽고 싶은 경우에는  recursive=True 옵션을 주면 되는군요. 유용하게 사용하고 있습니다.

~~~
import glob

def test_files_in_dir() :
    for filename in glob.glob('*.py'): 
        print(filename)

    for filename in glob.iglob('**/*.py', recursive=True): 
        print(filename)
~~~

### 실행 시 인자 받기
파이썬 프로그램을 실행할 때 인자를 받을 수 있으면 동일한 프로그램을 여러 계정에 대하여 사용할 수 있습니다.

제가 하고 싶은 것은 아래와 같이 실행을 하면 인자로 전달한 계정에 대하여 실행하는 것입니다.

pythontest.exe --acc tradingideas

만약 인자가 정의된 것이 아니면 사용법을 출력해주는군요. 실행 예는 아래와 같습니다.
![](https://cdn.steemitimages.com/DQmS6nJYQCFbSULXeVQGj6CqtWbSjtg92ZxA7G4WVuty4CW/image.png)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 255 others
👎  ,
properties (23)
post_id80,579,879
authortradingideas
permlink15-api
categorysct
json_metadata{"tags":["sct","sct-kr","sct-freeboard","s","union","spt","jjm","zzan","liv"],"image":["https:\/\/cdn.steemitimages.com\/DQmPLoMTvs6Ex9N1brdfoSEtoyUpRyBgh4FAdL1qDHLmGtQ\/image.png","https:\/\/cdn.steemitimages.com\/DQmeAEh2d8kM2qmJm9i7kDsGzWCtqhBnC3GLcmhu9WVfzkt\/image.png","https:\/\/cdn.steemitimages.com\/DQmamqbxHAB2PFjq12YeRsFwBkNcGNxQWX66wKrwjdRZ8Mf\/image.png","https:\/\/cdn.steemitimages.com\/DQmS6nJYQCFbSULXeVQGj6CqtWbSjtg92ZxA7G4WVuty4CW\/image.png"],"links":["https:\/\/steemmonsters.com\/players\/balances?username=tradingideas","https:\/\/steemmonsters.com\/players\/details?name=tradingideas","https:\/\/steemmonsters.com\/battle\/history?player=tradingideas","https:\/\/steemmonsters.com\/battle\/result?id=trx_id","https:\/\/steemmonsters.com\/tournaments\/upcoming","https:\/\/steemmonsters.com\/tournaments\/in_progress","https:\/\/steemmonsters.com\/tournaments\/completed","https:\/\/steemmonsters.com\/cards\/get_details","https:\/\/steemmonsters.com\/cards\/collection\/tradingideas","https:\/\/steemmonsters.com\/market\/for_sale","https:\/\/steemmonsters.com\/purchases\/settings","https:\/\/time.is"],"app":"steemcoinpan\/0.1","format":"markdown","canonical_url":"https:\/\/www.steemcoinpan.com\/@tradingideas\/15-api"}
created2019-10-04 08:30:36
last_update2019-10-04 11:07:03
depth0
children7
net_rshares75,740,791,196,469
last_payout2019-10-11 08:30:36
cashout_time1969-12-31 23:59:59
total_payout_value9.419 SBD
curator_payout_value12.461 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length2,888
author_reputation3,130,080,850,260,488
root_title"[개발] 스몬 카드 투자[15] 시간동기화, 파일리스트, 실행시 인자 그리고 스몬 API들"
beneficiaries
0.
accountsct.krwp
weight3,000
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (321)
@jsquare ·
jcar토큰 10월 구독신청감사합니다. ^^
즐거운 하루 되세요.  
properties (22)
post_id80,580,270
authorjsquare
permlinkre-15-api-20191004t085444z
categorysct
json_metadata{"app":"rewarding\/0.1.5"}
created2019-10-04 08:54:48
last_update2019-10-04 08:54:48
depth1
children0
net_rshares0
last_payout2019-10-11 08:54:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length41
author_reputation1,154,043,614,241,513
root_title"[개발] 스몬 카드 투자[15] 시간동기화, 파일리스트, 실행시 인자 그리고 스몬 API들"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@fur2002ks ·
> 현재 스몬에 대하여 집중적으로 연구 중인데

연구까지 필요한 스몬... 안하길 잘했...ㅋㅋ 열정이 대단하십니다^^
properties (22)
post_id80,580,409
authorfur2002ks
permlinkpyuegt
categorysct
json_metadata{"app":"steemit\/0.1"}
created2019-10-04 09:02:57
last_update2019-10-04 09:02:57
depth1
children1
net_rshares0
last_payout2019-10-11 09:02:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length66
author_reputation1,183,949,922,229,304
root_title"[개발] 스몬 카드 투자[15] 시간동기화, 파일리스트, 실행시 인자 그리고 스몬 API들"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@tradingideas ·
ㅎㅎ 이게 참 쉽지가 않네요.
properties (22)
post_id80,582,472
authortradingideas
permlinkpyuk6e
categorysct
json_metadata{"tags":["sct"],"app":"steemcoinpan\/0.1","canonical_url":"https:\/\/www.steemcoinpan.com\/@tradingideas\/pyuk6e"}
created2019-10-04 11:06:15
last_update2019-10-04 11:06:15
depth2
children0
net_rshares0
last_payout2019-10-11 11:06:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length16
author_reputation3,130,080,850,260,488
root_title"[개발] 스몬 카드 투자[15] 시간동기화, 파일리스트, 실행시 인자 그리고 스몬 API들"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@virus707 ·
Thank you for your continued support towards JJM. For each 1000 JJM you are holding, you can get an additional 1% of upvote. 10,000JJM would give you a 11% daily voting from the 700K SP virus707 account.
properties (22)
post_id80,586,131
authorvirus707
permlinkre-15-api-1570198088
categorysct
json_metadata{"tags":["jjm"]}
created2019-10-04 14:08:09
last_update2019-10-04 14:08:09
depth1
children0
net_rshares0
last_payout2019-10-11 14:08:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length203
author_reputation969,765,359,108,248
root_title"[개발] 스몬 카드 투자[15] 시간동기화, 파일리스트, 실행시 인자 그리고 스몬 API들"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@lovelyyeon.sct ·
오~ 승률과 바로 연결되는 연구면 신나실것 같아요~ 화이팅입니다!! ^^
properties (22)
post_id80,598,098
authorlovelyyeon.sct
permlinkpyvft3
categorysct
json_metadata{"tags":["sct"],"app":"steemcoinpan\/0.1","canonical_url":"https:\/\/www.steemcoinpan.com\/@lovelyyeon.sct\/pyvft3"}
created2019-10-04 22:29:30
last_update2019-10-04 22:29:30
depth1
children0
net_rshares0
last_payout2019-10-11 22:29:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length40
author_reputation489,778,819,368,445
root_title"[개발] 스몬 카드 투자[15] 시간동기화, 파일리스트, 실행시 인자 그리고 스몬 API들"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@steem-ua ·
#### Hi @tradingideas!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your **UA** account score is currently 4.398 which ranks you at **#2480** across all Steem accounts.
Your rank has not changed in the last three days.

In our last Algorithmic Curation Round, consisting of 115 contributions, your post is ranked at **#23**.
##### Evaluation of your UA score:

* Some people are already following you, keep going!
* The readers like your work!
* Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!


**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
post_id80,600,868
authorsteem-ua
permlinkre-15-api-20191005t015421z
categorysct
json_metadata{"app":"beem\/0.21.0"}
created2019-10-05 01:54:24
last_update2019-10-05 01:54:24
depth1
children0
net_rshares0
last_payout2019-10-12 01:54:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length702
author_reputation23,203,609,903,979
root_title"[개발] 스몬 카드 투자[15] 시간동기화, 파일리스트, 실행시 인자 그리고 스몬 API들"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@goodhello ·
오~ 시간 동기화!! 이건 생각도 못했네요... 

저도 참고하도록 하겠습니다~
properties (22)
post_id80,603,435
authorgoodhello
permlinkpyvxas
categorysct
json_metadata{"tags":["sct"],"app":"steemcoinpan\/0.1","canonical_url":"https:\/\/www.steemcoinpan.com\/@goodhello\/pyvxas"}
created2019-10-05 04:47:15
last_update2019-10-05 04:47:15
depth1
children0
net_rshares0
last_payout2019-10-12 04:47:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length44
author_reputation2,761,284,220,511,127
root_title"[개발] 스몬 카드 투자[15] 시간동기화, 파일리스트, 실행시 인자 그리고 스몬 API들"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000