2008年4月12日土曜日

Google App Engine 入門3



  helloworld のプログラムのソースを読む


APIs

Users API を利用している
 まず、 from google.appengine.api import users してから

     author = db.UserProperty()      author.nickname()

 Instance Methods として ncikname() と email() が用意されている。
 http://code.google.com/appengine/docs/users/userclass.html

Functions として以下がある
  • create_login_url(dest_url)
  • create_logout_url(dest_url)
  • get_current_user()
  • is_current_user_admin()
  http://code.google.com/appengine/docs/users/functions.html

Datastore API

Overview
The App Engine datastore is not a relational database
いわゆる RDBMS ではない。

An entity can be created by calling the constructor of the class,

class Pet(db.Model):
name = db.StringProperty(required=True) 
pet
= Pet(name="Fluffy",
のように Entiy を定義し、値をセットして

then stored by calling the put() method.

pet.Put()
のようにデータベース( datastore ) に保存する。

The datastore API provides two interfaces for queries:
a query object interface, and a SQL-like query language called GQL.
2種類のインターフェイスを用意していて、1つはSQLみたいなものでGQLといいます。

A query returns entities in the form of instances of the model classes that can be modified and put back into the datastore.
検索した値の更新もできます
構造を把握したところで、テンプレートに以下

{{ greeting.datedate:"Y/m/d H:m:s" }}
を追加して、時間を表示するようにしたところ自動的に登録される時間がJST(日本標準時)でなくUTCとなっているのをなんとかしたい。

DateTimeProperty のところのauto_now_add=True
で時刻が自動設定されています。


author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
テンプレートで対応できれば、ベストなのですが
http://www.djangoproject.com/documentation/0.96/templates/#now
時間表示の書式設定ではフォーマットはいろいろ設定できても、計算まではできないようです。
時刻でなく、数値の加減は filter 機能で対応していました。
{{gdateadd:"-2"}}
このような感じでテンプレート側で対応できますが・・・ 日付の場合、どうするかは次回の検討事項とします。


---- memo
「Google App Engine」のメリットとデメリット

2008年4月11日金曜日

Google App Engine 入門2



Docs > Getting Started >


1. Hello, World!
2 Using the webapp Framework
3 Using the Users Service
4 Handling Forms With webapp
 ここまではチュートリアルのコードをそのまま利用できます。
5 Using the Datastore
 ここでは 4 のソースに追加するようになります。
 SQL を発行して、データベースにアクセスしているようですが、特に自分でデータベースを作成したり、テーブルを作成したりする必要なく、ローカルで稼動しました。
 一時ファイルをデータベースとして作成しているようです。

C:\google>dev_appserver.py --clear_datastore helloworld/
INFO 2008-04-11 16:43:28,375 appcfg.py] Checking for updates to the SDK.
INFO 2008-04-11 16:43:28,780 appcfg.py] The SDK is up to date.
INFO 2008-04-11 16:43:28,780 dev_appserver.py] Attempting to remove file at
c:\docume~1\user\locals~1\temp\dev_appserver.datastore
6. Using Templates
 5 のスクリプトを修正
 Django が導入され、SQL がなくなる。テンプレートの詳細は Django のサイトへ。



7. Using Static Files
 不具合注意

 windows 環境では bug 対応が必要
app.yaml と \google\appengine\tools\dev_appserver.py を修正する。
see -> http://d.hatena.ne.jp/Aoba/20080410/1207842114
 上記も含めいろいろやったが
INFO 2008-04-11 16:01:44,328 dev_appserver.py] "GET /stylesheets/main.css HTTP/1.1" 404 -
が止まらず。 

link type="text/css" rel="stylesheet" href="c:/google/helloworld/stylesheets/main.css"
のように絶対パスで書くとエラーは止まるが、cssは適用されていない様子。
dev_appserver.py は修正した状態。
結局、このファイルは元に戻して、 css ファイルは分けるのをやめた。
- index.html 内に当面、記述

<head>
<style type="text/css">
body {
font-family: Verdana, Helvetica, sans-serif;
background-color: #DDDDDD;
}
</style>
</head>

追記:  以下のような対策で利用可能となりました。 app.yaml の変更

- url: /css/(.*\.css)
static_files: css/\1
upload: css/(.*\.css)


やはり javascript などの利用を考えた場合、別ファイルにできないのはつらい。

8. Uploading Your Application
 アカウントが必要


その他のエラー対応

・ helloworld.py の改行が正しくなく、2行が1行になっているときに以下のようなエラーとなります。

Python 2.5.2: C:\Python25\python.exeFri Apr 11 13:01:06 2008
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.p in _HandleRequest(self=)
2243 infile,
2244 outfile,
2245 base_env_dict=env_dict)
2246 finally:
2247 self.module_manager.UpdateModuleFileModificationTimes()
base_env_dict undefined, env_dict = {'REMOTE_ADDR': '127.0.0.1', 'REQUEST_METHOD': 'GET', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', 'SERVER_SOFTWARE': 'Development/1.0'}


・ main.css ファイルの文字コードが sjis になっていた時のエラー

ERROR 2008-04-11 14:59:53,453 __init__.py] Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 486, in __call__ handler.post(*groups) File "C:\Documents and Settings\kt\My Documents\google\helloworld\helloworld.py", line 39, in post greeting.put() File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 602, in put self._save_to_entity() File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 621, in _save_to_entity self._store_to_entity(self._entity) File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 587, in _store_to_entity entity[prop.name] = datastore_value File "C:\Program Files\Google\google_appengine\google\appengine\api\datastore.py", line 341, in __setitem__ datastore_types.ToPropertyPb(name, value) File "C:\Program Files\Google\google_appengine\google\appengine\api\datastore_types.py", line 976, in ToPropertyPb pbvalue.mutable_uservalue().set_email(v.email().encode('utf-8'))UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 3: ordinalnot in range(128)
----------------------------------------------------



Google App Engine 入門1



「Google App Engine」の登場とPaaS--Web 2.5がもたらす変化 2008/04/10 17:27
http://japan.cnet.com/column/pers/story/0,2000055923,20371171,00.htm


1. Google App Engine SDK は Python 2.5 が前提
Python 2.5 をインストール         http://www.python.org/download/

2. SDK をインストール
Google App Engine General Questions http://code.google.com/appengine/kb/general.html
Download the SDK をダウンロード    http://code.google.com/appengine/downloads.html


既にパスは通っている。
C:\>path
PATH=C:\WINDOWS\system32;
C:\Program Files\Google\google_appengine\


3. helloworld を動かす

Docs >Getting Started >Hello, World!
を参考に





3.1  2つのファイルを作成

 C:> cd Documents and Settings\user\My Documents\google
 C:> md helloworld

helloworld ディレクトリに以下の2つのファイルを作成

-helloworld.py-

#!-*- coding:utf-8 -*-
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'


* ローカルでなく、 Google Upload の場合、日本語対応には必要
  [ #!-*- coding:utf-8 -*- ] c.f

-app.yaml -
application: helloworld
version: 1
runtime: pythonapi_version: 1
handlers:- url: /.*
script: helloworld.py

5.  DOS prompt より以下のコマンドを実行 (自動的に webサーバーが起動される)
C:\Documents and Settings\user\My Documents\google>dev_appserver.py helloworld/

6.  ブラウザデアクセスしてみる










7.  DOS prompt の出力の様子

C:\Documents and Settings\user\My Documents\google>dev_appserver.py helloworld/
Allow dev_appserver to check for updates on startup? (Y/n): y
dev_appserver will check for updates on startup. To change this setting, edit C:\Documents and Settings\user/.appcfg_nag

INFO 2008-04-11 11:28:02,328 appcfg.py] Checking for updates to the SDK.
INFO 2008-04-11 11:28:02,733 appcfg.py] The SDK is up to date.
WARNING 2008-04-11 11:28:02,733 datastore_file_stub.py] Could not read datastore data from c:\docume~1\user\locals~1\temp\dev_appserver.datastore
WARNING 2008-04-11 11:28:02,733 datastore_file_stub.py] Could not read datastore data from c:\docume~1\user\locals~1\temp\dev_appserver.datastore.history
INFO 2008-04-11 11:28:02,750 dev_appserver_main.py] Running application helloworld on port 8080:
http://localhost:8080

INFO 2008-04-11 11:31:28,092 dev_appserver.py] "GET / HTTP/1.1" 200 -
INFO 2008-04-11 11:31:28,108 dev_appserver_index.py] Updating C:\Documents and Settings\user\My Documents\google\helloworld\index.yaml
INFO 2008-04-11 11:31:28,171 dev_appserver.py] "GET /favicon.ico HTTP/1.1" 200 -
INFO 2008-04-11 11:31:41,296 dev_appserver.py] "GET / HTTP/1.1" 200 -
INFO 2008-04-11 11:31:42,217 dev_appserver.py] "GET / HTTP/1.1" 200 -
INFO 2008-04-11 11:31:45,296 dev_appserver.py] "GET / HTTP/1.1" 200 -



拡張子 .py が Python と関連付けられている。
以前、install した python22 を uninstall した
際、この情報も削除され
c:> dev_appserver.py が起動しなくなった。

Python.exe に PATH が通っている必要はないが
拡張子 .py との関連付けは必要。










8. 紹介 Vide の様子  ひと昔まえまではこうした雰囲気を味わうには会場のいくしかなかった。

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

Announcing Google App Engine at Campfire One on April 7, 2008

2007年12月11日火曜日

Google Map , Calendar , Sketchup

Google Map APIのSign up for a Google Maps API key. で表示するドメイン用の API Key を取得する必要があった?
現在は  Google マップを自分のサイトに貼り付けよう にしたがって、貼り付けるだけで表示は可能。


カレンダー

sketchup
 Video チュートリアル
 sketchupを楽しもう
 レイヤーの変更

Sketchup のデータを Second Life にもっていくには blender 経由、あるいは Google Sketchup -> Second Life export にあるように ruby APIを使うとある程度可能な様子。Ruby スクリプトにサンプルがある。


Lib PC Parts
Google Sketchup Paradise


背景を透明にする方法(Photoshop Elements)

2007年11月29日木曜日

Javascript

Stylesheet との関係で id と class の使い分けがわからなかったので検索してみた。
個別の“要素”(タグ)に class属性 を指定し、そのクラスをセレクタとすることで、よりきめ細かなスタイル設定ができるようになっています。また、id属性とスタイルを対応させれば、ドキュメントの中でそのidを持つ“要素”だけに適用されるスタイルを定義できます。
確かに「JavaScriptは邪道」という意識はあった。
ここでみつけた jQuery を使ってみたが、これを使うとかなり楽になる様子。日本語の解説もあった。
カレンダーなどもjQueryベースのものがある。これで入力はできるが、検知の仕方やら
   $('#example').datepicker();
   $('#example').change(function(){
   // alert ("test") ;
   $("<div><p>" + $(this).val() +"</p></div> ").appendTo("body");
   });
月末を求めたり文字列の置換行追加追加したエレメントに文字表示 など基本的なことも確認しないと。 再入門。 FirebugでDebugできる。


JQuery Memo
$("#sl_avatar").load("/search",{});
これにより POST になる。
省略すると GET で http 405エラーとなるケースがある。


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="jquery-1.2.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input.buttonBslideup").click(function(){
alert("test");
$("#sl_avatar").load("./test2.html");
});
});
</script>
</head>
<body>
<input type="button" value="buttonBslideup" class="buttonBslideup" />
<div id="sl_avatar"> div sl_avatar</div>
</body>
</html>

Bloger への html 入力 

JQuey  Get the input field's value with the name of 'bar':
 $("input[@name=bar]").val();

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

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