Posts

Making a table format on Discord

Image
by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/making-a-table-format-on-discord Hello, this is @joviansummer. My code revision of the automated missed-block reporter for witness Discord channel continues. After implementing mentioning(pinging) capability , I'm trying to convert reporting format to tabular form. It was requested by witness @steemchiller). On Steemit, creating a table is easy thanks to markdown table support. On Discord, unfortunately, table is not supported. Discord only supports a limited subset of markdown and table is not available. Thus, it seems the only way to make something similar is to use code block. In code block, text alignment possible because every character occupies the same width. You can see the difference from the screenshot below: Now, I need to make sure each field occupies pre-determined length. Thankfully, python provides a really useful capability called f-string. Here is an example. name = '@joviansumm

How to mention(ping) user on a Discord channel with web hook

Image
by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/how-to-mention-ping-user-on-a-discord-channel-with-web-hook Hello, this is @joviansummer. I've been providing automated hourly report of missed blocks on witness Discord channel. Considering witness @faisalamin's suggestion, I did some research and test to find out how to mention(ping) discord users when their witness nodes are missing blocks. The reporter process uses web hook to send missed blocks report. Discord's developer document for web hook is at https://discord.com/developers/docs/resources/webhook . I decided to write this post because it took me a bit of time to figure out how to ping a user. It might be of a little help for anyone interested in working with Discord web hook. When you use Discord with your web browser, mentioning someone is simple. You just type Discord username with preceding '@'. If you mention Discord user joviansummer for example, you just type @joviansu

파이썬에서 datetime.timezone()을 이용한 시간대 설정

by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/datetime-timezone 파이썬에서 datetime.timezone()을 이용해서 datetime 객체의 시간대를 설정할 수 있습니다. 예를 들어 한국시간(KST)은 GMT+9시간이므로 아래와 같이 설정해서 현재 시각을 구할 수 있습니다. import datetime KST = datetime.timezone(datetime.timedelta(hours=9)) now_kst = datetime.datetime.now(tz=KST) 시간대 정보가 없는 datetime 객체의 경우에는 앞의 예제 코드에서 정의된 변수 KST를 이용해서 아래와 같이 시간대를 할당할 수 있습니다. # 시간대 정보 없는 UTC 기준 현재시각 가져오기 - utcnow() now = datetime.datetime.utcnow() # 시간대 정보 추가 now_kst = now.astimezone(KST) @joviansummer의 스팀 프로젝트 스팀 증인노드를 운영중입니다. @jswit에 증인투표해 주시면 감사하겠습니다. ( https://steemitwallet.com/~witnesses ) jswit 증인 노드 프로젝트를 시작합니다. jsup 업보팅(upvoting) 서비스 소개 jsup 수혜자 지정 기능 추가 jsup 2.0 - 업보팅을 다시 위대하게 jSTEEM 프로젝트 - 텔레그램 챗봇으로 구현하는 스팀 블럭체인 탐색기 Steemit-Search - 스팀잇 포스팅 검색 STEEM.NFT - 디지털 아트 보존 프로젝트

파이썬에서 리스트 내용을 텍스트 파일로 저장

by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/3afmfh 파이썬에서 리스트(list) 원소 하나가 텍스트 파일의 한줄이 되도록 저장하는 방법입니다. x = ['abc', 'def', 'hij'] f = open('my_file.txt', 'w') f.write('\n'.join(x)) f.close() 줄바꿈(\n)을 기준으로 join()을 통해서 리스트의 원소를 문자열로 변환해 주었습니다. 여기서 주의할 점은 처음부터 리스트의 원소가 모두 문자열(str)이어야 한다는 점입니다. 수자 등 다른 형식이 포함되어 있으면 오류가 발생합니다. 이런 경우에는 for 반복문을 이용해서 한줄씩 문자열로 변환해서 저장해 줄 수 있습니다. x = ['abc', 'def', 'hij'] f = open('my_file.txt', 'w') for item in x: f.writelines(str(item) + '\n') f.close() @joviansummer의 스팀 프로젝트 스팀 증인노드를 운영중입니다. @jswit에 증인투표해 주시면 감사하겠습니다. ( https://steemitwallet.com/~witnesses ) jswit 증인 노드 프로젝트를 시작합니다. jsup 업보팅(upvoting) 서비스 소개 jsup 수혜자 지정 기능 추가 jsup 2.0 - 업보팅을 다시 위대하게 jSTEEM 프로젝트 - 텔레그램 챗봇으로 구현하는 스팀 블럭체인 탐색기 Steemit-Search - 스팀잇 포스팅 검색 STEEM.NFT - 디지털 아트 보존 프로젝트

파이썬에서 현재 사용중인 시스템의 시간대(timezone) 정보 확인

by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/6k7bmf-timezone 파이썬에서 현재 사용중인 시스템의 시간대(timezone) 정보를 조회할 수 있습니다. tzlocal 모듈의 get_localzone() 함수를 이용하면 간편하게 가능합니다. import tzlocal sys_tz = tzlocal.get_localzone() print(str(sys_tz)) Asia/Seoul @joviansummer의 스팀 프로젝트 스팀 증인노드를 운영중입니다. @jswit에 증인투표해 주시면 감사하겠습니다. ( https://steemitwallet.com/~witnesses ) jswit 증인 노드 프로젝트를 시작합니다. jsup 업보팅(upvoting) 서비스 소개 jsup 수혜자 지정 기능 추가 jsup 2.0 - 업보팅을 다시 위대하게 jSTEEM 프로젝트 - 텔레그램 챗봇으로 구현하는 스팀 블럭체인 탐색기 Steemit-Search - 스팀잇 포스팅 검색 STEEM.NFT - 디지털 아트 보존 프로젝트