Created
June 29, 2012 11:23
-
-
Save fabiosussetto/3017426 to your computer and use it in GitHub Desktop.
Appengine remote API into script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
import os | |
import sys | |
# Hardwire in appengine modules to PYTHONPATH | |
# or use wrapper to do it more elegantly | |
appengine_dirs = ['/Applications/blah/blah/google_appengine'...] | |
sys.path.extend(appengine_dirs) | |
# Add your models to path | |
my_root_dir = os.path.abspath(os.path.dirname(__file__)) | |
sys.path.insert(0, my_root_dir) | |
from google.appengine.ext import db | |
from google.appengine.ext.remote_api import remote_api_stub | |
import getpass | |
from models.mystuff import Foo | |
APP_NAME = 'my-app' | |
os.environ['AUTH_DOMAIN'] = 'gmail.com' | |
os.environ['USER_EMAIL'] = '[email protected]' | |
def auth_func(): | |
return (raw_input('Username:'), getpass.getpass('Password:')) | |
# Use local dev server by passing in as parameter: | |
# servername='localhost:8080' | |
# Otherwise, remote_api assumes you are targeting APP_NAME.appspot.com | |
remote_api_stub.ConfigureRemoteDatastore(APP_NAME, | |
'/remote_api', auth_func) | |
# Do stuff like your code was running on App Engine | |
foos = Foo.all().fetch(100) | |
for foo in foos: | |
foo.note = 'Hello World!' | |
db.puts(foos) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment