Twitterã®ãã©ãã¯ã¼ãããããããªãµã¼ãã¹ãã£ãããããªãã¨åãã¦ããã¾ãã¦ã
ãã£ã¡ã俺ãä½ããï¼ã¨ããäºã§ãä½æ¥è¨é²ãæ®ãã¦ã¿ãããã¨æãã¾ãã
æè¿MacãOSåã¤ã³ã¹ãã¼ã«ããã»ã¼ã¾ã£ãããxcode(使ããªããã©gitæå¹åã«å¿ è¦)ã¨emacsã ããå ¥ã£ã¦ããããªç¶æ ããã®ã¹ã¿ã¼ãã§ãã
Webãµã¼ãã¹ã£ã¦ã©ããã£ã¦ä½ã£ã¦ãããã ãã¨æããã¦ãæ¹ã®åèã«ãªãã°å¹¸ãã§ãããªãããã¤ãã®éãDjango&Herokuæ§æã§ãã
â»ããè¦ã¦ä½ããä½ããã¨ãã訳ã§ã¯ãªãããããªæµãã§ä½ã£ã¦ããã¨ãã説æã§ãã®ã§ã詳細ã¯çµæ§çãæ°å³ã§ãã
â»ä½ãã¨ãã®ãã¤ã³ããå ã«è¨ã£ã¦ãã¾ãã¾ããããããªãå®æç³»ãç®æãããããªãã¦ãã¡ãã£ã¨ä½ã£ã¦åããã¦ãç¹°ãè¿ãã®ããã¤ã³ãã«ãªã£ã¦ããããããªãããªã¨æã£ã¦ã¾ããåã¯SIå±ãªãã§ãããæ°äººåã¨ãã§ããããªãå ¨é¨ã³ã¼ãã£ã³ã°ãã¦ãããåããã¨åããéæ¹ã«æ®ãããªãã¦ããã®ãããè¦ã¾ããåããªãåé¡ãåºãæã«ãããæ°ã¥ããç¨ã«ã¡ããã¡ããåä½ç¢ºèªãã¾ãããã
ä½æã®ãã£ãã
ãã®ãã¤ã¼ãè¦ã¦ä½æã«çæãã¾ãããä½ã£ãå¾ã«IFTTTã§ã§ããããããªããã¨æãã¾ããããæ£è¦è¡¨ç¾å¼ãã£ã¦è¨ããã¦ãæ®éã®äººã«ã¯è¾ãã ãããªã¨æããæ°ã«ããã®ç´¹ä»ã§ãã
è¨èª(Python3)ã®ã¤ã³ã¹ãã¼ã«
Macã«ã¯æåããPythonãå ¥ã£ã¦ãããã§ããã2.7.6ã¨ã¡ãã£ã¨å¤ãã§ãã
åã¯Python3.xã好ããªã®ã§ããã¡ããã¤ã³ã¹ãã¼ã«ãã¾ãã
ãã¡ããã3.4.2ããã¦ã³ãã¼ãããã¤ã³ã¹ãã¼ã©ã¼ã§æ¬¡ã¸ãé£æãã¤ã³ã¹ãã¼ã«ãã¾ããã
virtualenvã®ã¤ã³ã¹ãã¼ã«
pythonã§å©ç¨ããã©ã¤ãã©ãªããç¹å®ããã¸ã§ã¯ãç¨ã«éé¢ãã¦ã¤ã³ã¹ãã¼ã«ããããã®ãã¼ã«ã§ãã
ãã¡ããã¤ã³ã¹ãã¼ã«ãã¾ããpipã¨ããã³ãã³ãã ãã§ã¤ã³ã¹ãã¼ã«ã§ããã®ã§ä¾¿å©ã§ãã
ããã¸ã§ã¯ãåãèãã¦ããã¸ã§ã¯ããã©ã«ããä½ã
ããã§å¤§å²ããï¼ã¨ããããã¸ã§ã¯ããªãã¨ãããã趣å³ããã¸ã§ã¯ãã®ä¸ç°ãªã®ã§ããªã§ã¤ãã¾ããScheduleTweetã¨ãã§ããã§ããããæ°åãå ¥ãã¦ä½ãæã¯ãåãååã®ãµã¼ãã¹ããã§ã«ãªãã調æ»ãããã¨ããç¥ç§°ã¯ã©ããªãã ãããã¨ãèãã¦ã¤ãã¾ãã
virtualenvãæå¹åãã
ããã§ããã¸ã§ã¯ãç¨ã®ç°å¢ãåºæ¥ã¾ããã
Djangoãã¤ã³ã¹ãã¼ã«ãã
ãã¡ããpipã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ãã¾ãã
ç°¡åï¼
Djangoã®ããã¸ã§ã¯ããä½æãã
Djangoã§ã¯ãã³ãã³ãä¸ã¤ã§ããã¸ã§ã¯ãã®éå½¢ãä½ã£ã¦ããã¾ãã
Â
ããã¦ããã©ã¦ã¶ããhttp://localhost:8000ã«ã¢ã¯ã»ã¹
åãã¦ããäºã確èªã§ãã¾ãã
ãã°ã¤ã³ç¨ãã¼ã¸ãä½ã
æåã¯ãã°ã¤ã³ç¡ãå©ç¨ã§ãã¦ãããããªã¨æã£ããã©ãã¹ãã ã®è¸ã¿å°ã¨ãã¦å©ç¨ããã¦ãå«ãªã®ã§ãTwitterã¢ã«ã¦ã³ãã§ãã°ã¤ã³ã§ããæ§ã«ãã¾ãã
ã¤ã¾ããä»æ§çã«ã¯
- Twitterã§ãã°ã¤ã³ï¼&ãµã¤ã³ã¢ããï¼
- ãã®äººã®TLãããæ¥ä»ãå«ãTweetãæ½åº
- æ¥ä»ããã£ããã¤ã¼ãã®URLããã®äººã«ãã¤ã¼ãé£ã°ã
ãããªæãã§ã
ã¾ãã¯å¤å´ãä½ã
å é¨ãã¸ãã¯ã¯ç¡è¦ãã¦ããã¼ã¸ãä½ãã¾ãã
ãããããã¯ç½®ãã¦ããã¦ãã¾ãã¯åãããæ§ã«ãå¿ è¦ãªinputãå ¥åã§ãã¦ãåºãããoutputãåºããå ´æãä½ãã¾ãã
ãããªæã
Djangoã¨Twitterãé£æºããã
ãããè¥å¹²é¢åããããæè¿ã®èªè¨¼ã¯OAuthèªè¨¼ã¨ãã£ã¦Twitterã®ãã¼ã¸ã§èªè¨¼ããã¦ãèªè¨¼éãã°ã¢ã¯ã»ã¹ããããã®éµï¼ã¦ã¼ã¶ã¼IDã¨ããã¹ã¯ã¼ãã¨ã¯å¥ã®å¤ï¼ãåãåãäºãã§ãããã®éµããã£ã¦Twitterã¨ã®é£æºãè¡ãå½¢ã«ãªãã¾ãã
Djangoã§ã®å®è£ æ¹æ³ã¯ããã¡ãã詳ãã
Djangoã®ã¦ã¼ã¶èªè¨¼ã¾ã¨ã - Programming Log
 ã¾ãã¯pipã§OAuthã®çºã®ã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«
ããã¦å ã»ã©ã®Djangoã®ã¦ã¼ã¶èªè¨¼ã¾ã¨ã - Programming Logãå ã«ã»ã¼ã³ããã
twitterå´ã®Callback URLãå ¥ããªãã¨401ã¨ã©ã¼ãè¿ã£ã¦ããã®ã§æ³¨æãããã«ã¡ãã£ã¨ããã£ãã
ã¯ãã¼ã«ããã°ã©ã ãä½ã
TLãæ½åºãã
å é¨ã§ã¹ã¬ããç«ã¦ã¦ãä¸å®æéã§ã«ã¼ãããã¨ãã¦ããããã§ãããæ»ãã æã«å度起ããããããã®ãé¢åãªã®ã§ãç¹å®URLã«ã¢ã¯ã»ã¹ããã£ãéã«ã¯ãã¼ã«ããæ§ã«ãã¾ãã
ãã®æç¹ã§ã®ã³ã¼ãã¯ãããªæãã
Pythonãããï¼ã£ã¦æã£ãã®ã¯ç¢å°ã®é¨åãunicodedata.normalizeããããPythonã®æ¨æºã¢ã¸ã¥ã¼ã«ãªãã§ãããå ¨è§toåè§ãããã§æ¸ã¾ããã¨ãã§ããã
赤æ ã§å²ãã§ãä¸ã®æ¹ã§æ£è¦è¡¨ç¾å®ç¾©ãã¦ã¾ããããããåè§æåã ãã§æ¸ãããã«ãªã£ã¦ããã®ããããã§å ¨è§ãåè§ã«ãã¦ããçºã§ãã
ãã®æç¹ã§åããã¨ããããªæãã
æ½åºãããã¤ã¼ãããå©ç¨è ã«ç¥ãããé¨åãä½ã
å©ç¨è ã«ç»é²ãã¦ãããéã«ãä¸å®ãæ¸ããããã«æ¨©éãèªã¿åãå°ç¨ã«ãã¦ãã¾ãã
ã¤ã¾ããä¸è¬ã®äººãè¦ããã¨ãã§ããæ å ±ããã¢ã¯ã»ã¹ã§ããããã¤å½è©²ã¢ã«ã¦ã³ãã§ã®æ稿ãªãã¦ã§ããªã権éã¨ãã¦ãã¾ãã
ãã£ã¦ãæ稿ç¨ã®ã¢ã«ã¦ã³ããããå¥ã¢ããªã±ã¼ã·ã§ã³ã¨ãã¦ç»é²ããå¿ è¦ãããã¾ãã
ãããªæãã§ãããä¸ã¤ã¢ããªã±ã¼ã·ã§ã³ãç»é²ãã¦ãã¾ãã
ããã¦ãç»é²ããã¢ããªã±ã¼ã·ã§ã³ã®Keyã使ã£ã¦ãæ稿ã®å®è£ ããã¾ãã
ã³ã¼ãã§è¨ãã¨ãå²ãã ç®æã追å ç®æã
 ããã§ãæ½åºããããã®ãéç¥ãããããã«ãªãã¾ããã
åéç¥ãé²ãÂ
ç¾å¨ã®åãã ã¨ãä¸åº¦éç¥ããããã®ããå度åããéã«åéç¥ããã¦ãã¾ãã¾ãã
ãã®ã¾ã¾ã ã¨ãã¡ãªã®ã§ãéç¥ã«æåãããã®ãDBã«ä¿åãã¦ãããåéç¥ãé²ãæ§ã«ãã¾ãã
éç¥ããæ å ±ãä¿åãã¦ããããã®ãã¼ãã«ãä½ã
models.pyã«ãã¼ãã«å®ç¾©ãä½æãã¾ãã
syncdbããã¦ããã¼ãã«ä½æ
ãã¼ãã«ã«å¤ããªããã°ãã¤ã¼ããã¦ãã¼ã¿ç»é²ãå¤ãããã°ç¡è¦ããã³ã¼ãã追å ã
åããã¨ã確èªãã¦å®æã§ãï¼
ãããã¤ãã
herokuãã¼ã«ãå ¥ãã
ãã¡ãããheroku toolbeltããã¦ã³ãã¼ããã¦ãã¦ã¤ã³ã¹ãã¼ã«ãã¾ãã
django-toolbeltã®ã¤ã³ã¹ãã¼ã«
djangoã¨herokuããããªã«é£æºãã¦ããããã¼ã«ã§ãããã ãåã®ç°å¢ã§ã¤ã³ã¹ãã¼ã«ãããã¨ããã¨
Error: pg_config executable not found.
 ã¨ã¨ã©ã¼ãçºçãpostgreSQLãã¤ã³ã¹ãã¼ã«ããã¦ããªãã®ãåå ã®ãããªã®ã§ã
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
ã§homebrewãã¤ã³ã¹ãã¼ã«ããã®ã¡ã
brew install postgresql
ãå®è¡ã
æ¹ãã¦pipã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ãã¾ãããããªæã
herokuåãã«ã½ã¼ã¹ã®ä¿®æ£ï¼è¿½å
ãã¡ãã«ãã¤ã³ããã¾ã¨ãã¦ã¾ãããherokuåãã«å¹¾ã¤ãä¿®æ£ãå¿ è¦ã§ãã
Rubyã«è² ãããªï¼Herokuã§Python(Django)åããæ¹æ³ - Qiita
- runtime.txtãç¨æãã¦ãPythonã®ãã¼ã¸ã§ã³æå®
- ãããã°ã¢ã¼ãã®è§£é¤
- (ä¸ã®ãã¼ã¸ã«ã¯è¨è¼ãã¦ãã¾ããã)Procfileã®ä½æ
- (ä¸ã®ãã¼ã¸ã«ã¯è¨è¼ãã¦ãã¾ããã)requirements.txtã®ä½æ
ã§ãã
gitããã¸ã§ã¯ãåãã
git initã§gitããã¸ã§ã¯ãåããã¾ããã¤ãã§ã«.gitignoreãä½ã£ã¦ãã¾ãã¾ãã
commitã¾ã§æ¸ã¾ãã¾ã
herokuã«ãããã¤ãã
heroku createã³ãã³ãã§ãherokuå´ã«ããã¸ã§ã¯ããä½ãã¾ãã
ç¶ãã¦gitãªãã¸ããªãpush
ããã§herokuã®ããã·ã¥ãã¼ãã確èªããã¨ãæå¹åããã¦ãããã¨ã確èªã§ãã¾ãã
herokuä¸ã«ãã¼ãã«ãä½ã
herokuä¸ã§ã³ãã³ããå®è¡ããã«ã¯heroku run ã»ã»ã»ã¨ããã°OKã§ããsyncdbã¯ãããªæãã
以ä¸ã§åä½ããã¨ããã¾ã§ãã£ã¦ããã¾ããï¼
ãã¨ã¯ãå®æçã«URLãå©ãã®ãcronãªãã§å®è£ ããå¿ è¦ãããã¾ãããç´¹ä»ã¨ãã¦ã¯ãã®è¾ºã§ã
Â
æå¾ã«ãä½ã£ããã®ã¨ã½ã¼ã¹ã³ã¼ãã®ç´¹ä»
ï¼ï¼ä»åä½ã£ããã®
http://scheduletweet.herokuapp.com
>>ã½ã¼ã¹ã³ã¼ã
nakazye/ScheduleTweet · GitHub
Â
ãããã§ããã§ããããï¼å®éãã³ã¼ããæ¸ãã¦ãã¨ããããããæåã¯è¨å®ç³»ã«æéã使ãæãã§ãã
ãã ãä¸åº¦åãã¨ããã¾ã§æã£ã¦è¡ã£ã¦ãã¾ãã°ããã¨ã¯herokuã«git pushããã ããªã®ã§é常ã«æ¥½ã§ãã
Â
ãããªæãã§ä½ã£ã¦è¡ã£ã¦ããã ãªã¼ã¨ããåèã«ãªãã°å¹¸ãã§ãã
追è¨
å®æçã«checkã«ã¢ã¯ã»ã¹ããã®ã¯ã以ä¸ã®ãµã¼ãã¹ã使ãã¾ããã便å©ï¼
cron-job.org - Kostenlose Cron-Jobs, von minütlich bis einmal im Jahr.
追è¨ã®è¿½è¨
ã³ã£ãããããã¨ã«ã使ã£ã¦ä¸ãã£ã¦ãæ¹ãããã¿ããã§ãã
å 輪ãã¿ã®ã¤ããã ã£ãã®ã§ãç»é²è§£é¤æ©è½ã¯æãã¦ã¾ãããã®ã§ãä¸è¦ã«ãªã£ãéã¯Twitterã®è¨å®ããã¢ããªé£æºè§£é¤ãã¦ããã ããã°ã¨æãã¾ãã