Coder Social home page Coder Social logo

twitter_bot_test's Introduction

bot_test

일정 주기로 텍스트 파일에서 한 줄을 읽어 트윗을 올리는 프로그램을 만들어보기로 했다. python 모듈 tweepy를 이용하였다.

참고 문서:

tweepy 설치

pip install tweepy

가상환경을 설정했는지 안 했는지 모르겠다.

아마 귀찮아서 안 한 거 같은데...

얼마전에 컴퓨터 밀어서 아무것도 안 깔려있으니 걱정 노노 (아마도)

api 얻기

https://developer.twitter.com/en

이 부분이 귀찮았는데 영어를 열심히 읽으면서 따라가면 되는 듯하다

해당 계정은 전화번호와 이메일이 등록된 상태여야 하고,

이 앱을 어디에 쓸지 영어로 100자 정도 작문해야 한다. 몇번 해야하니까 똑같은 말을 복붙할 수 있도록 준비하면 편할듯

코드 작성

tweepy와 관련된 기능은 거의 쓰지 않았다.

api = tweepy.API() #api 받아오기
api.update_status("문자열") #해당 문자열을 트윗 작성

오랜만에 파일입출력을 복습했다... 해당 파일은 커밋하겠음

그래서... 이제 다 했다.

thisbot.py를 실행하면 랜덤하게 한 줄을 작성해준다.

6/11 추가: 텍스트파일 내부에서 \n를 직접 입력하는 것으로 줄바꿈도 인식한다.

cron으로 작업 예약하기

일정한 시간마다 thisbot.py를 실행시키기 위해 작업 스케줄러를 알아보았다.

윈도우 기본 작업 스케줄러보다 cron을 써서 한다고 해서 깔았음.

상기 링크 참고.

cron은 유닉스 계열에서 쓰는 건데 이걸 윈도우에서 돌아가게 한 프로그램이 nncron

라이트 버전을 깔아준다. 라이트 버전은 프리웨어.

워드패드를 관리자 권한으로 실행해 cron.tab을 수정해준다.

* * * * * C:\Users\00_ma\AppData\Local\Programs\Python\Python38-32\python.exe C:\Users\00_ma\AppData\Local\Programs\Python\Python38-32\tweepy-bots\bots\thisbot.py

테스트를 위해 매 분 마다 실행시켜줌.

컴퓨터에서 파이썬 프로그램 창이 잠깐 켜졌다가 꺼지는 것을 확인함.

상대경로 문제

저렇게까지 했는데 cron으로 프로그램이 실행되면 안 되어서 헤맸다.

그리고 오류 메시지인지 뭐가 줄줄 뜨기는 하는데 킹받게 안보여주고 바로 꺼지는거 ㅎㅎ;;

cmd에서 해당 파일을 실행해본 결과, data.txt 파일의 path 문제라는 걸 알았다. 뭐 파일 내부에서 os 모듈로 경로를 옮기던가 해야 하나봄...

더 머리쓰기 귀찮아서 절대경로로 때려박음

그 결과 잘 작동하고 있습니다. 끝.

발전가능성

프로그램을 작동시킬 때마다 txt에서 리스트를 만들어내므로 효율이 떨어진다.

외부 파일로 리스트를 저장하고 그걸 불러올 수도 있을 것 같다.

twitter_bot_test's People

Contributors

0008mari avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.