2008年9月3日水曜日

トランザクション エラー Nested transactions are not supported.

1. get_or_insert  自体がトランザクションなのでこれを含めたトランザクションを
  作成しようとするとエラーとなる。

File "C:\Program Files\Google\google_appengine\google\appengine\api\datastore.py",
   line 1386, in RunInTransaction'Nested transactions are not supported.')
BadRequestError: Nested transactions are not supported.


2.動作確認


First up is batch writes. You can now include entities in different entity groups in a single db.put() or db.delete() call. Entity modifications are only atomic within each entity group, but a single call that spans entity groups will be more efficient than a call for each group, which was required before.


以下は SDK だと Cannot operate on different entity groups in a transaction:
となるが Cloud では動作した。

class Dummy2(db.Model):
d1 = db.StringProperty()

class Dummy(db.Model):
d1 = db.StringProperty()

def tran():
d2 = Dummy2(d1 = "aaab")
d1 = Dummy(d1 = "aaab")

d1.put()
d2.put()

tran()


3. その他

   トランザクションの中で検索は実行できない。
  Can't query inside a transaction

2008年9月1日月曜日

YouTube API

http://code.google.com/apis/youtube/articles/youtube_api_appengine.html
に従い進めた。

Developer Key の取得の際は自分でどのように利用するか簡単に記述。
(どこかから値を持ってきて登録するのではない)

けれども、検索するだけであれば
self.developer_key = 'ADD YOUR DEVELOPER KEY HERE'
この部分は不要だった。

チュートリアルのSourceは以下にあるが、これらを特にダウンロードするまでの必要はなかった。
http://code.google.com/p/hello-youtube/source/browse/#svn/trunk/03_hello_youtube_search_query
http://code.google.com/p/hello-youtube/source/browse/#svn/trunk/04_hello_user_input

gdata 関連の設定は既に spredsheet などにアクセスするために導入してあったので
素直に検索を行なうことができた。

Youtube は検索言語の設定により、検索結果がかなり異なるので
http://code.google.com/apis/youtube/reference.html#Query_parameter_definitions
を参考に lr は追加しておいた。

query.vq = search_term
query.max_results = '5'
query.lr = 'ja'

* ja 以外の設定にして "japanese" で検索するとひどい結果になるとの指摘を最近みかけたので。

また、以下の値は検索キーによっては値が得られないことがあるため分岐が必要となる。
rating.average 
 if entry.rating:

2008年8月31日日曜日

NormalizeAndTypeCheck エラー

reference などの key は .key() が必要

○ login.session.key()
× login.session

忘れた場合のエラー

keys, multiple = datastore.NormalizeAndTypeCheckKeys(keys)
File "C:\Program Files\Google\google_appengine\google\appengine\api\datastore.py", line 117, in NormalizeAndTypeCheckK
ys
keys, multiple = NormalizeAndTypeCheck(keys, (basestring, Entity, Key))
File "C:\Program Files\Google\google_appengine\google\appengine\api\datastore.py", line 96, in NormalizeAndTypeCheck
(types, arg, typename(arg)))
adArgumentError: Expected an instance or sequence of (, , ); received (a Session).

2008年8月26日火曜日

mixi openid

Google App Engine上でmixi OpenIDを使ってユーザ認証をするサンプルコード - yanbe.diff - subtech  
を参考にテストしたところ
local:8080 だと動作するが Cloud (GAE に upload すると)だと以下のエラーとなる。
---
Traceback (most recent call last):
File "/base/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 499, in __call__
handler.get(*groups)
File "/base/data/home/apps/blog-editor/1.937/mixi_login.py", line 28, in get
request = consumer.begin('https://mixi.jp')
File "/base/data/home/apps/blog-editor/1.937/openid/consumer/consumer.py", line 354, in begin
'No usable OpenID services found for %s' % (user_url,), None)
DiscoveryFailure: No usable OpenID services found for https://mixi.jp
----

以下、参考

http://d.hatena.ne.jp/mitsugi-bb/20080823/1219592219#c


http://www.socialpreneur.info/ja/blog/784

http://ms76.jp/2008/08/22/mixi_openid_for_wordpress/


http://insilico.jognote.com/blog/2008/08/13/curl-%E3%81%AB-https-%E3%81%A7%E3%82%A2%E3%82%AF%E3%82%BB%E3%82%B9%E3%81%A7%E3%81%8D%E3%82%8B%E3%82%88%E3%81%86%E3%81%AB%E8%A8%BC%E6%98%8E%E6%9B%B8%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B/

---
おそらくこれが原因
Issue 407 http://code.google.com/p/googleappengine/issues/detail?id=407 :
webapp.RequestHandler.redirect missing location header for long urls

2008年8月12日火曜日

spreadsheet からの GAE への upload

GAE SDK付属のdemo/guestbook.py をベースに spreadsheet.google.com のデータを
GAE Cloud の datastore に upload する script を作成
参考ファイルはこちら guestbook.py
今回程度のレコードサイズのデータの場合、read は 150 レコード、 put (write)は 20~30レコード程度毎の処理としました。

利用方法

  1. まず、spreadsheet のデータを読み込みます。

    • 今回は対象は DOW の株価データで 960 レコード程度です。
    • SDK 環境では一度にすべての spreadsheet のデータを読み込むことができましたが、
      cloud では 100 行程度 ( 200行はエラー ) ごとに複数のシートにデータを分割
    • "read" とし、シートの key と シート番号を指定
    •  1 sheet 分のデータを Memcache に読み込みます。


  2. 読み込んだデータを GAE Cloud の datastore に書き込みます。

    • "put" を指定
    • 100 行一度に書き込もうとするとエラーになりますので、今回の場合、20行程度ごとに
      区切り、 offset をかけながら、何度かに分けて書き込み処理を行ないました。


  3. offset は自動的に加算するようにしましたので、[Sign Guest]を繰り返しクリック

  4. 1 sheet 分のデータの upload が完了したら Memcache をクリア
  5. 次のシート番号を指定し、同様の作業を繰り返します。



2008年8月11日月曜日

Memcache API

http://code.google.com/appengine/docs/memcache/

日本語訳 http://d.hatena.ne.jp/technohippy/20080717#1216393318



memcache.add( key, value, time=xx, min_compress_len=0)
time 設定した有効時間(単位秒)以後は再度、検索処理を行なう
Optional expiration time, either relative number of seconds from current time (up to 1 month), or an absolute Unix epoch time. By default, items never expire, though items may be evicted due to memory pressure. Float values will be rounded up to the nearest whole second.   



2008年8月4日月曜日

Debug デバッグ

quick and dirty: きれいではなけれども簡単な方法(開発環境用)
* Cloud ではログにエラー出力されるの危険
import sys
print >>sys.stderr, "xxxxxxx"


正しくは
import logging
logging.debug("xxxxxxx")

def main():
# Set the logging level in the main function
# See the section on Requests and App Caching for information on how
# App Engine reuses your request handlers when you specify a main function
logging
.getLogger().setLevel(logging.DEBUG)
application
= webapp.WSGIApplication([('/', MainPage),
('/sign', Guestbook)],
debug
=True)
webapp
.util.run_wsgi_app(application)

if __name__ = '__main__':
main
()

参考
http://code.google.com/appengine/articles/logging.html
http://code.google.com/appengine/docs/python/logging.html
http://groups.google.com/group/google-appengine/browse_thread/thread/a67752ac402bb21e/345e203a5bdd0750?lnk=gst&q=debug+#345e203a5bdd0750
・Django Middleware で Traceback をコンソールに出力する
http://yamashita.dyndns.org/blog/django-middleware-traceback/

Unityでドアの開閉はAnimatorそれともiTween?

Mac Mini M2 の Unity で Sketchup のデータを復元したつづき。 以前、苦労して作成したドアの開閉が動作しないので修復する。 どうやって動かしていたのか、また忘れそうなので記録しておく。             Animator 左右のドア PlaneL,...