def get(self): self.response.headers['Content-Type'] = 'text/plain' startStep = int(self.request.get('start')) stopStep = int(self.request.get('stop')) #stepDate keys have form: "sD" + step stepDates = db.GqlQuery("Select * From stepDate Where step >= :1 AND step <= :2",startStep,stopStep).fetch(1000) total = 0 meList = [] counter = 0 for meStep in stepDates: if meStep.key().name() == "sD" + str(meStep.step): newStep = meSchema.stepDate(key_name = str(meStep.step), step = meStep.step, date = meStep.date) meList.append(newStep) counter += 1 if counter == 100: db.put(meList) meList = [] total += counter counter = 0 if counter > 0: db.put(meList) total += counter self.response.out.write('Done putting %s new key_names for stepDate!' % total)
def putEm(step): positions = getPositions("*****@*****.**") meDatetime = datetime.now() entityDict = {} symbols = ["GOOG", "HBC", "INTC", "CME"] stckIDs = meTools.getStckIDs(symbols) for pos in positions: symbol = pos.ticker_id.split(":")[1] quote = float(str(pos.position_data.market_value).replace(" USD", "")) if symbol in symbols: stckID = stckIDs[symbol] meStck = meSchema.stck(key_name=str(stckID) + "_" + str(step), ID=stckID, step=step, quote=quote) entityDict[meStck.key().name()] = meStck meStepDate = meSchema.stepDate(key_name=str(step), step=step, date=meDatetime) entityDict[meStepDate.key().name()] = meStepDate wait = 0.1 while True: try: meTools.memPut_multi(entityDict) break except db.Timeout: from time import sleep sleep(timeout) wait *= 2
def get(self): self.response.headers['Content-Type'] = 'text/plain' step = 0 dayZeroStart = dt.datetime(2009,11,18) dayZeroStart += dt.timedelta(hours=14.5) for day in range(73): meList = [] # Must re-initialize at beginning of each day count. dtime = dayZeroStart + dt.timedelta(days=day) if dt.date.weekday(dtime) not in [5,6]: for i in range(1,79): step += 1 stepdate = dtime + dt.timedelta(minutes=i*5) meEntity = meSchema.stepDate(step = step, date = stepdate) meList.append(meEntity) result = db.GqlQuery("Select * from stepDate Where step > :1 AND step < :2",step-77,step).fetch(100) if len(result) == 0: db.put(meList) self.response.out.write('Populated datetimes for Steps %s - %s for date %s\n' % (step - 77, step, stepdate)) else: self.response.out.write('Already full! for Steps %s - %s for date %s\n' % (step - 77, step, stepdate)) self.response.out.write('Done!')