Last active
December 20, 2015 15:28
-
-
Save kgn/6153852 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, os | |
sys.path.insert(0, os.path.join(os.path.dirname( __file__ ), 'ParsePy')) | |
from parse_rest.user import User as PFUser | |
from parse_rest.datatypes import Object as PFObject | |
from parse_rest.installation import Installation as PFInstallation | |
from parse_rest.connection import register as PFRegister | |
from parse_rest.connection import ParseBatcher as PFBatcher | |
PFRegister(PARSE_APPLICATION_ID, PARSE_REST_API_KEY, master_key=PARSE_MASTER_KEY) | |
class Guess(PFObject): pass | |
class Photo(PFObject): pass | |
class Activity(PFObject): pass | |
KWGuessResultIncorrect = 0 | |
KWGuessResultCorrect = 1 | |
KWGuessResultUnlocked = 2 | |
KWActivityTypePostPhoto = 0 | |
KWActivityTypeCorrect = 1 | |
KWActivityTypeUnlocked = 2 | |
activities = [] | |
cachedUsers = {} | |
cachedPhotos = {} | |
batcher = PFBatcher() | |
photos = Photo.Query.all().filter(dev__activity__ne=True).limit(10) | |
for photo in photos: | |
userId = photo.user.objectId | |
if userId not in cachedUsers: | |
cachedUsers[userId] = PFUser.Query.get(objectId=userId) | |
cachedPhotos[photo.objectId] = photo | |
user = cachedUsers[userId] | |
activities.append(Activity( | |
type=KWActivityTypePostPhoto, photo=photo, | |
activityAt=photo.createdAt, user=user | |
)) | |
photo.dev__activity = True | |
correctOrUnlockedGuesses = Guess.Query.all().filter(result__ne=KWGuessResultIncorrect, dev__activity__ne=True).limit(10) | |
for guess in correctOrUnlockedGuesses: | |
userId = guess.user.objectId | |
photoId = guess.photo.objectId | |
if userId not in cachedUsers: | |
cachedUsers[userId] = PFUser.Query.get(objectId=userId) | |
if photoId not in cachedPhotos: | |
cachedPhotos[photoId] = Photo.Query.get(objectId=photoId) | |
user = cachedUsers[userId] | |
photo = cachedPhotos[photoId] | |
activities.append(Activity( | |
type=guess.result, photo=photo, guess=guess, | |
activityAt=guess.createdAt, user=user | |
)) | |
guess.dev__activity = True | |
batcher.batch_save(activities) | |
batcher.batch_save(photo) | |
batcher.batch_save(guess) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment