Пример #1
0
    def test_CuriosityImage_DataStoreGet(self):
        #Insert a basic CuriosityImage
        ci = CuriosityImage(key_name=str(42))
        ci.imageid = 42
        ci.description = u'previously “N165”'
        ci.put()

        dbCI = CuriosityImage.get_by_key_name(str(42))

        self.assertIsNotNone(dbCI)
        self.assertEquals(ci.description, dbCI.description)
Пример #2
0
    def test_CuriosityImageExists_ExistingImageID_ReturnsTrue(self):
        #Insert a basic CuriosityImage
        ci = CuriosityImage(key_name=str(42))
        ci.imageid = 42
        ci.description = 'DESC123'
        ci.put()

        exists = getfeeds.CuriosityImageExists(42)

        self.assertTrue(exists)
Пример #3
0
    def test_SaveCuriosityImage_InsertIfNotExists(self):

        self.assertIsNone(CuriosityImage.get_by_key_name(str(42)))

        newCi = CuriosityImage(key_name=str(42))
        newCi.imageid = 42
        newCi.description = 'DESC123'

        #Save to DB
        getfeeds.SaveCuriosityImage(newCi)

        self.assertIsNotNone(CuriosityImage.get_by_key_name(str(42)))
Пример #4
0
    def ParseAllPagesAndFollowNextLink(self, imageIndexPageUrl):

        if imageIndexPageUrl is None or len(imageIndexPageUrl) == 0:
            return

        self.log("Processing %s" % imageIndexPageUrl)

        imageIndexPageHTML = self.GetUrlContents(imageIndexPageUrl)

        if not imageIndexPageHTML:
            self.log("imageIndexPageHTML is empty for " + imageIndexPageUrl)
            return

        imageIds = GetImageIDs(imageIndexPageHTML)

        for i,j in imageIds:
            if CuriosityImageExists(i):
                self.log("Image ID %s already exists in the datastore." % i)
                if not self.firstRun:
                    self.log("Stopping processing.")
                    return
                else:
                    continue

            imagePageHtml = self.GetUrlContents(GetImagePageUrl(i))
            if not imagePageHtml:
                self.log("imagePageHtml is empty for " + str(i))
                break
            ci = CuriosityImage(key_name=str(i))
            ci.imageid = i
            ci.title = GetImageTitle(imagePageHtml)
            ci.description = GetImageDescription(imagePageHtml)
            ci.date = GetImageDate(imagePageHtml)
            ci.imageurl = GetMediumImageUrl(imagePageHtml)
            SaveCuriosityImage(ci)

        self.log("Sleeping for 5 seconds")
        sleep(5)

        #App engine doesn't like long running pages,
        #so we redirect to same page with different querystring
        self.ProcessNextPage(imageIndexPageHTML)
Пример #5
0
def CuriosityImageExists(imageId):
    return CuriosityImage.get_by_key_name(str(imageId)) is not None
Пример #6
0
def SaveCuriosityImage(curiosityImage):
    dbCI = CuriosityImage.get_by_key_name(curiosityImage.key().name())

    if dbCI is None:
        memcache.flush_all()
        curiosityImage.put()
Пример #7
0
 def GetImagesFromDataStore(self, numberOfImages):
     q = CuriosityImage.all()
     q.order('-date')
     return q.fetch(limit=numberOfImages)
Пример #8
0
    def test_SaveCuriosityImage_DoNotUpdateExistingCuriosityImage(self):
        #Insert a basic CuriosityImage
        ci = CuriosityImage(key_name=str(42))
        ci.imageid = 42
        ci.description = 'DESC123'
        ci.put()

        newCi = CuriosityImage(key_name=str(42))
        newCi.imageid = 42
        newCi.description = 'NEWDESC123'

        #Save to DB
        getfeeds.SaveCuriosityImage(newCi)

        #Get back from DB
        dbCI = CuriosityImage.get_by_key_name(str(42))

        self.assertEquals(u'DESC123', dbCI.description)
        self.assertNotEquals(u'NEWDESC123', ci.description)
Пример #9
0
 def GetImagesFromDataStore(self, numberOfImages):
     q = CuriosityImage.all()
     q.order('-date')
     return q.fetch(limit=numberOfImages)