ãPythonãFlask+Tweepyã§Twitteré£æºã¢ããªãä½ã
ãFlaskãã¨ãTweepyãã使ã£ã¦Twitteré£æºã¢ããªãä½æããæ¹æ³ãã¾ã¨ãã¾ããï¼
ã©ã¡ããPythonã§å®è£
ãããã©ã¤ãã©ãªã§ï¼Flaskã¯Webéçºãã¬ã¼ã ã¯ã¼ã¯ï¼Tweepyã¯Twitter APIã¸ã®ã¢ã¯ã»ã¹ãç°¡åã«ãã¦ãããã©ã¤ãã©ãªã§ãï¼
Flask 㨠Tweepy ã«ã¤ãã¦
Flaskã¨ã¯ï¼
å ¬å¼ãµã¤ãã®æ¥æ¬èªçããã¥ã¡ã³ãã«ããã¨ï¼
Flaskã¯ãPythonç¨ã®ãã¤ã¯ãWebéçºãã¬ã¼ã ã¯ã¼ã¯ã§ãã
Bitbucket | The Git solution for professional teams
ã¨ã®ãã¨ã§ãï¼
Webãã¬ã¼ã ã¯ã¼ã¯ã¨ããã°ï¼Railsï¼CakePHPï¼Djangoçãæåã§ããï¼ãããã¯ãã«ã¹ã¿ãã¯Webéçºãã¬ã¼ã ã¯ã¼ã¯ã¨å¼ã°ãã¦ãã¾ãï¼
ããã«ã¹ã¿ãã¯ãã¨ã¯ãå
¨é¨å
¥ããã¨ããæå³ã§ï¼Webéçºã«å¿
è¦ãªããããæ©è½ããã1ã¤ã§ã«ãã¼ãã¦ãã¾ãï¼
ãã ãï¼ãã®åå¦ç¿ã³ã¹ããé«ãæ·å±
ã¯é«ãã§ãï¼
ä¸æ¹ã§ï¼Flaskã¯Webã¢ããªã®å®è£
ã«å¿
è¦æå°éã®æ©è½ã®ã¿ã«çµã£ãã³ã³ãã¯ããªãã¬ã¼ã ã¯ã¼ã¯ã§ãï¼
æ©è½ãå¿
è¦æå°éãããªãã®ã§ï¼å¦ç¿ã³ã¹ããä½ãæ·å±
ã¯ä½ãã§ãï¼
ã¾ãï¼æå°éã¨è¨ã£ã¦ãç°¡åãªWebã¢ããªãéçºããç¨åº¦ã§ããã°ååã®æ©è½ãæã£ã¦ãã¾ãï¼
ãããããã¤ã¯ããã®æå³ããã¨ããã§ãï¼
ä»åã¯ãã®Flaskã使ã£ã¦Webã¢ããªãéçºãã¾ãï¼
Tweepyã¨ã¯ï¼
PythonããTwitter APIãç°¡åã«å©ç¨ã§ããã©ã¤ãã©ãªã§ãï¼
Twitter APIã¯ç´ ã®ã¾ã¾ä½¿ããã¨æãã¨è²ã
é¢åï¼ç¹ã«èªè¨¼å¨ãï¼ãªã®ã§ããï¼ãã®è¾ºãã©ã¤ãã©ãªå´ã§å¤§ä½ä½ã¨ããã¦ããã¾ãï¼
ä»ã«ããã®ãããªã©ã¤ãã©ãªã¯è¤æ°åå¨ãã¾ããï¼å人çã«ä¸çªãã£ããããã®ãTweepyã ã£ãã®ã§ï¼ä»åã¯ããã使ç¨ãã¾ãï¼
ãªãï¼å
¬å¼ãµã¤ãã¯ä»¥ä¸ã«ãªãã¾ãï¼
Tweepy
ç°å¢æ§ç¯
以ä¸ãã¤ã³ã¹ãã¼ã«æ¸ã¿ã§ãããã¨ãåæã«è©±ãé²ãã¾ãï¼
- Python㯠2.7.xç³» ãã¤ã³ã¹ãã¼ã«æ¸ã¿ï¼
pip
ãã¤ã³ã¹ãã¼ã«æ¸ã¿ï¼git
ãã¤ã³ã¹ãã¼ã«æ¸ã¿ï¼
Flask, Tweepyã®ã¤ã³ã¹ãã¼ã«
pip
ã§ã¤ã³ã¹ãã¼ã«ããã ãã§ãï¼
root権éã§å®è¡ãã¦ä¸ããï¼
# pip install flask # pip install tweepy
ã¾ãï¼ã¢ããªã®å®è¡ã«ä»¥ä¸ãå¿ è¦ãªã®ã§ã¤ã³ã¹ãã¼ã«ãã¦ããã¾ãï¼
# pip install gunicorn
Twitter API key ã®åå¾
以ä¸ã®ãã¼ã¸ãåèã«ãã¦ï¼Twitter API keyãåå¾ãã¾ãï¼
http://wplogs.com/twitter-apps/
ã¢ããªã±ã¼ã·ã§ã³ä½æç»é¢ (Create an application) ã§ã®å
¥åå
容ã«é¢ãã¦ã¯ä½ã§ãæ§ãã¾ããï¼
ãWebsiteãã®é
ç®ãé©å½ãªURLï¼ä¾ãã° http://twitter.com/ ï¼ãå
¥åãã¦ããã°OKã§ãï¼
ã¾ãï¼ãCallback URLããä½ã§ãããã®ã§å¿
ãå
¥åããããã«ãã¦ä¸ãã*1ï¼
ä½æãå®äºãããï¼ä¸è¨ã®ãã¼ã¸ãåèã«ãã¦ãConsumer keyãã¨ãConsumer secretããæ§ãã¦ããã¾ãï¼
Herokuå¨ã
ã¢ã«ã¦ã³ãç»é²
Herokuå ¬å¼ãµã¤ãã®ãSign upããã¿ã³ããã¢ã«ã¦ã³ãç»é²ãè¡ãã¾ãï¼
Heroku Toolbelt ã®ã¤ã³ã¹ãã¼ã«
ãHeroku Toolbeltãã¨ã¯Herokuãã¿ã¼ããã«ä¸ã§æä½ããã®ã«å¿
è¦ãªãã¼ã«ã§ãï¼
以ä¸ããã¤ã³ã¹ãã¼ã«ã§ãã¾ãï¼
ã¤ã³ã¹ãã¼ã«ããã heroku login
ã³ãã³ãã§ãã°ã¤ã³ãã¾ãï¼
ã¡ã¼ã«ã¢ãã¬ã¹ã¨ãã¹ã¯ã¼ããè¦æ±ãããã®ã§å
¥åãã¾ãï¼
$ heroku login Enter your Heroku credentials. Email: [Herokuã«ç»é²ããã¡ã¼ã«ã¢ãã¬ã¹] Password (typing will be hidden): [ãã¹ã¯ã¼ã]
ã¾ãï¼Herokuã¸ã¢ããªããããã¤ããã®ã«SSHå
¬ééµã®ç»é²ãå¿
è¦ã§ãï¼
éµãä½æãã¦ããªãå ´åã¯ä»¥ä¸ã®ããã«è¡¨ç¤ºãããã®ã§ä½æãã¦ç»é²ãã¾ãï¼
Could not find an existing public key. Would you like to generate one? [Yn] Generating new SSH public key. Uploading ssh public key /Users/hoge/.ssh/id_rsa.pub
ã¢ããªã®å®è£
ä»åä½ãã¢ããªã¯ãé£æºã¢ããªèªè¨¼ãè¡ãï¼ãã®ã¦ã¼ã¶ã¼ã®ã¿ã¤ã ã©ã¤ã³ã表示ããï¼ãã¨ãããã®ã§ãï¼
å®è£ ããã³ã¼ãã¯GitHubã«å ¬éãã¦ããã¾ãï¼
å®éã«ä»¥ä¸ã®URLã§ç¨¼åãã¦ãã¾ãï¼
https://flask-tweepy.herokuapp.com/
以ä¸ï¼Flaskã¨Tweepyã®ä½¿ãæ¹ã«è§¦ããªããã³ã¼ãã®è§£èª¬ãæ¸ãã¦ãã¾ããï¼ã¨ããããã¢ããªãåããããã¨ããæ¹ã¯ããã¼ã«ã«ã§åãããããHerokuã«å ¬éãã®é ã«ã¹ããããã¦ä¸ããï¼
ãã£ã¬ã¯ããªæ§æ
flask-tweepy âââ Procfile # Herokuä¸ã§èµ·åããã³ãã³ããè¨è¿°ãããã¡ã¤ã« âââ README.md # Readme âââ app.py # ã¢ããªæ¬ä½ âââ requirements.txt # ä¾åã©ã¤ãã©ãªãè¨è¿°ãããã¡ã¤ã« âââ static # éçãã¡ã¤ã« (ç»å, CSS, JSç) ãç½®ããã£ã¬ã¯ã㪠(ä»åã¯ä½¿ãã¾ãã) âââ templates # ã¢ããªå ã§å¼ã³åºããã³ãã¬ã¼ããç½®ããã£ã¬ã¯ã㪠âââ index.html # root ãã¼ã¸ã®ãã³ãã¬ã¼ã
å®éã«ã³ã¼ããæ¸ãã®ã¯ app.py
㨠templates/index.html
ã®2ã¤ã§ãï¼
app.py
# Consumer Key CONSUMER_KEY = os.environ['CONSUMER_KEY'] # Consumer Secret CONSUMER_SECRET = os.environ['CONSUMER_SECRET'] # Callback URL (èªè¨¼å¾ãªãã¤ã¬ã¯ããããURL) CALLBACK_URL = 'https://flask-tweepy.herokuapp.com/' # Herokuä¸ # CALLBACK_URL = 'http://localhost:5000/' # ãã¼ã«ã«ç°å¢
CONSUMER_KEY
㨠CONSUMER_SECRET
ã¯ãTwitter API key ã®åå¾ãã§æ§ãã¦ããããConsumer keyãã¨ãConsumer secretãã®ãã¨ã§ãï¼
ç°å¢å¤æ°ã«è¨å®ãã¦å¼ã³åºãããã«ãã¦ãã¾ãï¼
ãããããã¨ã§ï¼ã½ã¼ã¹ã³ã¼ãã«ç´ã«keyãè¨è¿°ããå¿
è¦ããªããªãã¾ãï¼
ç°å¢å¤æ°ã¸ã®è¨å®æ¹æ³ã¯å¾è¿°ãã¾ãï¼
CALLBACK_URL
ã¯é£æºã¢ããªèªè¨¼å¾ã«ãªãã¤ã¬ã¯ããããURLã§ãï¼
ãã¼ã«ã«ç°å¢ã¨Herokuä¸ã§ã¯URLãç°ãªãã®ã§ï¼é½åº¦å¤æ´ããå¿
è¦ãããã¾ãï¼
# Flask ã®èµ·å
app = Flask(__name__)
Flaskã使ãããã®åªæã§ãï¼
ããæ¸ããã®ã ã¨æã£ã¦ä¸ããï¼
# flask ã® session ã使ãã«ã¯keyãè¨å®ããå¿ è¦ãããï¼ app.secret_key = os.environ['SECRET_KEY']
Flask ã® session æ©è½ã使ãããã«ã¯ app.secret_key
ã«å¤ãè¨å®ããå¿
è¦ãããã¾ãï¼
ããã§ãç°å¢å¤æ°ãç¨ãã¦ããï¼è¨å®æ¹æ³ã¯ä¾ã®ãã¨ãå¾è¿°ã¨ãã¾ãï¼
@app.route('/') def index():
Flaskç¬ç¹ã®æ¸ãæ¹ãåºã¦ãã¾ããï¼
é¢æ°ã®ç´åã« @app.route(PATH)
ã¨æ¸ããã¨ã§ï¼PATH 㨠é¢æ°ãç´ä»ãã¾ãï¼
ä¸è¨ã®ä¾ã§ã¯ï¼'/'
(root ãã¼ã¸) ããªã¯ã¨ã¹ããããã index()
é¢æ°ãå¼ã³åºãããã«è¨å®ãããã¨ã«ãªãã¾ãï¼
return render_template('index.html', timeline=timeline)
ãã®ããã«æ¸ããã¨ã§ï¼ãã³ãã¬ã¼ãã使ã£ã¦ãã¼ã¸ãã¬ã³ããªã³ã°ï¼æç»ï¼ãã¦ããã¾ãï¼
ä¸è¨ã§ã¯ãindex.html
ã使ã£ã¦ãã¼ã¸ãæç»ãã¦ãã¾ãï¼
ãã³ãã¬ã¼ã㯠templates
ãã£ã¬ã¯ããªã«ç½®ãã¦ãããã¨ã§èªåã§èªèãã¦ããã¾ãï¼
ã¾ãï¼å¤ããã³ãã¬ã¼ãã«æ¸¡ããã¨ãå¯è½ã§ï¼ä¸è¨ã§ã¯ timeline
(ã¦ã¼ã¶ã¼ã®ã¿ã¤ã ã©ã¤ã³ã®ãã¤ã¼ãã®ãªã¹ã) ã渡ãã¦ãã¾ãï¼
@app.route('/twitter_auth', methods=['GET']) def twitter_auth():
'/twitter_auth'
㨠twitter_auth()
é¢æ°ãç´ä»ãã¾ãï¼
ãã ãï¼ä»å㯠methods=['GET']
ã¨æå®ãããã¨ã§ãGET以å¤ã®ãªã¯ã¨ã¹ããæå¦ããã¦ãã¾ãï¼
# tweepy ã§ã¢ããªã®OAuthèªè¨¼ãè¡ã auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL) try: # é£æºã¢ããªèªè¨¼ç¨ã® URL ãåå¾ redirect_url = auth.get_authorization_url() # èªè¨¼å¾ã«å¿ è¦ãª request_token ã session ã«ä¿å session['request_token'] = auth.request_token except tweepy.TweepError, e: logging.error(str(e))
twitter_auth()
é¢æ°ã§ã¯ Tweepy ã使ã£ã¦é£æºã¢ããªèªè¨¼ç¨ã®URLãåå¾ãã¾ãï¼
ã½ã¼ã¹ã³ã¼ãã®ã³ã¡ã³ãéãï¼
- OAuthèªè¨¼
- ã¢ããªèªè¨¼ç¨URLã®åå¾
request_token
ã session ã«ä¿å
ã¨ããæµãã«ãªãã¾ãï¼
request_token
ã¯ã¢ããªèªè¨¼å¾ã« Access token, Access token secret ã¨ãããã®ãåå¾ããæã«å¿
è¦ã«ãªãã®ã§ï¼ã»ãã·ã§ã³ã«ä¿åãã¦ããå¿
è¦ãããã¾ãï¼
return redirect(redirect_url)
redirect
ãFlaskã®æ©è½ã§ï¼æå®ããURLã«ãªãã¤ã¬ã¯ããã¦ããã¾ãï¼
ä¸è¨ã§ã¯åå¾ããã¢ããªèªè¨¼ç¨ã®URLã«é£ã°ãã¦ãã¾ãï¼
def user_timeline():
ã¢ããªèªè¨¼ããã¦ã¼ã¶ã®ã¿ã¤ã ã©ã¤ã³ãåå¾ããé¢æ°ã§ãï¼
æµãã¨ãã¦ã¯ï¼
- request_token 㨠oauth_verifier ã®ãã§ãã¯
- OAuth èªè¨¼
- Access token, Access token secret ã®åå¾
- Twitter APIã«ã¢ã¯ã»ã¹ããããã®ã¤ã³ã¹ã¿ã³ã¹ãçæãï¼ã¿ã¤ã ã©ã¤ã³ãåå¾
ã¨ããæãã§ãï¼
# request_token 㨠oauth_verifier ã®ãã§ã㯠token = session.pop('request_token', None) verifier = request.args.get('oauth_verifier') if token is None or verifier is None: return False # æªèªè¨¼ãªãFalseãè¿ã
request_token
㨠oauth_verifier
ã®ãã§ãã¯ã§ãï¼
request_token
㯠session
ã«ä¿åãã¦ããã¯ããªã®ã§ï¼ããããåå¾ãã¾ãï¼
åå¾ããã session
ããã¯åé¤ãã¦ããããã®ã§ pop
ã¡ã½ããã使ã£ã¦ãã¾ãï¼
oauth_verifier
ã¯ã¢ããªèªè¨¼å¾ã«ã¢ããªã®ãã¼ã¸ã«ãªãã¤ã¬ã¯ããããéã«URLãã©ã¡ã¼ã¿ã¨ãã¦ä»ä¸ããã¦ãã¾ãï¼
Flaskã® request.args.get()
é¢æ°ã使ãã°ï¼URLãã©ã¡ã¼ã¿ã®å¤ãåå¾ãããã¨ãã§ãã¾ãï¼
æçµçã«ï¼2ã¤ã®ãã¡ã©ã¡ããä¸æ¹ã§ãæ¬ ãã¦ããå ´åã¯èªè¨¼ãæ¸ãã§ããªãã¨ã¿ãªãï¼False
ãè¿ãã¾ãï¼
# tweepy ã§ã¢ããªã®OAuthèªè¨¼ãè¡ã auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET, CALLBACK_URL) # Access token, Access token secret ãåå¾ï¼ auth.request_token = token try: auth.get_access_token(verifier) except tweepy.TweepError, e: logging.error(str(e)) return {}
OAuth èªè¨¼ã¨ Access token, Access token secret ã®åå¾ã§ãï¼
Access token, Access token secret ãåå¾ããã«ã¯å
ç¨ãã§ãã¯ãã request_token
㨠oauth_verifier
ãå¿
è¦ã§ãï¼
æ£ãã Access token, Access token secret ãåå¾ã§ãã¦ããã°ï¼auth.access_token
, auth.access_token_secret
ã«ããããå¤ãæ ¼ç´ããã¦ããã¯ãã§ãï¼
ããï¼èªè¨¼ç¶æ
ãæ°¸ç¶ãããå ´åã¯ããããDBçã«ä¿åãã¦ããã¨ããã§ãï¼
# tweepy 㧠Twitter API ã«ã¢ã¯ã»ã¹ api = tweepy.API(auth) # user ã® timeline å ã®ãã¤ã¼ãã®ãªã¹ããæ大100件åå¾ãã¦è¿ã return api.user_timeline(count=100)
tweepy.API(auth)
ã§ï¼Twitter APIã«ã¢ã¯ã»ã¹ããããã®ã¤ã³ã¹ã¿ã³ã¹ãçæãã¾ãï¼
ãã㦠api.user_timeline()
ã¡ã½ããã«ããã¿ã¤ã ã©ã¤ã³ã®ãã¤ã¼ãããªã¹ãå½¢å¼ã§åå¾ãã¦è¿ãã¦ãã¾ãï¼
count=100
ã«ããï¼æ大100件ã¾ã§åå¾ããããã«ãã¦ãã¾ãï¼
templates/index.html
{% if timeline == False %} <!-- æ¡ä»¶ã True ã®å ´åã«è¡¨ç¤ºããè¦ç´ --> {% else %} <!-- æ¡ä»¶ã False ã®å ´åã«è¡¨ç¤ºããè¦ç´ --> {% endif %}
æè¬ifæã§ãï¼
åºæ¬çã«Pythonã¨åãããã«ä½¿ãã¾ããï¼è¥å¹²ä»æ§ãç°ãªãã¿ããã§ãï¼
ä¸è¨ã³ã¼ãã§ã¯ï¼ã¢ããªèªè¨¼ãæ¸ãã§ããªãå ´åã¯ã¢ããªèªè¨¼ç¨ã®ãªã³ã¯ã表示ãï¼æ¸ãã§ããå ´åã¯ã¦ã¼ã¶ã®ã¿ã¤ã ã©ã¤ã³ã表示ãã¾ã*2ï¼
{{ url_for('twitter_auth') }}
Flaskã§ã¯ãã³ãã¬ã¼ãã§ä½¿ããé¢æ°ãããã¤ãç¨æããã¦ããï¼url_for()
ããã®1ã¤ã§ãï¼
ãã®é¢æ°ã¯ï¼æå®ãããã¹ãå®éã«ã¢ã¯ã»ã¹ã§ããURLã«å¤æãã¾ãï¼
ä¸è¨ã ã¨ï¼ã¢ããªèªè¨¼ç¨ã®URLã«å¤æãã¦ããã¾ãï¼
ã¾ãï¼é¢æ°ãå¤æ°ã使ãæ㯠{{ }}
ã§å²ã決ã¾ãã«ãªã£ã¦ãã¾ãï¼
{% for status in timeline %} <p>{{ status.text }}</p> <hr> {% endfor %}
ãã¡ã㯠for æã§ããï¼
timeline ãããã¤ã¼ã (Statusãªãã¸ã§ã¯ã) ã1件ãã¤åãåºãï¼ãã¤ã¼ãæ¬æ status.text
ã表示ãã¦ãã¾ãï¼
ãã¼ã«ã«ã§åãã
Herokuã§åããåã«ï¼ã¾ãã¯ãã¼ã«ã«ç°å¢ã§åããã¦ã¿ã¾ãï¼
ãã®ããã«ã¯ .env
ã¨ãããã¡ã¤ã«ãæºåããå¿
è¦ãããã¾ãï¼
ä¸èº«ã¯ä»¥ä¸ã®ããã«ãã¾ãï¼
SECRET_KEY=****** CONSUMER_KEY=****** CONSUMER_SECRET=******
SECRET_KEY
ã«ã¯ ä»»æã®è±æ°åãè¨è¿°ãã¾ãï¼ä½ã§ãæ§ãã¾ããï¼ä¾ï¼HvonjvTDDllnFkcnKJbvT6i,lnJYFYï¼ãï¼çãããã®ã¯æ¢ãã¨ããã»ããããã§ãããï¼
CONSUMER_KEY
, CONSUMER_SECRET
ã«ã¯ãTwitter API key ã®åå¾ãã§æ§ãã¦ããããConsumer keyãã¨ãConsumer secretããã³ãããã¾ãï¼
å®æãããï¼Procfile
ãç½®ãã¦ããã®ã¨åããã£ã¬ã¯ããªã«ä¿åãã¦ä¸ããï¼
å®ã¯ããã§ãã¼ã«ã«ç°å¢ã¸ã®ç°å¢å¤æ°ã®è¨å®ãå®äºãããã¨ã«ãªãã¾ãï¼
ãã1ã¤å¤æ´ãå¿
è¦ãªç®æãããã¾ãï¼
app.py ã® CALLBACK_URL
ã«ãã¼ã«ã«ç°å¢ç¨ã®URLãã»ãããã¾ãï¼
以ä¸ã®ããã«ã³ã¡ã³ãã¢ã¦ãããè¡ãå¤æ´ãã¦ä¸ããï¼
# Callback URL (èªè¨¼å¾ãªãã¤ã¬ã¯ããããURL) # CALLBACK_URL = 'https://flask-tweepy.herokuapp.com/' # Herokuä¸ CALLBACK_URL = 'http://localhost:5000/' # ãã¼ã«ã«ç°å¢
ãã¦ï¼ããã§ã¯åããã¦ã¿ã¾ãï¼
ã¢ããªã®ãã£ã¬ã¯ããªç´ä¸ã§ä»¥ä¸ã®ã³ãã³ããå
¥åãã¾ãï¼
% foreman start 12:30:34 web.1 | started with pid 61216 12:30:35 web.1 | [2015-09-01 12:30:35 +0900] [61216] [INFO] Starting gunicorn 19.3.0 12:30:35 web.1 | [2015-09-01 12:30:35 +0900] [61216] [INFO] Listening at: http://0.0.0.0:5000 (61216) 12:30:35 web.1 | [2015-09-01 12:30:35 +0900] [61216] [INFO] Using worker: sync 12:30:35 web.1 | [2015-09-01 12:30:35 +0900] [61219] [INFO] Booting worker with pid: 61219
ãã®ç¶æ ã§ãã©ã¦ã¶ãã以ä¸ã®URLã«ã¢ã¯ã»ã¹ãã¦ä¸ããï¼
http://localhost:5000/
ç¡äºã«ã¢ããªã¯åãã¾ãããï¼
ã¡ãªã¿ã«ï¼foreman
ã¨ããã³ãã³ãã¯ãã¼ã«ã«ã«Herokuã®æ¬ä¼¼ç°å¢ãç«ã¡ä¸ããã³ãã³ãã§ï¼éçºæã«ã¯ãä¸è©±ã«ãªããã¨æãã¾ãï¼
Herokuã«å ¬é
ããããHerokuã«å ¬éãã¾ãï¼
ã¾ãã¯Herokuä¸ã§ã¢ããªä½æãè¡ãã¾ãï¼
$ heroku create Creating tranquil-chamber-4602... done, stack is cedar-14 https://tranquil-chamber-4602.herokuapp.com/ | https://git.heroku.com/tranquil-chamber-4602.git
次ã«ï¼ã³ã¼ãã1ã¶æä¿®æ£ãã¾ãï¼
app.py ã® CALLBACK_URL
ã«ä½æããã¢ããªã®URLãã³ãããã¾ãï¼
URL㯠heroku create
ã³ãã³ãå®è¡æã«è¡¨ç¤ºããã¾ãï¼ä¸è¨ãªããhttps://tranquil-chamber-4602.herokuapp.com/ãï¼
ï¼ï¼
ç¶ã㦠git commit ãè¡ãï¼ãããHerokuã«pushãã¦ãããã¤ãã¾ãï¼
以ä¸ã®ã³ãã³ãã§ã¢ããªã®ãã£ã¬ã¯ããªç´ä¸ã§å®è¡ãã¾ãï¼
$ git init $ git add . $ git commit -m 'Initial commit' $ git push heroku master
æå¾ã«Herokuå´ã§ãç°å¢å¤æ°ãè¨å®ããå¿
è¦ãããã®ã§ï¼heroku config:set
ã³ãã³ãã§è¨å®ãã¾ãï¼
$ heroku config:set SECRET_KEY=****** $ heroku config:set CONSUMER_KEY=****** $ heroku config:set CONSUMER_SECRET=******
ããã§ã¯å®éã«ã¢ã¯ã»ã¹ãã¦ã¿ã¾ãï¼
$ heroku open
ãã¼ã«ã«ç°å¢ã®æã¨åãããã«åãã¾ãããï¼
ã¾ã¨ã
ãFlaskãã¨ãTweepyãã使ã£ã¦Twitteré£æºã¢ããªãä½æãï¼ãããHerokuä¸ã«å
¬éããæ¹æ³ãç´¹ä»ãã¾ããï¼
æ°ã¥ãããããªãé·ãè¨äºã«ãªã£ã¦ãã¾ãã¾ãã^^;
èªã¿ã«ããã£ããããããªããm(__)m
Flask, Tweepy, Heroku ã«ã¯ãã®è¨äºã§ç´¹ä»ãããã¦ããªãæ©è½ãã¾ã ã¾ã ããããåå¨ãã¾ãï¼
èå³ã®ããæ¹ã¯ä»¥ä¸ã®åèãã¼ã¸ãåç
§ãã¦ä¸ãã^^
åèãã¼ã¸
続いてはPython(Flask)でHeroku! - Qiita
Flaskã¢ããªãHerokuã«å
¬éããæé ã¯ãããåèã«ãã¾ããï¼
Flask
Flaskã®å
¬å¼ãµã¤ãï¼è±èªï¼
Flask v0.5.1 documentation
Flaskã®ãã¥ã¼ããªã¢ã«ï¼ããã¥ã¡ã³ãï¼APIãªãã¡ã¬ã³ã¹ï¼ä¸é¨è±èªï¼
Pythonã§å¦ã¶webã¢ããªã±ã¼ã·ã§ã³ã®ä½ãæ¹ by Flask
Flaskã®ãã¥ã¼ããªã¢ã«ãã®2ï¼
Tweepy
Tweepyã®å
¬å¼ãµã¤ãï¼è±èªï¼
Tweepy Documentation
Tweepyã®ããã¥ã¡ã³ãï¼APIãªãã¡ã¬ã³ã¹ï¼è±èªï¼
python 㧠twitter ã¡ã¢
Tweepyã®è§£èª¬è¨äºï¼
*1:http://d.hatena.ne.jp/speg03/20091019/1255957580 åç §
*2:ã¢ããªèªè¨¼ãæ¸ãã§ããªãå ´åï¼timeline 㯠False ã¨ãªãããã«å®è£ ãã¦ããã®ã§ããï¼