How to programmatically put data into a Google Appengine database from a remote executable file?

I would like to pre-populate and periodically post data to the Google Appengine database.

I would like to write a program in java and python that connect to my GAE service and load data into my database.

How can i do this?

thanks

+4
source share
1 answer

To do this, use the RemoteAPI software.

In python, you can configure appengine_console.py first, as described here

After that, you can run and write the following commands in the python shell:

$ python appengine_console.py yourapp

>>> import yourdbmodelclassnamehere >>> m = yourmodelclassnamehere(x='',y='') >>> m.put() 

And here is the code from the java version that he himself explains (directly borrowed from the remote api page on gae docs ):

 package remoteapiexample; import com.google.appengine.api.datastore.DatastoreService; import com.google.appengine.api.datastore.DatastoreServiceFactory; import com.google.appengine.api.datastore.Entity; import com.google.appengine.tools.remoteapi.RemoteApiInstaller; import com.google.appengine.tools.remoteapi.RemoteApiOptions; import java.io.IOException; public class RemoteApiExample { public static void main(String[] args) throws IOException { String username = System.console().readLine("username: "); String password = new String(System.console().readPassword("password: ")); RemoteApiOptions options = new RemoteApiOptions() .server("<your app>.appspot.com", 443) .credentials(username, password); RemoteApiInstaller installer = new RemoteApiInstaller(); installer.install(options); try { DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); System.out.println("Key of new entity is " + ds.put(new Entity("Hello Remote API!"))); } finally { installer.uninstall(); } } } 
+3
source

Source: https://habr.com/ru/post/1348132/


All Articles