示例#1
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        user = users.get_current_user()
        if user == None:
            template_values = {
                'login_url': users.create_login_url(self.request.uri)
            }
            template = JINJA_ENVIRONMENT.get_template('mainpage_guest.html')
            self.response.write(template.render(template_values))
            return
        myuser_key = ndb.Key('MyUser', user.user_id())
        myuser = myuser_key.get()
        if myuser == None:
            myuser = MyUser(username=user.email(),
                            id=user.user_id(),
                            myAnagram=0,
                            myWordCount=0)
            myuser.put()
        ana = Anagram.query().fetch()
        # c = Counter();
        template_values = {
            'logout_url': users.create_logout_url(self.request.uri),
            'user': user,
            'myuser': myuser,
            'ana': ana
            # ,
            # 'counter': getAnaCount()
        }

        template = JINJA_ENVIRONMENT.get_template('main.html')
        self.response.write(template.render(template_values))
示例#2
0
    def post(self):

        self.response.headers['Content-Type'] = 'text/html'
        action = self.request.get('button')
        if action == 'SEARCH':

            user = users.get_current_user()
            myuser_key = ndb.Key('MyUser', user.user_id())
            myuser = myuser_key.get()

            searchText = (self.request.get('word')).lower()
            if searchText == "":
                message = "Word not found"
                template_values = {
                    'user': user,
                    'message': "Word not found",
                    'ana': Anagram.query().fetch()
                }
                template = JINJA_ENVIRONMENT.get_template('main.html')
                self.response.write(template.render(template_values))
            else:
                search_key = lexi(searchText)

                ana_key = ndb.Key("Anagram", user.email() + search_key)
                ana = ana_key.get()

                template_values = {'ana': ana, 'user': user, 'myuser': myuser}
                template = JINJA_ENVIRONMENT.get_template('main.html')
                self.response.write(template.render(template_values))
示例#3
0
    def post(self):

        self.response.headers["Content-Type"] = "text/html"

        file = self.request.get("textfile")
        openFile = open(file)
        readLine = openFile.readline()

        while readLine:

            text_word = (readLine.strip('\n\r')).lower()
            sorted_key = Services().sorted_key(word=text_word)

            list_word = Anagram.query()
            list_word = list_word.filter(
                Anagram.anagram_key == sorted_key,
                Anagram.user_id == Services().get_current_user_id())
            list_word = list_word.fetch()

            valid_permutation = Services().validpermutations(text=sorted_key)

            if len(valid_permutation) > 0:

                if len(list_word) > 0:

                    anagram = list_word[0]

                    if text_word not in anagram.inputed_words:
                        inputed_words = anagram.inputed_words
                        inputed_words.append(text_word)
                        anagram.inputed_words = inputed_words
                        anagram.inputed_words_count = anagram.inputed_words_count + 1
                        anagram.put()

                else:

                    new_anagram = Anagram(
                        anagram_key=sorted_key,
                        anagram_words=Services().possiblepermutations(
                            text=sorted_key),
                        inputed_words=[text_word],
                        inputed_words_count=1,
                        word_length=len(text_word),
                        user_id=Services().get_current_user_id())
                    new_anagram.put()

            readLine = openFile.readline()

        openFile.close()

        message = "Upload completed"

        template_values = {'message': message}

        template = JINJA_ENVIRONMENT.get_template("importdata.html")
        self.response.write(template.render(template_values))
    def get(self):

        self.response.headers["Content-Type"] = "text/html"

        user = Services().get_current_user()
        word_model = Anagram.query()
        anagram_model = None

        if user:
            url = users.create_logout_url(self.request.uri)
            myuser_key = ndb.Key("MyUser", Services().get_current_user_id())
            myuser = myuser_key.get()

            if myuser == None:
                myuser = MyUser(id=user.user_id())
                myuser.put()

            anagram_query = Anagram.query(Anagram.user_id == Services().get_current_user_id())
            inputed_word = self.request.get("input_word").lower()


            if len(inputed_word) > 0:

                if self.request.GET.get("search") == "Search Word":

                    anagram_query = anagram_query.filter(Anagram.inputed_words.IN([inputed_word]))

            anagram_model = anagram_query.fetch()

        else:
            url = users.create_login_url(self.request.uri)


        template_values = {
            "url": url,
            "user": user,
            "anagram_model":anagram_model
        }

        template = JINJA_ENVIRONMENT.get_template("main.html")
        self.response.write(template.render(template_values))
示例#5
0
    def get(self):

        self.response.headers["Content-Type"] = "text/html"
        user = Services().get_current_user()
        total_count = 0
        unique_anagrams = 0
        #  word_model = Anagram.query()
        anagram_model = None
        # checking the user
        if user:
            url = users.create_logout_url(self.request.uri)
            user_key = ndb.Key("MyUser", Services().get_current_user_id())
            user = user_key.get()
            # creating user and storing in data base
            if user == None:
                user = MyUser(id=Services().get_current_user_id())
                user.put()
# storing th word in the anagram query and converting them to lower case letters
            anagram_query = Anagram.query(
                Anagram.user_id == Services().get_current_user_id())
            anagram_count_query = anagram_query.fetch()
            unique_anagrams = len(anagram_count_query)

            for inputed_word in anagram_count_query:
                for word in inputed_word.input_words:
                    total_count += 1
            input_word = self.request.get("input_word").lower()
            # checking lenth of the word
            if len(input_word) > 0:
                # checking whether the button is search or not
                if self.request.GET.get("search_button") == "Search Word":
                    # filtering the anagram query
                    anagram_query = anagram_query.filter(
                        Anagram.input_words.IN([input_word]))
# fetching the filterd anagram query
            anagram_model = anagram_query.fetch()
# creating login for user
        else:
            url = users.create_login_url(self.request.uri)
# tempate values storing all the required values
        template_values = {
            "url": url,
            "user": user,
            "anagram_model": anagram_model,
            "unique_anagrams": unique_anagrams,
            "total_count": total_count,
        }
        # environment for the templatr values
        template = JINJA_ENVIRONMENT.get_template("main.html")
        self.response.write(template.render(template_values))
    def post(self):

        self.response.headers["Content-Type"] = "text/html"

        if self.request.get("addword") == "Add Word":
            user_word = self.request.get("word").lower()

            if Services().get_current_user() == None or user_word == None or user_word == "" :
                self.redirect("/addword")
                return

            current_user_id = Services().get_current_user_id()
            sorted_key = Services().sorted_key(word =user_word)

            list_word = Anagram.query()
            list_word = list_word.filter(Anagram.anagram_key == sorted_key,Anagram.user_id == current_user_id)
            list_word = list_word.fetch()

            valid_permutation = Services().validpermutations(text=sorted_key)


            if len(valid_permutation) == 0:
                self.redirect("/addword")
                return

            if len(list_word) > 0:
                anagram = list_word[0]

                if user_word in anagram.inputed_words:
                    self.redirect("/addword")
                    return

                inputed_words = anagram.inputed_words
                inputed_words.append(user_word)
                anagram.inputed_words = inputed_words
                anagram.inputed_words_count = anagram.inputed_words_count + 1
                anagram.put()

            else:

                new_anagram = Anagram(anagram_key=sorted_key,
                                   anagram_words = Services().possiblepermutations(text=sorted_key),
                                   inputed_words = [user_word],
                                   inputed_words_count = 1,
                                   word_length = len(user_word),
                                   user_id = current_user_id)
                new_anagram.put()

        self.redirect("/")
 def generate(self, input_text, my_user):
     permutations = utilities.a_permutations(input_text)
     anagrams = Anagram.query().fetch()
     sorted_list = []
     result = []
     for i in range(len(anagrams)):
         sorted_list.append(anagrams[i].sorted_word)
     for i in permutations:
         for j in sorted_list:
             if i == j:
                 anagram_id = my_user.key.id() + '/' + j
                 anagram = ndb.Key(Anagram, anagram_id).get()
                 for x in anagram.words:
                     result.append(str(x))
     if input_text in result:
         result.remove(input_text)
     return result
示例#8
0
    def post(self):
        self.response.headers["Content-Type"] = "text/html"
        # checking whether the key is add word
        if self.request.get("newdevice") == "Add Word":
            inputed_word = self.request.get("word").lower()
            # checking whether the inputed word is null or not  and redirecting to the add word paeg
            if Services().get_current_user(
            ) == None or inputed_word == None or inputed_word == "":
                self.redirect("/newdevice")
                return
            current_user_id = Services().get_current_user_id()
            sorted_key = Services().sorted_key(word=inputed_word)
            list_word = Anagram.query()
            list_word = list_word.filter(Anagram.anagram_key == sorted_key,
                                         Anagram.user_id == current_user_id)
            list_word = list_word.fetch()
            valid_permutation = Services().validpermutations(text=sorted_key)
            # checking whether the inputed word has valid permutations or not
            if len(valid_permutation) == 0:
                self.redirect("/newdevice")
                return
# checking whether the there are any word in the list or redirecting to the add word page
            if len(list_word) > 0:
                anagram = list_word[0]
                if inputed_word in anagram.input_words:
                    self.redirect("/newdevice")
                    return

                inputed_words = anagram.input_words
                inputed_words.append(inputed_word)
                anagram.input_words = inputed_words
                anagram.input_words_count = anagram.input_words_count + 1
                anagram.put()

            else:

                new_anagram = Anagram(
                    anagram_key=sorted_key,
                    anagram_words=Services().permutations(text=sorted_key),
                    input_words=[inputed_word],
                    input_words_count=1,
                    word_length=len(inputed_word),
                    user_id=current_user_id)
                new_anagram.put()
        self.redirect("/")
示例#9
0
    def get(self):

        self.response.headers["Content-Type"] = "text/html"

        inputed_word = self.request.GET.get("input_word")

        sorted_key = Services().sorted_key(word=inputed_word)
        list_sorted_keys = []

        anagram_query = Anagram.query(
            Anagram.user_id == Services().get_current_user_id())

        possible_combination_key = Services().possibleAllCountPermutations(
            text=sorted_key)
        anagram_models = []

        for word in possible_combination_key:

            query = anagram_query.filter(Anagram.anagram_key == word).fetch(
                projection=[Anagram.inputed_words])
            if len(query) > 0:

                for anagram in query:
                    anagram_models.extend(anagram.inputed_words)

        dictionary_words = {}
        for word in anagram_models:

            if len(word) in dictionary_words:
                dict_words = dictionary_words[len(word)]
                dict_words.append(word)
                dictionary_words[len(word)] = dict_words
            else:
                dictionary_words[len(word)] = [word]

        template_values = {
            "inputword": inputed_word,
            "dictionary_words": dictionary_words
        }

        template = JINJA_ENVIRONMENT.get_template("subanagram.html")
        self.response.write(template.render(template_values))
示例#10
0
    def get(self):
        # getting the data from the inputed word and storing in the anagram model which has all the words
        self.response.headers["Content-Type"] = "text/html"
        input_word = self.request.GET.get("input_word")
        sorted_key = Services().sorted_key(word=input_word)
        anagram_query = Anagram.query(
            Anagram.user_id == Services().get_current_user_id())
        possible_combination_key = Services().AllPermutations(text=sorted_key)
        anagram_models = []
        # filtering the words which has same key values
        for word in possible_combination_key:
            query = anagram_query.filter(Anagram.anagram_key == word).fetch(
                projection=[Anagram.input_words])
            # checking whether the query has more than one word
            if len(query) > 0:

                for anagram in query:
                    anagram_models.extend(anagram.input_words)
        dictionary_words = {}
        # doing appending operation adn storing in dict word
        for word in anagram_models:
            if len(word) in dictionary_words:
                dict_words = dictionary_words[len(word)]
                dict_words.append(word)
                dictionary_words[len(word)] = dict_words
            else:
                dictionary_words[len(word)] = [word]
# template value store the required feilds of data to access
        template_values = {
            "inputword": input_word,
            "dictionary_words": dictionary_words
        }

        # environment for connect to the info.html page
        template = JINJA_ENVIRONMENT.get_template("info.html")
        self.response.write(template.render(template_values))
示例#11
0
 def number_search(self, number, my_user):
     number = int(number)
     result = Anagram.query(Anagram.length == number,
                            Anagram.user_id == my_user.key.id()).fetch()
     return result