Skip to content

Commit

Permalink
fix(infra.py): fix to used datestore. ref #402 @0.25h
Browse files Browse the repository at this point in the history
  • Loading branch information
hayatedayon committed Jul 30, 2018
1 parent 40e116f commit 1acbd85
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions infra.py
Expand Up @@ -27,7 +27,6 @@


class User(ndb.Model):
user_id = ndb.StringProperty()
words = ndb.TextProperty()
last_word = ndb.TextProperty()
count = ndb.IntegerProperty()
Expand All @@ -36,16 +35,15 @@ class User(ndb.Model):

def reset_datastore(user_id):
try:
key = ndb.Key.from_path(u'User', user_id)
ndb.delete(key)
user = User.get_by_id(user_id)
user.key.delete()
except Exception:
pass


def check_word_datastore(user_id, check_word):
try:
key = ndb.Key.from_path(u'User', user_id)
user = ndb.get(key)
user = User.get_by_id(user_id)
words = user.words.split(u',')
if check_word in words:
return False
Expand All @@ -56,14 +54,12 @@ def check_word_datastore(user_id, check_word):

def save_word_datastore(user_id, save_word):
try:
key = ndb.Key.from_path(u'User', user_id)
user = ndb.get(key)
user = User.get_by_id(user_id)
user.words += u',' + save_word
user.count += 1
except Exception:
user = User()
user.user_id = user_id
user.words += save_word
user = User(id=user_id)
user.words = save_word
user.count = 1
user.last_word = save_word
user.put()
Expand Down
2 changes: 1 addition & 1 deletion main.py
Expand Up @@ -47,7 +47,7 @@ def post(self):
queryResult = obj[u'queryResult']
originalDetectIntentRequest = obj['originalDetectIntentRequest']
intentDisplayName = queryResult[u'intent'][u'displayName']
userId = originalDetectIntentRequest[u'user'][u'userId']
userId = originalDetectIntentRequest[u'payload'][u'user'][u'userId']

self.response.headers['Content-Type'] = 'application/json'
if intentDisplayName == GOOGLE_ASSISTANT_WELCOME_INTENT:
Expand Down

0 comments on commit 1acbd85

Please sign in to comment.