Skip to content

Instantly share code, notes, and snippets.

View jdunne-kaplan's full-sized avatar

Jim Dunne jdunne-kaplan

  • Kaplan
  • Chicago, IL
View GitHub Profile
@jdunne-kaplan
jdunne-kaplan / update-deck-url.py
Created March 25, 2015 20:07
Update SlideDeck deck_url
import models
import json
from lib.utils import DateTimeJSONEncoder
deck_id = "558a3de6-9019-4ee8-9c18-1cad41346d50"
new_deck_url = "https://s3.amazonaws.com/slides.kaplan.com/PACE/8980c532-2e99-414f-acb3-5c99702f418e/data"
deckA = models.SlideDeck.get_by_id(deck_id)
deckA.deck_url = new_deck_url
@jdunne-kaplan
jdunne-kaplan / add-deck-asset.py
Created March 18, 2015 16:56
Add deck_id to slidedecks asset
import json
import models
from google.appengine.ext import ndb
opaqueID = '9f3cccbe-ee94-4bd6-9ba6-96efb1967ae4'
deck_asset = models.DBAsset.all().filter('opaqueID = ', opaqueID).filter('assetType = ', 'slidedecks').get()
asset = json.loads(deck_asset.asset)
# Add new deck_id:
@jdunne-kaplan
jdunne-kaplan / clean-deck-asset.py
Created March 18, 2015 16:55
Clean slidedecks asset by removing invalid deck_ids
import json
import models
from google.appengine.ext import ndb
opaqueID = '9f3cccbe-ee94-4bd6-9ba6-96efb1967ae4'
deck_asset = models.DBAsset.all().filter('opaqueID = ', opaqueID).filter('assetType = ', 'slidedecks').get()
asset = json.loads(deck_asset.asset)
keys = [ndb.Key(models.SlideDeck, id) for id in asset["deck_ids"]]
@jdunne-kaplan
jdunne-kaplan / swap-deckids-tles.py
Created March 18, 2015 16:43
Swap deck_ids in TLEs
import models
from google.appengine.ext import ndb
import lib
from lib.utils import AsyncBatchUpdateManager
from lib.utils import QueryBatchIterator
session = models.DBSession.get_by_key_name('9f3cccbe-ee94-4bd6-9ba6-96efb1967ae4')
tle_query = models.TimelineEvent.query_ordered_versioned(session, timeline_version=2)\
@jdunne-kaplan
jdunne-kaplan / add-participant.py
Created March 18, 2015 16:32
Add participant to session
import models
from google.appengine.ext import ndb
import lib
lib.session.create_participant(
opaqueID='TODO',
firstName='KAPx',
lastName='Developer',
username='kapxdev',
emailAddress='[email protected]',
@jdunne-kaplan
jdunne-kaplan / find-deck-urls.py
Created March 18, 2015 16:24
Find deck urls by deck ids
import models
from google.appengine.ext import ndb
ids = ['TODO']
keys = [ndb.Key(models.SlideDeck, id) for id in ids]
decks = ndb.get_multi(keys)
for deck in decks:
if deck is None: continue
print deck.deck_id, deck.deck_url
@jdunne-kaplan
jdunne-kaplan / swap_decks.py
Created March 12, 2015 18:28
Update deck_url of deckA with deckB's
import models
import json
from lib.utils import DateTimeJSONEncoder
# Original deck in use, in production:
deckA = models.SlideDeck.get_by_id("2cd8f7cf-ca9c-4799-a424-ab9cbe454695")
# Reconverted deck, unused:
deckB = models.SlideDeck.get_by_id("d72a7645-256c-4d05-9574-22b88d6b9785")
#print json.dumps(deckA.to_dict(), indent=2, cls=DateTimeJSONEncoder)
@jdunne-kaplan
jdunne-kaplan / reindex-tles.py
Created March 12, 2015 14:22
Rebuild TLE index for session
import models
from lib.utils import AsyncBatchUpdateManager
from lib.utils import QueryBatchIterator
session = models.DBSession.get_by_key_name("4c80b95e-5554-4dfb-8807-839d7851ab36")
print session.is_versioned
print ""
tles = models.TimelineEvent.query_unversioned(session)
@jdunne-kaplan
jdunne-kaplan / site-secure-add-exception.py
Created February 6, 2015 16:51
kapx-site-secure add non-edu employee to exception table
from google.appengine.ext import ndb
from models import models
key = ndb.Key(models.KnownKaplanEmployee, "[email protected]")
models.KnownKaplanEmployee(key=key).put()
@jdunne-kaplan
jdunne-kaplan / associate-slidedeck.py
Created February 2, 2015 20:01
Associate slide deck to session
import lib.session
opaque_id = "620-test-1"
a = lib.session.get_asset(opaque_id, "slidedecks")
print a.asset
# lib.session.save_asset(opaque_id, "slidedecks", {"deck_ids":["e7eb7111-30f7-4468-a334-4b87a7ac012a"]})
a = lib.session.get_asset(opaque_id, "slidedecks")