2012-01-31
【GAEj】Eclipse 3.7にGAEj入れようとしたら失敗した件
Eclipse 3.7にGAEjの環境を整えようと、こちらからプラグインのインストールを試みる。
http://dl.google.com/eclipse/plugin/3.7
が、こんな感じのエラーがでてインストールが進まない。
Cannot complete the install because one or more required items could not be found.Software being installed: Google App Engine Java SDK 1.6
なのでhttp://download.eclipse.org/releases/indigoから[Web, XML, JAVA EE and OSGi Enterprise Development]を選択してインストール、これでGAEjプラグインをもう一度インストール試みたら大丈夫だった。
2012-01-28
【Mac】MacでiTunesで再生中の曲をYoutubeのリンクと共にツイートする
これの続き。今までJavaでやってたことがPython&Macでもようやくできるようになった。
まずは結果から
$ python tweetSong.py キスをしようよ YUKI http://goo.gl/BafaS #nowplaying
ソース
tweet.scpt iTunes情報取得
tell application "iTunes" set m_artist to artist of current track set m_song to name of current track set m_info to m_song & " " & m_artist end tell
で、こっちがツイートするPythonのプログラム。例外処理はまったくやってないです。
tweetSong.py
# /usr/bin/python # -*- coding: utf-8 -*- import tweepy import os import subprocess import simplejson import urllib, urllib2 consumer_key = 'xxx' consumer_secret = 'xxx' access_key = 'xxx' access_secret = 'xxx' ytube_base = 'http://www.youtube.com/results?search_category=10&search_type=videos&suggested_categories=10&uni=3&search_query=' def post(message): auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.API(auth_handler=auth) api.update_status(message) def getCurrentSong(): info = subprocess.check_output(['osascript ' + os.getcwd()+'/tweet.scpt'], shell=True) return info def getShortUrl(_longUrl): req = urllib2.Request('https://www.googleapis.com/urlshortener/v1/url') data = "{'longUrl' : '%s'}" % _longUrl req.add_data(data) req.add_header('Content-Type', 'application/json') r = urllib2.urlopen(req) res = simplejson.loads(r.read()) r.close() return res['id'] def getYoutubeUrl(info): ytube_url = ytube_base + urllib.quote(info.encode('utf-8')) ytube_url = getShortUrl(ytube_url) return ytube_url def main(): info = getCurrentSong().rstrip() ytube_url = getYoutubeUrl(info) tweet = info + ' ' + ytube_url + ' #nowplaying' print tweet post(tweet) main()
2012-01-24
【Mac】MacでiTunesで再生中の曲をツイートする。
AppleScriptをPythonで無理やり実行して、その結果を取得してtweepyでツイートしてます。tweepyはこちらの記事を参考に入れてみてください。
以下適当スクリプト。
tweet.scpt
tell application "iTunes"
set m_album to album of current track
set m_artist to artist of current track
set m_song to name of current track
set m_info to m_song & " " & m_artist & " " & m_album
end tell
tweetSong.py
# /usr/bin/python # -*- coding: utf-8 -*- import tweepy import os import subprocess consumer_key = 'xxx' consumer_secret = 'xxx' access_key = 'xxx' access_secret = 'xxx' def post(message): auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.API(auth_handler=auth) api.update_status(message) def getCurrentSong(): info = subprocess.check_output(['osascript ' + os.getcwd()+'/tweet.scpt'], shell=True) return info def main(): info = getCurrentSong() print info post(info) main()
2012-01-21
【Arduino】俺専用コントローラーを自作する
さっそく前回の記事の【Arduino】タクトスイッチとシリアル通信を発展させていくよ(・∀・)
今回はこんな感じのコントローラを作ります。チープですねぇ。
作成
まずはケースにボタン箇所2つとUSBが入る所1つを電動ドリルとかでホリホリします。ボタンに関してはドリルの直径より大きかったので、やすりで削って穴を大きくしました。
で、次にユニバーサル基盤に回路を組んでいきます。まずはブレッドボードで試したほうが良いです。今回1つしかスイッチつなげてないですが、いずれ並列でも使えるようにしてます。しかし、コンパクトな回路図の作り方が分からないので適当です。(・∀・;) スイッチ初めての人はこちらなんかも参考に。
今回もボタンを押すとシリアル通信をするようにしてます。更にLEDも光るようにしてます。前回の記事と同じです。あとは閉じればコントローラーが完成。
2012-01-16
【Arduino】タクトスイッチとシリアル通信
タクトスイッチを押すとLEDが光る簡単な仕組みですが、PC側でこのオン、オフが受け取るシリアル通信アプリを書いてみるよ。
ちなみにこの回路は下の本の35ページと一緒です。基本回路ですね。
- 作者: Massimo Banzi,船田巧
- 出版社/メーカー: オライリージャパン
- 発売日: 2009/03/27
- メディア: 単行本(ソフトカバー)
- 購入: 26人 クリック: 190回
- この商品を含むブログ (66件) を見る
シリアル通信はこちら様のサイトの「シリアル通信プログラム(受信専用)」を丸パクリ。ただボーレートは9600に、シリアルポートはデバイスマネージャからArduinoの接続ポートを確認して、対応したCOM番号に変更しておきましょう。
で、Arduino側のプログラム。これも「Arduinoをはじめよう」のプログラムにSerial.beginとSerial.printlnを追加するだけ。超簡単ですね。
#define LED 13 #define BUTTON 7 int val = 0; void setup() { pinMode(LED, OUTPUT); pinMode(BUTTON, INPUT); Serial.begin(9600); } void loop() { val = digitalRead(BUTTON); if(val == HIGH) { digitalWrite(LED, HIGH); Serial.println(1); } else { digitalWrite(LED, LOW); Serial.println(0); } delay(300); }
これでArduinoをPCとつなげた状態でCプログラムの方を動かすと、タクトスイッチを押した状態で1が、押してない状態で0がストリームで流れてきます。あとはこれを他のアプリにdllとして組み込んだりしてあげると、デモの時とかに大活躍しそうですね。スイッチも複数とか大きいやつとかを使ってあげれば更に活躍の場が広がりそう。







