안녕하세요. 굳헬로 @goodhello 입니다.
오늘은 아들님 방학식 하는 날이라... 수업도 없고, 급식도 없어서, 학교 마치고 학원 가야 하는 시간 사이 공백이 있어, 아들님 모시고 점심 식사 챙겨 드리고, 학원 보내주느라 정신 없는 오전 시간을 보내었네요.
그럼 오늘도 열심히 프로그래밍 공부해서 일기를 남겨보도록 하겠습니다.
이제 프로그램일기 시작한지도 1주일이 되었는데요.
그동안 다른 사람의 예제만 살펴 보았는데, 이제 처음으로 직접 코드를 짜보도록 하겠습니다.
어제는 스팀엔진 토큰들을 클레임 하는 예제를 살펴 보았는데요.
scot-api.steem-engine.com
을 통하여 사용자의 pending_token
정보를 가지고 와서 출력해주고, 포스팅 키를 입력하면 모든 토큰을 클레임 해주는 코드였습니다.
하지만 이 예제는 일일이 수동으로 작업을 시켜줘야만 일을 하는 코드이지요.
오늘은 주기적으로 원하는 시간에 이 코드가 실행되게 하여, 클레임 할 토큰이 있으면 자동으로 클레임 하는 코드를 직접 만들어 보도록 하겠습니다.
먼저 코드를 작성하고 코드가 주기적으로 실행이 될 수 있도록 해주는 예제를 살펴 보겠습니다.
파이썬에서는 코드를 주기적으로 실행을 할 수 있도록 지원해주는 명령어가 여러개 있습니다.
그 중에서 저는 time과 while 반복문을 이용해서 작업을 계속 수행 시켜 보겠습니다.
import time
def run():
while True:
print("무한 반복 작업중...")
time.sleep(10)
if __name__ == '__main__':
run()
run() 함수를 실행 시키면 while 반복문이 계속 작동되게 되는 예제입니다.
while은 조건을 만족하는동안 작업을 수행하는 반복문인데, while True:
구문때문에 작업을 멈출때까지 무한 반복 작업을 수행하게 됩니다.
그리고 time.sleep(10)
는 10초동안 쉬라는 명령입니다.
따라서 이 예제를 실행시키면 print("무한 반복 작업중...")
을 수행하고 10초를 쉬면서 계속 print("무한 반복 작업중...") 구문이 반복 동작되게 됩니다.
위 코드를 조금 수정하여 시간도 같이 출력되게 만들어 보겠습니다.
import time
def run():
while True:
print(time.strftime('%Y-%m-%d %HH:%MM:%SS', time.localtime(time.time())))
print("무한 반복 작업중...")
time.sleep(10)
if __name__ == '__main__':
run()
앞의 예제에 time.strftime('%Y-%m-%d %HH:%MM:%SS', time.localtime(time.time()))
현재 시간을 출력하는 코드를 추가하였습니다.
그 결과 10초마다 현재시간과 무한 반복 작업중이 출력되는걸 확인할 수 있게 되었습니다.
그럼 이번에는 어제 공부했던 스팀엔진 토큰들을 클레임 하는 예제를 함수로 만들어 무한 반복 작업을 돌려 보도록 하겠습니다.
어제의 예제는 계정명과 포스팅키를 따로 입력 받아서 클레임을 수행하였지만, 오늘은 바로 본인 계정의 토큰을 클레임 할 수 있도록 미리 계정 정보를 코드에 넣어서 작업을 수행하여 보겠습니다.
import time
from beem import Steem
from beem.nodelist import NodeList
import json
import requests
def scot_claim_token():
username = "goodhello"
url = "http://scot-api.steem-engine.com/@" + username
r = requests.get(url)
result = r.json()
json_data = []
for token in result:
scot = result[token]
if int(scot["pending_token"]) > 0:
json_data.append({"symbol": token})
print("%s can be claimed" % (token), scot["pending_token"])
break
if len(json_data) > 0:
nodes = NodeList()
nodes.update_nodes()
stm = Steem(nodes.get_nodes())
pwd = "posting key"
try:
stm.unlock(pwd)
except:
stm = Steem(node=nodes.get_nodes(), keys=[pwd])
stm.custom_json("scot_claim_token", json_data, required_posting_auths=[username])
print("%s has been claimed" % (json_data[0]['symbol']))
else:
print("Nothing to claim")
def run():
while True:
print(time.strftime('%Y-%m-%d %HH:%MM:%SS', time.localtime(time.time())))
scot_claim_token()
print("무한 반복 작업중...")
time.sleep(60)
if __name__ == '__main__':
run()
제가 만든 코드는 토큰을 클레임 하는 scot_claim_token()
함수를 생성하여 1분마다 scot_claim_token()
함수를 호출함으로써 클레임 할 토큰이 있는지 검사하고 클레임 할 토큰이 있으면 클레임을 수행하고, 그리고 1분 뒤 다시 클레임 할 토큰이 있는지 검사를 다시 수행하는 작업을 무한 반복하는 코드입니다.
한번에 모든 토큰 검사를 끝내고 클레임을 해버리면 심심할 것 같기에 이번 예제에서는 클레임 가능한 토큰을 하나씩만 찾아서 클레임 하고 1분뒤 다시 수행하는 방식을 채택하였습니다.
그럼 코드를 좀 더 자세하게 살펴보겠습니다.
def scot_claim_token():
어제 공부했던 토큰 클레임 코드를 함수로 정의 하였습니다.
username = "goodhello"
url = "http://scot-api.steem-engine.com/@" + username
r = requests.get(url)
result = r.json()
어제는 사용자로부터 계정이름을 입력 받았지만, 이번에는 본인 계정명을 바로 입력하여 즉시 수행이 가능하도록 수정하였습니다.
본인의 계정으로 작업하실때면 username
에 본인 계정명을 넣으시면 됩니다.
for token in result:
scot = result[token]
if int(scot["pending_token"]) > 0:
json_data.append({"symbol": token})
print("%s can be claimed" % (token), scot["pending_token"])
break
클레임 할 토큰이 있는지 여부를 검사하는 코드입니다.
어제는 모든 클레임 가능한 토큰들을 찾아내어 한번에 클레임을 수행하였지만, 오늘은 클레임 가능한 토큰이 하나라도 있으면, for 반복문을 빠져 나와 그 토큰만 클레임 하도록 수정하였습니다.
if len(json_data) > 0:
nodes = NodeList()
nodes.update_nodes()
stm = Steem(nodes.get_nodes())
pwd = "posting key"
try:
stm.unlock(pwd)
except:
stm = Steem(node=nodes.get_nodes(), keys=[pwd])
stm.custom_json("scot_claim_token", json_data, required_posting_auths=[username])
print("%s has been claimed" % (json_data[0]['symbol']))
else:
print("Nothing to claim")
토큰을 클레임 하는 코드입니다.
pwd
에 본인의 포스팅 키를 넣으시면 됩니다.
def run():
while True:
print(time.strftime('%Y-%m-%d %HH:%MM:%SS', time.localtime(time.time())))
scot_claim_token()
print("무한 반복 작업중...")
time.sleep(60)
if __name__ == '__main__':
run()
run() 함수를 호출하면 현재 시간이 출력되고 클레임 할 토큰이 있는지 검사하고 클레임을 수행하는 scot_claim_token()
함수를 호출하여 작업을 수행하고 60초간 휴식 뒤에 다시 scot_claim_token()
함수를 호출하여 작업을 반복하게 됩니다.
마침 스팀엔진에 클레임 할 토큰들이 많이 쌓여 있네요.
위의 예제를 실행시켜 보겠습니다.
2019년 7월 24일 15시 2분 38초에 AAA 토큰을 클레임 하였습니다.
클레임 작업이 끝난 후 60초가 지난 뒤 다음으로 2019년 7월 24일 15시 3분 53초에 ENG 토큰이 클레임 되었네요.
다음으로 LIV 토큰이 클레임되고 또 1분뒤 SCT 토큰이 클레임 되었습니다.
스팀엔진에 확인을 해보니 이제 SPT 토큰과 ZZAN 토큰이 클레임을 기다리고 있네요.
막간을 이용하여 잠시 화장실을 다녀왔더니 나머지 토큰들도 모두 클레임이 끝나고 이제 클레임 할 토큰이 없으니 Nothing to claim
을 출력하면서 무한 반복 작업을 잘 수행하고 있네요.
이제 이 코드를 멈추지 않는다면 영원시 손으로 토큰을 클레임 하는 손맛을 못 보게 될 것 같습니다.
프로그램 일기를 시작한지 이제 일주일이 되었는데, 이제까지 다른 사람의 예제만 분석하다 처음으로 직접 만든 작업을 수행 시켜보니 대단히 만족 스럽네요.
그런데 아직 부족한 점이 많습니다.
이제 다음 시간에는 코드가 실행되면서 클레임 작업이 수행되면 텔레그램으로 알림을 받는 코드를 한번 짜 보도록 하겠습니다.
그리고 그 다음에는 자동으로 토큰을 배분하는 코드도 만들어 보려고 합니다.
갈길이 멀지만 한단계 한단계 진행하다 보면 나중에는 더욱 멋지고 유용한 프로그램도 만들수 있게 되지 않을까요
그때까지 열심히 해보겠습니다.
그럼 여러분들 행복한 수요일 되세요.
굳헬로의 스팀 프로그램 일기!! 시리즈
#1 굳헬로의 스팀 프로그램 일기!! 대망의 시작 #1 Python 프로그램 설치 && steemengine 파이썬 api 설치 && 간단한 steemengine 예제
#2 굳헬로의 스팀 프로그램 일기!! 그 두번째 #2 비주얼 스튜디오 코드 프로그램 설치 && 비주얼 스튜디오 코드를 사용하여 파이썬 다루기 && 간단한 steemengine 예제
#5 굳헬로의 스팀 프로그램 일기!! 다섯번째 #5 스팀엔진 블록을 뒤져서 원하는 정보를 찾아보자!! 스팀엔진 마켓 거래 내역을 뽑아내는 예제
always1success님의 Active Bloggers #8
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
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.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
holger님이 클레임할 토큰들 한방에 할 수 있도록 수정했다고 합니다.
https://steemit.com/scot/@holger80/how-to-stake-all-scot-at-once
공부용으로는 위 코드가 좋고, 실 사용용으로는 새 방식이 좋을 것 같습니다.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
네.. 클레임이랑 스테이크 한방에 다 되는건데...
그러면 보는게 심심해 보여서 일부러 하나씩 되도록 해봤어요.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
이 코드에 원래 break 가 없고, 한번에 클레임 할 토큰들을 json_data로 만들어 한방에 처리하거든요.
한번 클레임 다 하고 나면 심심해서... 하나씩 하나씩 클레임 하면서 즐기는 거죠~ ㅎㅎㅎㅎㅎ
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @goodhello! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
To support your work, I also upvoted your post!
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
대단하십니다 저도 보고 따라하며 배워야겠어요
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
별건 없는데... 감사합니다..
하나씩 배워가는 재미가 있네요.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
이렇게 꾸준히 해내실줄은 정말 몰랐습니다. ㅋㅋ 앞으로 왠지 원클릭 종합 완성형이 나올것만 같아요. 화이팅이에요!! ^^
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
감사합니다~
계속 실력을 키워 나가야죠~
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
union.sct님의 [공지] 스판유니언 조합원 대상 8차 큐레이션 수익배분 완료 안내
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi @goodhello!
Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 3.946 which ranks you at #4247 across all Steem accounts.
Your rank has improved 30 places in the last three days (old rank 4277).
In our last Algorithmic Curation Round, consisting of 198 contributions, your post is ranked at #95.
Evaluation of your UA score:
Feel free to join our @steem-ua Discord server
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit