Last active
October 29, 2016 05:24
-
-
Save aweekj/1d33d3ad5e0d874f54241593c05ccf69 to your computer and use it in GitHub Desktop.
Twitter Bot Tutorial (1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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!") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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