Apr 29, 2009
Presentation of Django Hack-a-thon Disc.8
Django & jQuery by id:monjudoh (資料) (ブログ)
jQuery な monjudoh 先生によるプレゼン。jQuery UI はすごいの一言。ユーザインターフェースはYUIオンリー(css含む)でしたが、今後はjQueryも使っていく予定。さっそく社内アプリに使ってみてます。jQuery で出来ることはdemosを見るのが一番早いかも。dropableとか面白いですね。jQueryのすごいところのひとつはプラグインの数。YUIよりは全然多い・・・。monjudoh 先生がご紹介されていたdatepickerもすごいです。
Django & Flash by otuka (資料)
Django AMF な otuka 先生によるプレゼン。何よりも作品がすごーーーい。別冊島耕作、Intel Centrino。。。島耕作アプリは登録すると本に自分の名前が出たりするのですが、実際のマンガを切り貼りするのがご苦労されたそうです。職人ですね・・。すべて Django × Django AMF で作成されているということです。
Django & GTD & MindMap by shibukawa (資料)
MindMapper だそうです。勉強会もあるそうです。俺もドキュメントはMindMapな人だったので、今度勉強会行ってみたい!最近は "The History of Python.jp" を翻訳されているそうです。う・・。昼休みに翻訳されているとのことんので、私も頑張ります。
ゲスト & おまけ (豪華すぎでおまけになっていませんw)
by id:perezvon
mixi アプリのお話。影響されて会社でueblog先生と作ることにw
by id:nishiohirokazu
TODO: Python 旅館でゲームに参加する。
by id:moriyoshi
javascript で、binary操作して音を鳴らしたり、Excel生成したり・・・。日本語じゃなかったのでよくわかりませんw
ここまで書いたり、勉強会に参加してみたりして気づいたこと。
- はてなユーザ率高い
- マカー率高い
- 勉強会に参加した時はやる気が出るけど、時間がたつとダレる
- TODO大事
- 視野は広く
- コードを書くのは好きだけど、あるもんは使ってみるべき
- もっとコードを読むべき
Google App Engine in Django Hack-a-thon
Django Hack-a-thon Disc.8 に参加してきました。初!Google App Engine Hack-a-thon のチューターを担当させていただくことになったのですが、いい具合に何もしません(できません)でした・・・。どちらかというと参加者として、色々と勉強させていただいたのでお金を払ったほうがよかったような気もしています。とりあえず、勉強させていただいたこととかを書いておきます(笑)。私がやったことは2つ。
- HTML を解析し、Web API として利用できるようにするための Python ライブラリーを書く
- Django on Google App Engine で Twitter の oAuth を使うアプリを書く
>>> import re >>> import urllib2 as urllib >>> url = 'http://google.com/' # 例だす >>> opener = urllib2.build_opener() >>> html = opener.open(url).read() # [html が出力される] >>> print html # 取得したhtmlが出力される >>> # 適当にhrefタグ内を取り出す >>> p = re.compile(u"href=\"(?P<link>[\w:/?&.-_%]+)\"",re.I) >>> # shift_jis はそのページのエンコード >>> for link in p.findall(unicode(html, "shift_jis")): ... print link # [link の一覧が出力される]一部だけの情報をとりたいのであれば、BeautifulSoup よりも正規表現が速いです。コードはごりごりになっちゃいますが。一応動きました。
午後からは oAuth なアプリ。Twitter と接続することにしますた。やっぱり Google App Engine の urllib に悩まされました。調べたら、グループにも何回か登場してますね(コレとかコレとか)。使ったスクリプトはtwitter_app。app-engine-patch使うと簡単に動きます。変更箇所は以下のとおり。
- url = str(oauth_request.to_url())
+ url = str(oauth_request.to_url()).replace('https://' + SERVER, '').replace('http://' + SERVER, '')
むりくりパッチです。改修待ち。でも一応oAuthは動いたので、アプリを作ることにしました。そのうち公開しますw
Apr 12, 2009
App EngineでTweet @ GAE Hackathon
昨日、Google App Engine Hackathon Disc.3 に参加してきました。わたくしはTutorial Aで外部データとの連携をがむばることに。 テーマは、Python Twitterというライブラリーを使って、GAEからTwitter API(JSON)をコールしてみようというもの。必要なライブラリーは、Python Twitterとsimplejsonの2つです。Python Twitterはデフォルトのままでは動きません。動作するように書き換えたやつを、ハカソンリポにコミットしております。だいぶひどい修正です。主な変更点は以下のとおり。
- 1487行目のDiff
def _GetUsername(self): - return os.getenv('USER') or \ - os.getenv('LOGNAME') or \ - os.getenv('USERNAME') or \ - os.getlogin() or \ - 'nobody' + return 'nobody' - 1394行目のDiff
def _FetchUrl(self, url, post_data=None, parameters=None, no_cache=None): - # Build the extra parameters dict - extra_params = {} - if self._default_params: - extra_params.update(self._default_params) - if parameters: - extra_params.update(parameters) - - # Add key/value parameters to the query string of the url - url = self._BuildUrl(url, extra_params=extra_params) - - # Get a url opener that can handle basic auth - opener = self._GetOpener(url, username=self._username, password=self._password) - - encoded_post_data = self._EncodePostData(post_data) - - # Open and return the URL immediately if we're not going to cache - if encoded_post_data or no_cache or not self._cache or not self._cache_timeout: - url_data = opener.open(url, encoded_post_data).read() - opener.close() - else: - # Unique keys are a combination of the url and the username - if self._username: - key = self._username + ':' + url - else: - key = url - - # See if it has been cached before - last_cached = self._cache.GetCachedTime(key) - - # If the cached version is outdated then fetch another and store it - if not last_cached or time.time() >= last_cached + self._cache_timeout: - url_data = opener.open(url, encoded_post_data).read() - opener.close() - self._cache.Set(key, url_data) - else: - url_data = self._cache.Get(key) - - # Always return the latest version - return url_data + method = urlfetch.GET + data = {} + if post_data: + method = urlfetch.POST + data.update(post_data) + params = {} + if parameters: + params.update(parameters) + url = self._BuildUrl(url, extra_params=params) + headers = {} + encoded_post_data = self._EncodePostData(post_data) + base64string = base64.encodestring('%s:%s' % (self._username, self._password))[:-1] + headers = {'Authorization': "Basic %s" % base64string} + if post_data: + headers.update({'Content-type':'application/x-www-form-urlencoded'}) + return urlfetch.fetch(url, encoded_post_data, method, headers, False).content
import twitter api = twitter.Api(username='[Twitterのユーザ名]', password=[Twitterのパスワード]) mystatuses = api.GetFriendsTimeline() for status in mystatuses : print status.text allstatuses = api.GetPublicTimeline() for status in allstatuses : print status.textGAE上で使った例もハカソンリポにコミットしています。ハカソンでは、このライブラリーを使って個別に色々と遊びました。ただしマージできているのが、PyAMFを使ってFlashにエコーをはくやつだけです。あとはフレンドの写真をひたすら表示していくなどの面白いアプリを作っていらっしゃる方もいたので、できればマージしたい・・・。 事務局の皆様、参加者の皆様お疲れ様でした!ハッピーコーディング(松尾さんの格言w)できました。