示例#1
0
    def runLyricsmash(self, artist0, artist1, str_):
        if str_ is None or str_ == "":
            template_values = {"http_get": True, "error": "No text entered. Try again."}
            return template_values

        try:
            brain = Brain()
            artist_words0 = ArtistWords.get_by_key_name(artist0)
            if artist_words0:
                brain.remember(artist_words0.words.split())
            if artist0 != artist1:
                artist_words1 = ArtistWords.get_by_key_name(artist1)
                if artist_words1:
                    brain2 = Brain()
                    brain2.remember(artist_words1.words.split())
                    brain.import_from(brain2.memory)
            result = self.format_result(brain.speak_about(str_, 640))

            template_values = {
                "http_get": False,
                "a0": artist0,
                "a1": artist1,
                "str": str_,
                "result": result,
                "ws_url_query": urllib.urlencode(dict([["q", re.sub("<br />", " ", result)]])),
                "artists": ArtistWords.all(keys_only=True).fetch(3100),
            }
        except DeadlineExceededError:
            template_values = {"http_get": True, "error": "The request has timed out, please try another."}

        return template_values
示例#2
0
 def loaddb(self):
   # load every artist file
   for subdir, dirs, files in os.walk(os.path.join(os.path.dirname(__file__), "../data/")):
     for f in files:
       if ArtistWords.get_by_key_name(f):
         self.response.out.write('Skipping ')
         continue
       try:
         path = os.path.join(
           os.path.dirname(__file__), "../data/" + f
         )
         df = open(path, 'r')
       except IOError:
         continue
       else:
         aname = unicode(df.readline().rstrip(), 'utf-8')
         lyr = ArtistWords(key_name=aname, name=aname, words=unicode(df.read(), 'utf-8'))
         lyr.put()
         df.close()
示例#3
0
    def get(self):
        template_values = {"http_get": True, "artists": ArtistWords.all(keys_only=True).fetch(3100)}

        path = os.path.join(os.path.dirname(__file__), "..", "templates", "lyricsmash.html")
        self.response.out.write(template.render(path, template_values))