def post(self): name = self.request.get('name') email = self.request.get('email') #Empty Name if len(name) == 0: self.response.write(json.dumps({'status_code': 100, 'key': "0"})) return #name exists (non-case sensitive) if Stream.name_exist(name): self.response.write(json.dumps({'status_code': 101, 'key': "0"})) return author = self.request.get('author') tags = self.request.get('tags').split() cover = self.request.get('cover_url') woType = self.request.get('woType') #dsm TODO: get_all or get stream = Stream(name=name, author=author, tags=tags, email=email, cover=cover, views=0, photos=[], woType=woType) key = stream.put() self.response.write(json.dumps({'status_code': 0, 'key': key.id()}))
def post(self): #stream_id, st, ed stream_id = [ int(p) for p in self.request.get('stream_id', allow_multiple=True) ] Stream.delete_streams(stream_id) time.sleep(0.1) self.redirect('/manage')
def get(self): session_id = self.request.get('session_id') session = Session.query_by_id(int(session_id)) stream = Stream.query_by_name(session.exercises[session.currWO]) #use stream[0] for first element in list if session.step >= stream[0].totalSteps: lastStep = True step_ = stream[0].totalSteps else: lastStep = False step_ = session.step if session.currWO >= (session.totalWOs - 1): # subtract 1 because exerciseList starts at element 0 lastWO = True print "This is the last workout. currWO = %d, totalWOs = %d" % (session.currWO, session.totalWOs) else: lastWO = False print "This is NOT the last workout. currWO = %d, totalWOs = %d" % (session.currWO, session.totalWOs) myDict = {"session_id": session_id, "photo": stream[0].woPics[unicode(step_)], #get the first pic "instructions": stream[0].woInstructions[unicode(step_)], "name": stream[0].name, "lastStep": lastStep, "lastWO": lastWO} self.response.write(json.dumps(myDict))
def get(self): session_id = self.request.get('session_id') session = Session.query_by_id(int(session_id)) stream = Stream.query_by_name(session.exercises[session.currWO]) #use stream[0] for first element in list if session.step >= stream[0].totalSteps: lastStep = True step_ = stream[0].totalSteps else: lastStep = False step_ = session.step if session.currWO >= ( session.totalWOs - 1): # subtract 1 because exerciseList starts at element 0 lastWO = True print "This is the last workout. currWO = %d, totalWOs = %d" % ( session.currWO, session.totalWOs) else: lastWO = False print "This is NOT the last workout. currWO = %d, totalWOs = %d" % ( session.currWO, session.totalWOs) myDict = { "session_id": session_id, "photo": stream[0].woPics[unicode(step_)], #get the first pic "instructions": stream[0].woInstructions[unicode(step_)], "name": stream[0].name, "lastStep": lastStep, "lastWO": lastWO } self.response.write(json.dumps(myDict))
def get(self): #stream_id, start_time, end_time stream_id = int(self.request.get('stream_id')) start_time = self.request.get('start_time') end_time = self.request.get('end_time') stream = Stream.query_by_id(int(stream_id)) stream.views = stream.views + 1 stream.put() images = [] LatLngBounds = { 'minLat': -85, 'maxLat': 85, 'minLng': -180, 'maxLng': 180, } start_time = datetime.datetime.strptime(start_time, "%b %d %Y") end_time = datetime.datetime.strptime(end_time, "%b %d %Y") + datetime.timedelta(days=1, hours=12) print start_time, end_time for photo_id in stream.photos: photo = Photo.get_by_id(photo_id) if photo.updated_time >= start_time and photo.updated_time <= end_time: images.append({ 'image': photo_id, 'updated_time': photo.updated_time.isoformat(), 'lat': randint(LatLngBounds['minLat'], LatLngBounds['maxLat']), 'lng': randint(LatLngBounds['minLng'], LatLngBounds['maxLat']), }) self.response.write(json.dumps({ 'images': images, 'status': 0, }))
def get(self): PushList = [] PullList = [] parameter = self.request.get('category') if int(parameter) == 0: category = 'Upper Body Push/Lower Body Pull' PushQuery = Stream.query(Stream.woType == '0') #upper push PullQuery = Stream.query(Stream.woType == '3') #lower pull else: category = 'Upper Body Pull/Lower Body Push' PullQuery = Stream.query(Stream.woType == '1') #upper pull PushQuery = Stream.query(Stream.woType == '2') # lower push for x in PushQuery: PushList.append(x.name) for x in PullQuery: PullList.append(x.name) exerciseList = [] exerciseList.append(random.choice(PushList)) exerciseList.append(random.choice(PullList)) reps = random.choice(['5 sets of 5', '4 sets of 10', '4 sets of 15']) totalWOs = len(exerciseList) session = Session(category=category, exercises=exerciseList, reps=reps, currWO=0, step=1, active=False, totalWOs=totalWOs, completed=False) key = session.put() session_id = key.id() workouts = { 'reps': reps, 'exercises': exerciseList, 'category': category, 'totalWOs': totalWOs, 'session_id': session_id } print json.dumps(workouts) self.response.write(json.dumps(workouts))
def get(self): user = users.get_current_user() if user is None: self.redirect('/') return BASE = GetPath(self.request.url, self.request.path) re = requests.get(BASE + "/api/management", params={"user_id": user.user_id()}, timeout=10) own_stream = [] sub_stream = [] if re: res = re.json() for r in res['own_stream']: s = Stream.query_by_id(int(r)) own_stream.append({ "id": r, "name": s.name, "size": len(s.photos), "updated_time": s.updated_time, "views": s.views }) for r in res['sub_stream']: s = Stream.query_by_id(int(r)) sub_stream.append({ "id": r, "name": s.name, "size": len(s.photos), "updated_time": s.updated_time, "views": s.views }) url = users.create_logout_url(self.request.uri) url_linktext = 'Logout' template_values = { 'login_logout_url': url, 'url_linktext': url_linktext, 'own_stream': own_stream, 'sub_stream': sub_stream, 'user_id': user.user_id(), } template = JINJA_ENVIRONMENT.get_template('manage.html') self.response.write(template.render(template_values))
def get(self): user_id = self.request.get('user_id') own_stream = Stream.query_by_author(user_id) own_stream_ids = [obj.key.id() for obj in own_stream.iter()] sub_stream = Subscribe.query_by_user(user_id) sub_stream_ids = [obj.stream for obj in sub_stream.iter()] r = {'own_stream': own_stream_ids, 'sub_stream': sub_stream_ids} self.response.write(json.dumps(r))
def get(self): user = users.get_current_user() if user is None: self.redirect('/') return BASE = GetPath(self.request.url, self.request.path) re = requests.get(BASE+"/api/management", params={"user_id":user.user_id()}, timeout=10) own_stream = [] sub_stream = [] if re: res = re.json() for r in res['own_stream']: s = Stream.query_by_id(int(r)) own_stream.append({ "id": r, "name": s.name, "size": len(s.photos), "updated_time": s.updated_time, "views": s.views }) for r in res['sub_stream']: s = Stream.query_by_id(int(r)) sub_stream.append({ "id": r, "name": s.name, "size": len(s.photos), "updated_time": s.updated_time, "views": s.views }) url = users.create_logout_url(self.request.uri) url_linktext = 'Logout' template_values = { 'login_logout_url' : url, 'url_linktext': url_linktext, 'own_stream': own_stream, 'sub_stream': sub_stream, 'user_id': user.user_id(), } template = JINJA_ENVIRONMENT.get_template('manage.html') self.response.write(template.render(template_values))
def get(self): user_id = self.request.get('user_id') streams = Stream.query() sub_stream = Subscribe.query_by_user(user_id) sub_stream_ids = [obj.stream for obj in sub_stream.iter()] #list of stream IDs #iterate through streams and get last image recentImages = [] streamName = [] streamIDs = [] for stream_id in sub_stream_ids: stream = Stream.query_by_id(int(stream_id)) if len(stream.photos) != 0: recentImages.append(stream.photos[-1]) streamName.append(stream.name) streamIDs.append(stream_id) self.response.write(json.dumps({"recentImages": recentImages, "streamName": streamName, "id": streamIDs}))
def get(self): PhotoDistances = [] streams = Stream.query() for stream in streams: for photo in stream.photos: p = Photo.query_by_id(photo) PhotoDistances.append({"lat":p.Latitude, "lng": p.Longitude, "stream_id":p.stream_id, "photo_id": photo, "stream_name": stream.name}) self.response.write(json.dumps({"Distances": PhotoDistances}))
def post(self): img = self.request.get('image') stream_id = self.request.get('stream_id') comment = self.request.get('comment') photo = Photo(image=img, stream_id=stream_id, comment=comment) key = photo.put() print img, stream_id, comment stream = Stream.query_by_id(int(stream_id)) if len(stream.cover) == 0: stream.cover = str(key.id()) stream.photos.append(key.id()) stream.put()
def update_stream(self, image_): stream_id = self.request.get('stream_id') comment = self.request.get('comment') lat = self.request.get('Latitude') lng = self.request.get('Longitude') description = self.request.get('description') step = self.request.get('step') woInstructions = {} woPics = {} if (lat == '') or (lng == ''): lat = 0.0 lng = 0.0 photo = Photo(image=image_, stream_id=stream_id, comment=comment, Latitude=lat, Longitude=lng) key = photo.put() stream = Stream.query_by_id(int(stream_id)) if (stream.woPics == None): print "no pics in steps" woPics[step] = key.id() else: print "pics present" woPics = stream.woPics if type(woPics) is not dict: woPics = ast.literal_eval(woPics) woPics[step] = key.id() print woPics if (stream.woInstructions == None): print "no inst in steps" woInstructions[step] = description else: print "inst present" woInstructions = stream.woInstructions if type(woInstructions) is not dict: woInstructions = ast.literal_eval(woInstructions) woInstructions[step] = description if len(stream.cover) == 0: stream.cover = str(key.id()) stream.photos.append(key.id()) stream.woPics = woPics stream.woInstructions = woInstructions print "number of keys is %d" % len(woPics.keys()) stream.totalSteps = len(woPics.keys()) stream.put()
def get(self): PushList = [] PullList = [] parameter = self.request.get('category') if int(parameter) == 0: category = 'Upper Body Push/Lower Body Pull' PushQuery = Stream.query(Stream.woType == '0') #upper push PullQuery = Stream.query(Stream.woType == '3') #lower pull else: category = 'Upper Body Pull/Lower Body Push' PullQuery = Stream.query(Stream.woType == '1') #upper pull PushQuery = Stream.query(Stream.woType == '2') # lower push for x in PushQuery: PushList.append(x.name) for x in PullQuery: PullList.append(x.name) exerciseList = [] exerciseList.append(random.choice(PushList)) exerciseList.append(random.choice(PullList)) reps = random.choice(['5 sets of 5','4 sets of 10','4 sets of 15']) totalWOs = len(exerciseList) session = Session(category=category, exercises=exerciseList,reps=reps,currWO=0, step=1,active=False,totalWOs=totalWOs,completed=False) key = session.put() session_id=key.id() workouts = {'reps': reps, 'exercises': exerciseList, 'category': category, 'totalWOs': totalWOs, 'session_id': session_id } print json.dumps(workouts) self.response.write(json.dumps(workouts))
def update_stream(self, image_): stream_id = self.request.get('stream_id') comment = self.request.get('comment') lat = self.request.get('Latitude') lng = self.request.get('Longitude') description = self.request.get('description') step = self.request.get('step') woInstructions = {} woPics = {} if (lat == '') or (lng == ''): lat = 0.0 lng = 0.0 photo = Photo(image=image_, stream_id=stream_id, comment=comment, Latitude=lat, Longitude=lng) key = photo.put() stream = Stream.query_by_id(int(stream_id)) if(stream.woPics == None): print "no pics in steps" woPics[step]=key.id() else: print "pics present" woPics= stream.woPics if type(woPics) is not dict: woPics = ast.literal_eval(woPics) woPics[step]=key.id() print woPics if(stream.woInstructions == None): print "no inst in steps" woInstructions[step] = description else: print "inst present" woInstructions=stream.woInstructions if type(woInstructions) is not dict: woInstructions=ast.literal_eval(woInstructions) woInstructions[step] = description if len(stream.cover) == 0: stream.cover = str(key.id()) stream.photos.append(key.id()) stream.woPics = woPics stream.woInstructions = woInstructions print "number of keys is %d" % len(woPics.keys()) stream.totalSteps = len(woPics.keys()) stream.put()
def get(self): user_id = self.request.get('user_id') streams = Stream.query() sub_stream = Subscribe.query_by_user(user_id) sub_stream_ids = [obj.stream for obj in sub_stream.iter()] #list of stream IDs #iterate through streams and get last image recentImages = [] streamName = [] streamIDs = [] for stream_id in sub_stream_ids: stream = Stream.query_by_id(int(stream_id)) if len(stream.photos) != 0: recentImages.append(stream.photos[-1]) streamName.append(stream.name) streamIDs.append(stream_id) self.response.write( json.dumps({ "recentImages": recentImages, "streamName": streamName, "id": streamIDs }))
def get(self): #stream_id, st, ed stream_id = int(self.request.get('stream_id')) if self.request.get('st'): st = int(self.request.get('st')) else: st = 1 stream = Stream.query_by_id(int(stream_id)) stream.views = stream.views + 1 stream.put() length = len(stream.photos) st = min(max(st, 1), length) ed = min(st + 3, length + 1) images = stream.photos[-st:-ed:-1] woPics = stream.woPics woInstructions = stream.woInstructions if self.request.get('all'): images = stream.photos[:] if ed == length + 1: ed = -1 LatLngBounds = { 'minLat': -85, 'maxLat': 85, 'minLng': -180, 'maxLng': 180, } locations = [{ 'lat': randint(LatLngBounds['minLat'], LatLngBounds['maxLat']), 'lng': randint(LatLngBounds['minLng'], LatLngBounds['maxLat']), } for i in range(len(images))] self.response.write( json.dumps({ 'images': images, 'locations': locations, 'st': st, 'ed': ed, 'size': length, 'woPics': woPics, 'woInstructions': woInstructions, }))
def get(self): term = self.request.get('term') streams = Stream.query() all_strings = [] for stream in streams: name = stream.name.lower(); user = stream.email.lower(); if (term.lower() in name): all_strings.append(stream.name) if(term.lower() in user and user not in all_strings): all_strings.append(stream.email) for tag in stream.tags: if (term.lower() in tag.lower()) and (tag.lower() not in all_strings): all_strings.append(tag) all_strings.sort() self.response.write(json.dumps(all_strings))
def get(self): term = self.request.get('term') streams = Stream.query() all_strings = [] for stream in streams: name = stream.name.lower() user = stream.email.lower() if (term.lower() in name): all_strings.append(stream.name) if (term.lower() in user and user not in all_strings): all_strings.append(stream.email) for tag in stream.tags: if (term.lower() in tag.lower()) and (tag.lower() not in all_strings): all_strings.append(tag) all_strings.sort() self.response.write(json.dumps(all_strings))
def get(self): #stream_id, st, ed stream_id = int(self.request.get('stream_id')) if self.request.get('st'): st = int(self.request.get('st')) else: st = 1 stream = Stream.query_by_id(int(stream_id)) stream.views = stream.views + 1 stream.put() length = len(stream.photos) st = min(max(st, 1), length) ed = min(st + 3, length + 1) images = stream.photos[-st:-ed:-1] woPics=stream.woPics woInstructions=stream.woInstructions if self.request.get('all'): images = stream.photos[:] if ed == length + 1: ed = -1 LatLngBounds = { 'minLat': -85, 'maxLat': 85, 'minLng': -180, 'maxLng': 180, } locations = [{ 'lat': randint(LatLngBounds['minLat'], LatLngBounds['maxLat']), 'lng': randint(LatLngBounds['minLng'], LatLngBounds['maxLat']), } for i in range(len(images))] self.response.write(json.dumps({ 'images': images, 'locations': locations, 'st': st, 'ed': ed, 'size': length, 'woPics': woPics, 'woInstructions': woInstructions, }))
def post(self): #stream_id, st, ed stream_id = [int(p) for p in self.request.get('stream_id', allow_multiple=True)] Stream.delete_streams(stream_id) time.sleep(0.1) self.redirect('/manage')
def get(self): user = users.get_current_user() if user is None: self.redirect('/') return url = users.create_logout_url(self.request.uri) url_linktext = 'Logout' #if stream_id is None stream_id = self.request.get('stream_id') BASE = GetPath(self.request.url, self.request.path) if stream_id: st = self.request.get('st') if len(st) == 0: st = 1 data = {"stream_id": stream_id, "st": st} print data re = requests.get(BASE + "/api/view", params=data) allphotos = [] woPicsList = [] woInstList = [] st = 1 multipage = True if re: allphotos = re.json()['images'] #get three photo each time. st = re.json()['ed'] woPics = re.json()['woPics'] woInstructions = re.json()['woInstructions'] if woInstructions is not None: sortedList = sorted(woInstructions.keys()) for x in sortedList: #print "santamaria" woPicsList.append(woPics[x]) woInstList.append(woInstructions[x]) if re.json()['size'] < 4: multipage = False #if user doesn't own the stream, he should not upload photo user_id = user.user_id() disableModify = True if str(Stream.query_by_id(int(stream_id)).author) == str(user_id): disableModify = False #subscribe subscribed = Subscribe.subscribed(stream_id, user_id) template_values = { 'login_logout_url': url, 'url_linktext': url_linktext, 'allphotos': allphotos, 'disableModify': disableModify, 'stream_id': stream_id, 'user_id': user.user_id(), 'subscribed': subscribed, 'st': st, 'multipage': multipage, 'woPics': woPicsList, 'woInstructions': woInstList, } template = JINJA_ENVIRONMENT.get_template('viewstream.html') self.response.write(template.render(template_values)) else: re = requests.get(BASE + "/api/allstreams") allstreams = [] if re: allstreams = re.json()["allstreams"] template_values = { "allstreams": allstreams, "img_1": 'http://ohtoptens.com/wp-content/uploads/2015/06/Flower-Images-and-Wallpapers3.jpg', 'login_logout_url': url, 'url_linktext': url_linktext } template = JINJA_ENVIRONMENT.get_template('view.html') self.response.write(template.render(template_values))
def get(self): #stream_id, st, ed stream = Stream.query().order(-Stream.views) r = [{'name': p.name, 'cover': p.cover, 'view': p.views} for p in stream] self.response.write(json.dumps(r))
def get(self): user = users.get_current_user() if user is None: self.redirect('/') return url = users.create_logout_url(self.request.uri) url_linktext = 'Logout' #if stream_id is None stream_id = self.request.get('stream_id') BASE = GetPath(self.request.url, self.request.path) if stream_id: st = self.request.get('st') if len(st)==0: st = 1 data = {"stream_id": stream_id, "st":st} print data re = requests.get(BASE+"/api/view", params=data) allphotos = [] woPicsList = [] woInstList = [] st = 1 multipage = True if re: allphotos = re.json()['images'] #get three photo each time. st = re.json()['ed'] woPics=re.json()['woPics'] woInstructions=re.json()['woInstructions'] if woInstructions is not None: sortedList= sorted(woInstructions.keys()) for x in sortedList: #print "santamaria" woPicsList.append(woPics[x]) woInstList.append(woInstructions[x]) if re.json()['size'] < 4: multipage = False #if user doesn't own the stream, he should not upload photo user_id = user.user_id() disableModify = True if str(Stream.query_by_id(int(stream_id)).author) == str(user_id): disableModify = False #subscribe subscribed = Subscribe.subscribed(stream_id, user_id) template_values = { 'login_logout_url' : url, 'url_linktext': url_linktext, 'allphotos':allphotos, 'disableModify': disableModify, 'stream_id': stream_id, 'user_id': user.user_id(), 'subscribed': subscribed, 'st': st, 'multipage': multipage, 'woPics': woPicsList, 'woInstructions': woInstList, } template = JINJA_ENVIRONMENT.get_template('viewstream.html') self.response.write(template.render(template_values)) else: re = requests.get(BASE+"/api/allstreams") allstreams = [] if re: allstreams = re.json()["allstreams"] template_values = {"allstreams" : allstreams, "img_1": 'http://ohtoptens.com/wp-content/uploads/2015/06/Flower-Images-and-Wallpapers3.jpg', 'login_logout_url' : url, 'url_linktext': url_linktext } template = JINJA_ENVIRONMENT.get_template('view.html') self.response.write(template.render(template_values))
def get(self): query = self.request.get('query') stream = Stream.query_by_name(query) r = [{'name': p.name, 'cover': p.cover, 'stream_id': p.key.id()} for p in stream] self.response.write(json.dumps({"r":r}))
def get(self): streams = Stream.query() all_streams = [] for s in streams: all_streams.append({'name':s.name, 'cover':s.cover, 'id':s.key.id(), 'views':s.views}) self.response.write(json.dumps({"allstreams": all_streams}))