def get(self): user = users.get_current_user() # Need admin access to import #if not user.is_current_user_admin(): # self.error(403) # Fetch JSON of published spreadsheet url = "http://spreadsheets.google.com/feeds/list/0AgsXfkShVJOsdHZ4bDlabGJRZVhEU0c0MTlLUzdiZ3c/od6/public/values?alt=json" result = urlfetch.fetch(url) count = 0 if result.status_code == 200: feed_obj = simplejson.loads(result.content) if "feed" in feed_obj: entries = feed_obj["feed"]["entry"] # Make an Application entity for each entry in feed for entry in entries: hindi = entry['gsx$hindi']['$t'] english = entry['gsx$english']['$t'] word = Word(hindi, english) word.put() count = count + 1 self.response.out.write("Words imported = " + count)
def get(self): self.jsonData = Word.all().fetch(1000) lang = self.request.params.get('lang') if lang == 'a2b': words = [ {'id': word.key().id(), 'question': word.langA, 'answer': word.langB } for word in self.jsonData] else: words = [ {'id': word.key().id(), 'question': word.langB, 'answer': word.langA } for word in self.jsonData] self.jsonData = { "words": words}; self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(self.jsonData))