Example #1
0
def resetDB():
    print 'reset db start'
    total = 0
    while True:
        print '===NEW LOOP==='
        query = ParsePy.ParseQuery("DHPhoto").limit(100).skip(total)
        query.order("createdAt", False)
        print "Fetching......."
        objects = query.fetch();
        print "....done"
        count = 0
        for x in objects:
            print x.createdAt()
            try:
                existingPhoto = DHPhoto.objects.get(objectID=x.objectId())
                existingPhoto.params = x.__dict__
                existingPhoto.createdAt = x.createdAt()
                existingPhoto.save()
                print 'updated existing'
            except DHPhoto.DoesNotExist:
                photo = DHPhoto(objectID=x.objectId(), createdAt=x.createdAt(), params=x.__dict__)
                photo.save()
                print 'new created'
            count += 1
            print total + count
        total += count
        print total
        if count == 0:
            break
Example #2
0
def updateDB():
    print "updateDB"
    try:
        latestPhoto = DHPhoto.objects.latest('timestamp')
        # latestPhoto = DHPhoto.objects.order_by('-timestamp')[:1][0]
        total = 0
        while True:
            query = ParsePy.ParseQuery("DHPhoto")
            combined = '{"__type":"Date","iso":"' + latestPhoto.timestamp.strftime('%Y-%m-%dT%H:%M:%S') + '"}'
            query.gte('updatedAt', combined)
            query.order("updatedAt", False)
            query.limit(100).skip(total)
            print "Fetching..."
            objects = query.fetch()
            print "...done"
            count = 0
            for x in objects:
                print "\n===NEW PHOTO====\n"
                print x.__dict__
                try:
                    try:
                       
                        existingPhoto = DHPhoto.objects.get(objectID=x.objectId())
                        existingPhoto.delete()
                        photo = DHPhoto(description=x.DHDataSixWord, level=x.DHDataHappinessLevel, userID=x.PFUser._object_id, location=x.DHDataLocationString, latitude=x.geopoint._latitude, longitude=x.geopoint._longitude, timestamp=x.createdAt(), photoURL=x.photoData.url, objectID=x.objectId(), params=x.__dict__)
                        photo.save()
                        print 'photo updated'
                    except DHPhoto.DoesNotExist:
                        print "before create"
                        photo = DHPhoto(description=x.DHDataSixWord, level=x.DHDataHappinessLevel, userID=x.PFUser._object_id, location=x.DHDataLocationString, latitude=x.geopoint._latitude, longitude=x.geopoint._longitude, timestamp=x.createdAt(), photoURL=x.photoData.url, objectID=x.objectId(), params=x.__dict__)
                        print "before save"
                        print photo
                        photo.save()
                except AttributeError:
                    print "ATT ERROR"
                    pass
                count += 1
                print count
            total += count
            print total
            if count == 0:
                break
            
    except (DHPhoto.DoesNotExist):
        print "does not exist"
        total = 0
        while True:
            print "new loop"
            query = ParsePy.ParseQuery("DHPhoto").limit(100).skip(total)
            query.order("updatedAt", True)
            print "Fetching......."
            objects = query.fetch();
            print "....done"
            count = 0
            for x in objects:
                try:
                    try:
                        existingPhoto = DHPhoto.objects.get(objectID=x.objectId())
                    except DHPhoto.DoesNotExist:
                        photo = DHPhoto(description=x.DHDataSixWord, level=x.DHDataHappinessLevel, userID=x.PFUser._object_id, location=x.DHDataLocationString, latitude=x.geopoint._latitude, longitude=x.geopoint._longitude, timestamp=x.createdAt(), photoURL=x.photoData.url, objectID=x.objectId(), params=x.__dict__)
                        photo.save()
                except AttributeError:
                    pass
                count += 1
                print count
            total += count
            print total
            if count == 0:
                break