Пример #1
0
    def post(self):
        """Post function"""
        user_name = users.get_current_user() and users.get_current_user()\
            .nickname() or 'anonymous'
        sended = Searched(parent=user_key(user_name))

        if users.get_current_user():
            sended.author = users.get_current_user()

        keyword = cgi.escape(self.request.get('keyword'))
        keyword = keyword.split()[0]

        allegro_price = allegro_api(keyword)[0]
        nokaut_price = nokaut_api(
            keyword, 'a8839b1180ea00fa1cf7c6b74ca01bb5')[0]
        allegro_url = allegro_api(keyword)[1]
        nokaut_url = nokaut_api(
            keyword, 'a8839b1180ea00fa1cf7c6b74ca01bb5')[1]
        allegro_image_url = allegro_api(keyword)[2]
        nokaut_image_url = nokaut_api(
            keyword, 'a8839b1180ea00fa1cf7c6b74ca01bb5')[2]

        if allegro_price < nokaut_price:
            url = allegro_url
        else:
            url = nokaut_url

        blob_key_allegro = make_blob_key(allegro_image_url)
        blob_key_nokaut = make_blob_key(nokaut_image_url)
        img_nokaut = images.get_serving_url(blob_key_nokaut)
        img_allegro = images.get_serving_url(blob_key_allegro)
        img_mini_allegro = "".join([img_allegro, "=s100"])
        img_mini_nokaut = "".join([img_nokaut, "=s100"])

        sended.blob_allegro = blob_key_allegro
        sended.blob_nokaut = blob_key_nokaut
        sended.url = url
        sended.content = keyword
        sended.put()

        template_values = {
            "allegro_url": allegro_url,
            "allegro_price": allegro_price,
            "nokaut_url": nokaut_url,
            "nokaut_price": nokaut_price,
            "prod_name": cgi.escape(self.request.get('content')),
            "img_nokaut": img_nokaut,
            "img_allegro": img_allegro,
            "img_mini_allegro": img_mini_allegro,
            "img_mini_nokaut": img_mini_nokaut
        }
        self.render_template(
            'templates/resoult.html', template_values=template_values
        )
Пример #2
0
 def test_nokaut_key_false(self):
     """Check if nokaut_api gives Flase when are bad dates"""
     tests = [
         ('macbook', 'a8839b1180ea0fa1cf7c6b74ca01bb'),
         ('canon450', 'a8839b1180ea00fa1c7c6b74ca01bb'),
         ('toshiba', '8839b1180ea00fa1cf7c6b74ca01bb'),
     ]
     for name, key in tests:
         self.assertFalse(nokaut_api(name, key))
Пример #3
0
 def test_nokaut_key_true(self):
     """Test if nokaut_api is giving good resoults"""
     tests = [
         ('macbook', 'a8839b1180ea00fa1cf7c6b74ca01bb5'),
         ('canon450', 'a8839b1180ea00fa1cf7c6b74ca01bb5'),
         ('wiedzmin', 'a8839b1180ea00fa1cf7c6b74ca01bb5'),
     ]
     for name, key in tests:
         resoult = nokaut_api(name, key)
         self.assertTrue(bool(resoult))