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 a998655
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 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,15 +35,15 @@ class User(ndb.Model):

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


def check_word_datastore(user_id, check_word):
try:
key = ndb.Key.from_path(u'User', user_id)
key = ndb.Key(u'User', user_id)
user = ndb.get(key)
words = user.words.split(u',')
if check_word in words:
Expand All @@ -56,14 +55,13 @@ 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)
key = ndb.Key(u'User', user_id)
user = ndb.get(key)
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 a998655

Please sign in to comment.