Skip to content

Instantly share code, notes, and snippets.

@aweekj
Last active October 29, 2016 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aweekj/1d33d3ad5e0d874f54241593c05ccf69 to your computer and use it in GitHub Desktop.
Save aweekj/1d33d3ad5e0d874f54241593c05ccf69 to your computer and use it in GitHub Desktop.
Twitter Bot Tutorial (1)
$ mkdir twitter-bot && cd twitter-bot # 폴더 생성
$ python3 -m venv env # 가상환경 셋업
$ source env/bin/activate # 가상환경 실행
(env) $ pip install —-upgrade pip # pip를 최신버전으로 업데이트(권장)
(env) $ pip install tweepy # 가상환경에 Tweepy 모듈 설치
(env) $ touch secret.py bot.py # 파이썬 파일 생성
(env) $ python bot.py
# -*- coding: utf-8 -*-
import tweepy
from secret import *
class TwitterAPI:
def __init__(self):
# Create an OAuthHandler instance
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
# Set access token
auth.set_access_token(access_token, access_token_secret)
# Create an API instance
self.api = tweepy.API(auth)
def tweet(self, message):
# Send tweet message to your timeline
self.api.update_status(status=message)
if __name__ == "__main__":
twitter = TwitterAPI()
twitter.tweet("Awesome Django Girls!")
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment