매일 자동 글쓰게 만들기
Dev No. 3
22.09.26. | Written by @ayogom

저는 11시가 지나도록 포스팅을 안하면, 자동으로 글을 쓰도록 만들어뒀습니다. 제 포스팅을 보시던 분이면 아래와 같이 써져있는 글을 보신적 있을 것 입니다.
바로 제가 11시가 지나도록 포스팅을 못 하여서... 자동으로 쓴 글입니다. 저는 서버를 운영하고 있기 때문에 손쉽게 했지만, 서버를 운영하지 않는다면, 저렴한 라즈베리파이 같은 것을 구입하셔서... 하나 돌려도 좋습니다. 편한게 짱입니다!
const steem = require("steem");
const cron = require('node-cron');
const author = 'ayogom'
const wif = '*****'
const parentAuthor = ''
const parentPermlink = 'hive-101145'
const jsonMetadata = {"tags":["hive-101145","sct-kr","sct-freeboard","zzan","kr","aaa","sct","krsuccess"],"app":"steemcoinpan\/0.1","format":"markdown"};
const getAccounts = async function (){
return new Promise((resolve, reject) => {
steem.api.getAccounts(['ayogom'], function(err, result) {
result = result[0].last_root_post;
result = result.split("T");
result = result[0].split("-");
resolve(result);
});
});
}
async function main(){
let lastposting = await getAccounts();
today = new Date();
year = today.getFullYear();
month = today.getMonth()+1;
day = today.getDate();
var steemtitle = '['+year+'-'+month+'-'+day+'] 임시포스팅';
var permlink = year+'-'+month+'-'+day;
var body = '안녕하세요. ayogom 입니다.\n부득이하게 일정 시간내에 포스팅을 못하게 되었습니다. 이 포스팅을 임시로 작성하고, 곧 오늘의 내용을 갱신하겠습니다'
if (lastposting[1]<month){
steem.broadcast.comment(wif, parentAuthor, parentPermlink, author, permlink, steemtitle, body, jsonMetadata, function(err, result) {
if (err != null){
console.log(err,"글작성 에러 발생");
}else {
console.log(body,result);
}
});
console.log("잔망스런 코딩1");
}else{
if (lastposting[2]<day){
steem.broadcast.comment(wif, parentAuthor, parentPermlink, author, permlink, steemtitle, body, jsonMetadata, function(err, result) {
if (err != null){
console.log(err,"글작성 에러 발생");
}else {
console.log(body,result);
}
});
console.log("잔망스런 코딩2");
}else{
console.log("잔망스런 코딩3");
}
}
}
cron.schedule('0 23 * * *', function () {
main ();
});
그냥 코드를 풀로 공개합니다.
먼저 cron.schedule
을 이용하여 매일 23시에 소스코드가 동작합니다.
그리고 getAccounts
을 통하여 마지막 포스팅 시간을 조회하고 24시간이 지났는지 체크 합니다. 그리고 지났으면 포스팅을 하게 작성되어 있습니다 ㅎㅎ 에러가 나면, 잔망스러운 코딩
이라는 단어가 나오게 됩니다 ㅋㅋㅋ 참 쉬죠? 이렇게 하면 매일 포스팅을 놓치지 않을 수 있습니다 ㅎㅎ
하지만... 다른 구독자 분들과 개인적인 기록을 위해 놓친 날짜는 다시 가서 수정하고 있습니다 ㅎㅎ
아무튼 ! 참고 하시기 바랍니다
PROS/좋은점
- 매일 포스팅을 쓰는 강박(?)을 줄일 수 있다.
CONS/아쉬운점
- 자꾸 밀릴 수 있다
Layout provided by Steemit Enhancer hommage by ayogom
안녕하세요.
SteemitKorea팀에서 제공하는 'steemit-enhancer'를 사용해 주셔서 감사합니다. 개선 사항이 있으면 언제나 저에게 연락을 주시면 되고, 관심이 있으신 분들은 https://cafe.naver.com/steemitkorea/425 에서 받아보실 수 있습니다. 사용시 @응원해 가 포함이 되며, 악용시에는 모든 서비스에서 제외될 수 있음을 알려드립니다.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
안녕하세요.
이 글은 SteemitKorea팀(@ayogom)님께서 저자이신 @ayogom님을 응원하는 글입니다.
소정의 보팅을 해드렸습니다 ^^ 항상 좋은글 부탁드립니다
SteemitKorea팀에서는 보다 즐거운 steemit 생활을 위해 노력하고 있습니다.
이 글은 다음날 다시 한번 포스팅을 통해 소개 될 예정입니다. 감사합니다!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Upvoted! Thank you for supporting witness @jswit.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
[by @ayogom] [개발] 매일 자동 글쓰게 만들기
https://www.steemit.com/@kr-dev.cu2/4xycsw
@kr-dev.cu2님이 당신을 멘션하였습니다.
멘션을 받고 싶거나 받지 않으시려면 댓글을 남겨주세요. 빠른 시일내에 반영하도록 하겠습니다.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This post has been upvoted by @italygame witness curation trail
If you like our work and want to support us, please consider to approve our witness
Come and visit Italy Community
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
Hi @ayogom,
my name is @ilnegro and I voted your post using steem-fanbase.com.
Come and visit Italy Community
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