[google-appengine] ideas for conditional routing

2012-07-27 Thread soujiro0725
GAE for Python 1.7.0


We normally set up the routing like,

PAGE_RE = r'(/(?:[a-zA-Z0-9_-]+/?)*)'  
>
app = webapp2.WSGIApplication([('/?', MainPage),
>('/signup', Register),
>('/login', Login),
>('/logout', Logout),
>('/_upload', Upload),
>('/_accept', AcceptPost),
>('/?' + JSON_LIST_RE, JsonListHandler),
>('/(.*).json', JsonHandler),
>('/_edit' + PAGE_RE, EditPageHandler),
>('/_history' + PAGE_RE, HistoryHandler),
>('/?' + PAGE_RE, WordPageHandler),
>('/?' + LIST_RE, WordListPageHandler),
>('/(.*)', WordPageHandler)
>],
>   debug=True)


An appropriate handler is to be chosen in accordance with the regular 
expression and the order of the handlers.
But it is getting messy.  I need to clean things up.

So hopefully I would like to pass it through conditional statements.

class Conditional(Handler):
> def get(self, newpost):
> if "+" in newpost:
> self.response.write('choice 1')
> else:
> self.response.write('choice 2')


My question is How can I apply a handler IN the handler?

in the above Conditional(Handler): case, I tried to put 'WordPageHandler'. 
 Certainly it does not seem to work

class Conditional(Handler):
> def get(self, newpost):
> if "+" in newpost:
> WordPageHandler



Is is possible to set up nested handlers?




-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/Uz__iDPwZ14J.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



[google-appengine] URL percent encoding using urllib

2012-07-23 Thread soujiro0725
GAE for Python 1.7.0

 I am trying to pass chinese characters to the URL so that handlers 
recognize them through regular expressions.

the regular expression is 

CH_RE = u'[⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]'


Hopefully the regular expression catches as follows

app = webapp2.WSGIApplication([('/?', MainPage), ('/_edit' + CH_RE, 
> EditPageHandler)]



I tried an URL

http://localhost:8092/鶴


But it gives an error,

404 Not Found
> The resource could not be found.


The log shows 

INFO 2012-07-23 07:10:34,546 dev_appserver.py:2952] "GET /%E9%B6%B4 
> HTTP/1.1" 404 - 


I am a little confused.  It looks like I need to encode the given URL so 
that the regular expression can at least read it.
The AppEngine seems to automatically execute percent encoding through the 
process.

It is hard to determine what to ask you all, but I believe that the problem 
is passing encoded URL to the main function.

The question is how and where in the code do I need to specify the encoding 
process?

I apologize for such a disorganized question, but I appreciate if anyone 
points out the problem more specifically.


 

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/rPNpgGb1qOYJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Uploading a json file from local computers. URLfetch?

2012-07-22 Thread soujiro0725
Yes! It took me a while but it's working now.

Thanks.


-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/2XCgslWrml8J.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



[google-appengine] cgi.py raise KeyError, key ?

2012-07-20 Thread soujiro0725
GoogleAppEngineLauncher version 1.7.0

I'm trying to develop a service in which users can upload json files.

# -*- coding: utf-8 -*-
> import os, cgi
> import cgitb; cgitb.enable()
> import logging
> from handler import Handler 

class Upload(Handler):
> def get(self):
> self.render('upload.html')
> def post(self):
> form = cgi.FieldStorage()
> fileitem = form['filejson']
> logging.error(fileitem)
> if fileitem.filename:
> logging.error('uploaded')
> fn = os.path.basename(fileitem.filename)
> open('files/' + fn, 'wb').write(fileitem.file.read())
> message = 'The file "' + fn + '" was uploaded successfully'
> else:
> logging.error('upload failed')
> message = 'No file was uploaded'



>   File: 
>   
> 


 Handler class works fine.  But this code raises an error,

 File "/Users/ishidasouichi/Dropbox/AppEngine/worddata/upload.py", line 16, in 
post
fileitem = form['filejson']
  File "/usr/local/Cellar/python/2.7.3/lib/python2.7/cgi.py", line 541, in 
__getitem__
raise KeyError, key
KeyError: 'filejson'


I have searched the web but could not find relevant resolutions to this 
problem.

Can anyone tell me where the problem is?


-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/9j-BE6jaWR0J.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Uploading a json file from local computers. URLfetch?

2012-07-20 Thread soujiro0725
Thanks. This seems what I wanted. 

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/JT5KJxUcwrUJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] Uploading a json file from local computers. URLfetch?

2012-07-19 Thread soujiro0725
I don't want to save the files.  I want the handler to parse the json file 
content, and discard it as long as the process is successfully finished.



-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/ICQESeInh-wJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



[google-appengine] Uploading a json file from local computers. URLfetch?

2012-07-19 Thread soujiro0725
GAE for Python!

Hi. I am trying to develop a web service which users can upload json files 
and modify the data.

Users create json files at local computers, and in the web service page, 
browse the path to the files and press 'upload'.
Then, a python handler parses the file contents and make necessary changes.

My question is the process of uploading the files from local computers.

Am I supposed to use 'URL fetch' API? by indicating the URL to the local 
file storage?

Or is there any other possible way to achieve this?


soichi

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/MBQ6_bOeEtYJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] separating files for Handler

2012-07-11 Thread soujiro0725


Thanks! It's working now.


-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/d-hV7ZHfyQcJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] separating files for Handler

2012-07-11 Thread soujiro0725
Thanks! It's working now.



On Thursday, July 12, 2012 3:20:39 PM UTC+9, Jason Galea wrote:
>
>
>
> On Thu, Jul 12, 2012 at 2:50 PM, soujiro0725 wrote:
>
>> AppEngine for Python SDK latest
>>
>> Hi, I'm trying to separate the program into many files.  In order to do 
>> so, I need to put "import handler" for handler.py file if I'm correct.
>>
>> But for some reason, I keep getting errors.
>>
>
> I think you've got two options..
>
> change "import handler" to "from handler import Handler"
>
> or
>
> change "class MainPage(Handler):" to "class MainPage(handler.Handler):"
>
> cheers,
>
> J
>
>  
>
>>
>> main.py is
>>
>> import webapp2
>>> import os
>>> import jinja2
>>> import handler
>>>
>>> template_dir = os.path.join(os.path.dirname(__file__), 'templates')
>>> jinja_env = jinja2.Environment(loader = 
>>> jinja2.FileSystemLoader(template_dir),
>>>autoescape = True)
>>> def render_str(template, **params):
>>> t = jinja_env.get_template(template)
>>> return t.render(params)
>>> def make_secure_val(val):
>>> return '%s|%s' % (val, hmac.new(secret, val).hexdigest())
>>> def check_secure_val(secure_val):
>>> val = secure_val.split('|')[0]
>>> if secure_val == make_secure_val(val):
>>> return val
>>> class MainPage(Handler):
>>> def get(self):
>>> self.response.headers['Content-Type'] = 'text/plain'
>>> self.render('front.html', wikis = wikis[0], time = 
>>> int(diff.total_seconds()))
>>> app = webapp2.WSGIApplication([('/?', MainPage)], debug=True)
>>
>>
>>  handler.py is
>>
>> import webapp2
>>> class Handler(webapp2.RequestHandler):
>>> def write(self, *a, **kw):
>>> self.response.out.write(*a, **kw)
>>> def render_str(self, template, **params):
>>> params['user'] = self.user
>>> return render_str(template, **params)
>>> def render(self, template, **kw):
>>> self.write(self.render_str(template, **kw))
>>> def set_secure_cookie(self, name, val):
>>> cookie_val = make_secure_val(val)
>>> self.response.headers.add_header(
>>> 'Set-Cookie',
>>> '%s=%s; Path=/' % (name, cookie_val))
>>> def read_secure_cookie(self, name):
>>> cookie_val = self.request.cookies.get(name)
>>> return cookie_val and check_secure_val(cookie_val)
>>> def login(self, user):
>>> self.set_secure_cookie('user_id', str(user.key().id()))
>>> def logout(self):
>>> self.response.headers.add_header('Set-Cookie', 'user_id=; 
>>> Path=/')
>>> def initialize(self, *a, **kw):
>>> webapp2.RequestHandler.initialize(self, *a, **kw)
>>> uid = self.read_secure_cookie('user_id')
>>> self.user = uid and User.by_id(int(uid))
>>
>>
>> This raises an error,
>>
>>   File "/Users/ishidasouichi/appengine_python/chword/main.py", line 28, 
>>> in 
>>> class MainPage(Handler):
>>> NameError: name 'Handler' is not defined
>>> INFO 2012-07-12 04:40:05,243 dev_appserver.py:2904] "GET 
>>> /favicon.ico HTTP/1.1" 500 - 
>>
>>
>> Looks like main.py is not reading handler.py at all.  
>>
>> Could anyone point out the mistake I am making?  
>>
>> soujiro0725 
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Google App Engine" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/google-appengine/-/V4KbCWSLNBsJ.
>> To post to this group, send email to google-appengine@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> google-appengine+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/google-appengine?hl=en.
>>
>
>
>
> -- 
> Jason Galea
> ja...@lecstor.com
>
> http://lecstor.com
> https://github.com/lecstor
> https://metacpan.org/author/LECSTOR
> http://au.linkedin.com/in/jasongalea
> https://plus.google.com/110776762575649383381
> https://twitter.com/Lecstor
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/dXdhlekA6VkJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



[google-appengine] separating files for Handler

2012-07-11 Thread soujiro0725
AppEngine for Python SDK latest

Hi, I'm trying to separate the program into many files.  In order to do so, 
I need to put "import handler" for handler.py file if I'm correct.

But for some reason, I keep getting errors.

main.py is

import webapp2
> import os
> import jinja2
> import handler
>
> template_dir = os.path.join(os.path.dirname(__file__), 'templates')
> jinja_env = jinja2.Environment(loader = 
> jinja2.FileSystemLoader(template_dir),
>autoescape = True)
> def render_str(template, **params):
> t = jinja_env.get_template(template)
> return t.render(params)
> def make_secure_val(val):
> return '%s|%s' % (val, hmac.new(secret, val).hexdigest())
> def check_secure_val(secure_val):
> val = secure_val.split('|')[0]
> if secure_val == make_secure_val(val):
> return val
> class MainPage(Handler):
> def get(self):
> self.response.headers['Content-Type'] = 'text/plain'
> self.render('front.html', wikis = wikis[0], time = 
> int(diff.total_seconds()))
> app = webapp2.WSGIApplication([('/?', MainPage)], debug=True)


 handler.py is

import webapp2
> class Handler(webapp2.RequestHandler):
> def write(self, *a, **kw):
> self.response.out.write(*a, **kw)
> def render_str(self, template, **params):
> params['user'] = self.user
> return render_str(template, **params)
> def render(self, template, **kw):
> self.write(self.render_str(template, **kw))
> def set_secure_cookie(self, name, val):
> cookie_val = make_secure_val(val)
> self.response.headers.add_header(
> 'Set-Cookie',
> '%s=%s; Path=/' % (name, cookie_val))
> def read_secure_cookie(self, name):
> cookie_val = self.request.cookies.get(name)
> return cookie_val and check_secure_val(cookie_val)
> def login(self, user):
> self.set_secure_cookie('user_id', str(user.key().id()))
> def logout(self):
> self.response.headers.add_header('Set-Cookie', 'user_id=; Path=/')
> def initialize(self, *a, **kw):
> webapp2.RequestHandler.initialize(self, *a, **kw)
> uid = self.read_secure_cookie('user_id')
> self.user = uid and User.by_id(int(uid))


This raises an error,

  File "/Users/ishidasouichi/appengine_python/chword/main.py", line 28, in 
> 
> class MainPage(Handler):
> NameError: name 'Handler' is not defined
> INFO 2012-07-12 04:40:05,243 dev_appserver.py:2904] "GET /favicon.ico 
> HTTP/1.1" 500 - 


Looks like main.py is not reading handler.py at all.  

Could anyone point out the mistake I am making?  

soujiro0725 

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/V4KbCWSLNBsJ.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



[google-appengine] Re: obtaining rich text editor content jQuery? or python?

2012-06-07 Thread soujiro0725
thanks for your answer.
I will check it out.

soujiro

On Jun 6, 8:56 pm, Barry Hunter  wrote:
> nearly every WYSIWYG/rich text editor I have used, automatically puts
> the raw html from the editor into a hidden textarea.
>
> ie the server application, just recieves the posted form, just the
> same as if it was a text area.
>
> No need for messing with jquery.
>
> Check the documentation for the rich text editor you are using.
>
>
>
>
>
>
>
> On Wed, Jun 6, 2012 at 8:56 AM, soujiro0725  wrote:
> > Hi. I am developing a sort of Wiki, where I put a rich text editor.
>
> > The data which the rich text editor generates is of course is a form
> > of html, and it looks like,
>
> >  > #document
> >  
> >     >       >         > ...
> > 
>
> > I believe I need to obtain the entire html part to make persistent in
> > datastore.
>
> > My question is how do you think I should get the value?
>
> > Certainly there are many ways but I need an efficient way.
>
> > Should I use jQuery to pass the part starting from "#document" ?
> > Of should I get it directly using Python?
>
> > I wonder how I can take advantage of the "#document" marker,
> > indicating the html content.
>
> > thanks in advance
>
> > soujiro
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Google App Engine" group.
> > To post to this group, send email to google-appengine@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > google-appengine+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/google-appengine?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



[google-appengine] obtaining rich text editor content jQuery? or python?

2012-06-06 Thread soujiro0725
Hi. I am developing a sort of Wiki, where I put a rich text editor.

The data which the rich text editor generates is of course is a form
of html, and it looks like,




I believe I need to obtain the entire html part to make persistent in
datastore.

My question is how do you think I should get the value?

Certainly there are many ways but I need an efficient way.

Should I use jQuery to pass the part starting from "#document" ?
Of should I get it directly using Python?

I wonder how I can take advantage of the "#document" marker,
indicating the html content.

thanks in advance

soujiro

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



[google-appengine] Re: Error for Twitter Bot : java.lang.NoClassDefFoundError: com/google/gdata/util/ServiceException

2010-05-29 Thread soujiro0725
Sorry for bothering you all.  It was simple.  I forgot to copy those
libs into WEB-INF/lib.  I have only did Build-Path...

soichi


On 5月27日, 午後3:31, soujiro0725  wrote:
> hi I am trying to make a Twitter bot that produces titles of blog
> entries.  Since I am not good at Java, the problem might be in
> understanding of Java itself.
>
> I keep getting an error message "java.lang.NoClassDefFoundError: com/
> google/gdata/util/ServiceException", and I have searched the web for
> information.  But all I found was the lack of libs, such as mail.jar ,
> google.collect...jar .  I tried to include all possible libs, but no
> change at all.
>
> Could anyone help me out?
>
> // servlet that produces
> tweets-
> public class Twitter_botServlet extends HttpServlet {
>
>         private static final Logger log =
> Logger.getLogger(Twitter_botServlet.class.getName());
>         private String botname = "new_public_line";
>         private String cachedtoken = "access_token";
>         private String cachedsecret = "access_secret";
>
>         public void doGet(HttpServletRequest req, HttpServletResponse resp)
>                         throws IOException {
>                 resp.setContentType("text/plain");
>                 resp.setCharacterEncoding("utf-8");
>                 resp.getWriter().println("Hello, world");
>
>                 log.info("info test");
>                 PersistenceManager pm = PMF.get().getPersistenceManager();
>                 Cache cache = null;
>
>                 try {
>                         CacheFactory cacheFactory =
> CacheManager.getInstance().getCacheFactory();
>                         cache = 
> cacheFactory.createCache(Collections.emptyMap());
>                 } catch (CacheException e) {
>                         log.info(e.getMessage());
>                 }
>
>                 if((String)cache.get(cachedtoken) == null ||
> (String)cache.get(cachedsecret) == null){
>                         Query query = pm.newQuery(Token.class);
>                         List tokens = (List)query.execute();
>
>                         for(Token token:tokens){
>                                 if(token !=null && 
> token.getBotName().equals(botname)){
>                                         cache.put(cachedtoken, 
> token.getAccessToken());
>                                         cache.put(cachedsecret, 
> token.getAccessSecret());
>                                 }
>                         }
>                         pm.close();
>                 }
>                 GenerateInputs(cache);
>         }
>
>         private void GenerateInputs(Cache cache) {
>                 Twitter twitter = new
> TwitterFactory().getOAuthAuthorizedInstance(new
> AccessToken((String)cache.get(cachedtoken),
> (String)cache.get(cachedsecret)));
>
>                 String title = new
> GetBlogEntriesServlet().ReturnInfo();
>                 try {
>                         twitter.updateStatus(title);
>                 } catch (TwitterException e) {
>                         System.out.println(e.getMessage());
>                 }
>         }}
>
> //--- tweet servlet ends here -
>
> //--- servlet that gets a blog title-
> public class GetBlogEntriesServlet extends HttpServlet {
>         public String ReturnInfo() {
>                 String blogId = "";
>                 String title = null;
>                 try {
>                         GoogleService myService = new GoogleService("blogger",
> "twitter_bot");
>                         title = printAllPosts(myService, blogId);
>                 } catch (ServiceException e) {
>                         System.out.println(e.getMessage());
>                 } catch (IOException e) {
>                         System.out.println(e.getMessage());
>                 }
>
>                 return title;
>         }
>
>         private static String printAllPosts(GoogleService myService,
> String blogId) throws ServiceException, IOException {
>
>                 final URL feedUrl = new URL("http://www.blogger.com/feeds/"; + 
> blogId
> + "/posts/default");
>                 Feed resultFeed = myService.getFeed(feedUrl, Feed.class);
>
>                 //define array that contains entry titles
>                 String[] ArrayTitle;
>                 ArrayTitle = new String[resultFeed.getEntries().size()];
>
>                 System.out.println(resultFeed.getTitle().getPlainText());
>                 for (int i = 0; i < resultF

[google-appengine] Error for Twitter Bot : java.lang.NoClassDefFoundError: com/google/gdata/util/ServiceException

2010-05-27 Thread soujiro0725
hi I am trying to make a Twitter bot that produces titles of blog
entries.  Since I am not good at Java, the problem might be in
understanding of Java itself.

I keep getting an error message "java.lang.NoClassDefFoundError: com/
google/gdata/util/ServiceException", and I have searched the web for
information.  But all I found was the lack of libs, such as mail.jar ,
google.collect...jar .  I tried to include all possible libs, but no
change at all.

Could anyone help me out?

// servlet that produces
tweets-
public class Twitter_botServlet extends HttpServlet {

private static final Logger log =
Logger.getLogger(Twitter_botServlet.class.getName());
private String botname = "new_public_line";
private String cachedtoken = "access_token";
private String cachedsecret = "access_secret";

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.setCharacterEncoding("utf-8");
resp.getWriter().println("Hello, world");

log.info("info test");
PersistenceManager pm = PMF.get().getPersistenceManager();
Cache cache = null;

try {
CacheFactory cacheFactory =
CacheManager.getInstance().getCacheFactory();
cache = 
cacheFactory.createCache(Collections.emptyMap());
} catch (CacheException e) {
log.info(e.getMessage());
}

if((String)cache.get(cachedtoken) == null ||
(String)cache.get(cachedsecret) == null){
Query query = pm.newQuery(Token.class);
List tokens = (List)query.execute();

for(Token token:tokens){
if(token !=null && 
token.getBotName().equals(botname)){
cache.put(cachedtoken, 
token.getAccessToken());
cache.put(cachedsecret, 
token.getAccessSecret());
}
}
pm.close();
}
GenerateInputs(cache);
}

private void GenerateInputs(Cache cache) {
Twitter twitter = new
TwitterFactory().getOAuthAuthorizedInstance(new
AccessToken((String)cache.get(cachedtoken),
(String)cache.get(cachedsecret)));

String title = new
GetBlogEntriesServlet().ReturnInfo();
try {
twitter.updateStatus(title);
} catch (TwitterException e) {
System.out.println(e.getMessage());
}
}
}
//--- tweet servlet ends here -

//--- servlet that gets a blog title-
public class GetBlogEntriesServlet extends HttpServlet {
public String ReturnInfo() {
String blogId = "";
String title = null;
try {
GoogleService myService = new GoogleService("blogger",
"twitter_bot");
title = printAllPosts(myService, blogId);
} catch (ServiceException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}

return title;
}

private static String printAllPosts(GoogleService myService,
String blogId) throws ServiceException, IOException {

final URL feedUrl = new URL("http://www.blogger.com/feeds/"; + 
blogId
+ "/posts/default");
Feed resultFeed = myService.getFeed(feedUrl, Feed.class);

//define array that contains entry titles
String[] ArrayTitle;
ArrayTitle = new String[resultFeed.getEntries().size()];

System.out.println(resultFeed.getTitle().getPlainText());
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
Entry entry = resultFeed.getEntries().get(i);
ArrayTitle[i] = entry.getTitle().getPlainText();
}

//get one of blog titles using a random number
Random rnd = new Random();
int ran = rnd.nextInt(resultFeed.getEntries().size());
return ArrayTitle[ran];
}
}
//-- code ends
here--

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-ap