Beispiel #1
0
def editDictEntry(user, original_word, new_string):
    original_word, _ = parseOpt(original_word)
    dict_entry = Dictionary.all().\
        filter("twitter_user ="******"word =", original_word.strip()).get()
    if dict_entry:
        parsed_dict = parseMessage(new_string, '')
        if parsed_dict != {}:
            dict_entry.word = parsed_dict["word"]
            dict_entry.meaning = parsed_dict["meaning"]
            dict_entry.pronounce = parsed_dict["pronounce"]
            dict_entry.put()
    return json.dumps({})
Beispiel #2
0
    def testCheckForAnswer(self):
        # I should collapse this code into something reusable
        Twitter = TwitterMockup()
        today = datetime.date.today()
        current_time = int(time.time())
        
        u = self.createUser("da_zbur","enabled",10)
        u.use_questions = "yes"
        u.put()

        d1 = self.createDictEntry("da_zbur",2,"lucrative",\
            u"profitable, moneymaking, remunerative","[LOO-kruh-tiv]")
        
        l1 = self.createLearnListItem("da_zbur",d1,today,current_time)
        
        # forcing question to be asked        
        l1.total_served = 4
        l1.put()
       
        buildDailyList(today, logging)
        # Keep in mind building daily list means serve times will be 
        # randomly distributed throighout the day!
        l1.next_serve_time = current_time
        l1.put()

        messages_generator = sendMessagesGenerator(Twitter, logging)
        m_list = []
        while True:
            try:
                message = messages_generator.next()
            except StopIteration:
                break
            m_list.append(message)

        q = Question.all().fetch(1)[0]

        # Question for word d1 was genereated and sent
        # Now user prepares an answer
        answer = "lucrative: moneymaking, profitable"
        m = Twitter.api.PostUpdate(answer, in_reply_to_s_id=q.question_message_id)
        parsed_dict = parseMessage(m.text)
        q2 = checkForAnswer(parsed_dict, u.twitter)
        self.assertEqual(q.key(), q2.key())
Beispiel #3
0
 def post(self):
     user = current_user()
     text = self.request.get("new_word")
     message_dict = parseMessage(text, '')
     addNewWord(message_dict, user, None)
     self.redirect("/vocabulary")
Beispiel #4
0
 def testParsing4(self):
     message = "@LangBotStage You will be singled out for promotion in your work"
     result = parseMessage(message, "LanguageBot")
     self.assertEqual(result, {})
Beispiel #5
0
 def testParsing3(self):
     message = "вcе прекрасно, но бот твои сообщения не видит, нужно писать @LanguageBot :)"
     result = parseMessage(message, "LanguageBot")
     self.assertEqual(result, {})
Beispiel #6
0
 def testParsing2(self):
     message = "  @languagebot lucrative[LOO-kruh-tiv]: profitable, moneymaking, remunerative "
     result = parseMessage(message, "LanguageBot")
     self.assertEqual(result['word'], "lucrative")
     self.assertEqual(result['pronounce'], "[LOO-kruh-tiv]")
     self.assertEqual(result['meaning'], "profitable, moneymaking, remunerative")
Beispiel #7
0
 def testParsing1(self):
     message = "@LanguageBot capex: capital expenditures; капитальные затраты"
     result = parseMessage(message, "LanguageBot")
     self.assertEqual(result['word'], "capex")
     self.assertEqual(result['pronounce'], "")
     self.assertEqual(result['meaning'], "capital expenditures, капитальные затраты")