def get(self): user = users.get_current_user() tags = '' if user: url = users.create_logout_url(self.request.uri) url_linktext = 'Logout' streams = CreateStream.Stream.query().fetch(50) for stream in streams: tags = tags + str(stream.name) + ' ' for tag in stream.tags: tags = tags + str(tag) + ' ' else: url = users.create_login_url(self.request.uri) url_linktext = 'Login' while len(Connexus.count_queue) > 0: datetime_in_queue = Connexus.count_queue.pop() if (datetime.datetime.now() - datetime_in_queue[1]) >= datetime.timedelta(hours=1): stream = Stream.query(Stream.name == datetime_in_queue[0]).fetch(1)[0] stream.num_of_late_views = stream.num_of_late_views - 1 else: Connexus.count_queue.appendleft(datetime_in_queue) break streams = Stream.query().order(-Stream.num_of_late_views).fetch(3) logging.info("count now is " + str(TrendStreams.num) + " " + str(TrendStreams.initial_num)) if(TrendStreams.num == 0): TrendStreams.num = TrendStreams.initial_num # Prepare for the mail content mail_content = "The most popular three streams are as follows:\n" for stream in streams: mail_content = mail_content + str(stream.name) + " has been recently viewed for " + str(stream.num_of_late_views) + " times!\n" mail_content = mail_content + "Thank you for following us~\n" # Send the notification to specified user email="nima.dini@@utexas.edu" message = mail.EmailMessage() message.sender = "*****@*****.**" message.to = email message.subject = "Check the most popular three streams!" message.body = mail_content message.send() TrendStreams.num = TrendStreams.num - 1 # In order to overstack if TrendStreams.num == -100: TrendStreams.num = -1 template_values = { 'streams': streams, # 'user_id': user.user_id(), 'url': url, 'url_linktext': url_linktext, 'value_checked':TrendStreams.initial_num, 'tags':str(tags) } template = Connexus.JINJA_ENVIRONMENT.get_template('/htmls/TrendingStreams.html') self.response.write(template.render(template_values))
def post(self): user = users.get_current_user() stream_name = self.request.get('stream_name') stream = Stream.query(Stream.name == stream_name).fetch(1)[0] stream.subscribers.append(user.email()) stream.put() self.redirect('/view?stream_name=' + str(stream_name))
def post(self): try: stream_name = self.request.get('stream_name') stream = Stream.query(Stream.name == stream_name).fetch(1)[0] if self.get_uploads(): logging.error("something") else: logging.error("none") for upload in self.get_uploads(): stream.num_of_pics = stream.num_of_pics+1 stream.date = datetime.datetime.now() stream.pictures.append(Picture(blob_key = upload.key(), date = datetime.datetime.now(), longitude = random.uniform(-150,150), latitude = random.uniform(-85,85))) stream.put() stream.put() # self.redirect('/view?stream_name=%s' % stream_name) # self.response.write("rrrr") except: self.error(500)
def get(self): streams = Stream.query().order(-Stream.creation_time).fetch() template_values = { 'streams': streams, } template = JINJA_ENVIRONMENT.get_template('ViewAll.html') self.response.write(template.render(template_values))
def post(self): user=users.get_current_user() if self.request.get('delete'): owned_streams=Stream.query(Stream.owner==user).fetch() for stream in owned_streams: tmp='delete'+str(stream.key.id()) if self.request.get(tmp): stream.key.delete() if self.request.get('unsubscribe'): all_streams=Stream.query().fetch() for stream in all_streams: tmp='unsubscribe'+str(stream.key.id()) if self.request.get(tmp): stream.subscribers.remove(user.email()) stream.put() self.redirect('/management')
def get(self): user=users.get_current_user() owned_streams=[] subscribed_streams=[] owned_streams=Stream.query(Stream.owner==user).fetch() all_streams=Stream.query().fetch() for stream in all_streams: if (user.email() in stream.subscribers): subscribed_streams.append(stream) template_values={ 'owned_streams':owned_streams, 'subscribed_streams':subscribed_streams } template=JINJA_ENVIRONMENT.get_template('management.html') self.response.write(template.render(template_values))
def post(self): stream_name = self.request.get('stream_name') stream = Stream.query(Stream.name == stream_name).fetch(1)[0] user = users.get_current_user() raw_data = { "count": 0, "photos": [ ]} i = 1 start = int(self.request.get("start")) end = int(self.request.get("end")) for picture in stream.pictures: if (picture.date - datetime.datetime.now()) >= datetime.timedelta(days=start) and (picture.date - datetime.datetime.now()) <= datetime.timedelta(days=end): raw_data['photos'].append({"photo_id": i, "photo_title": "Picture " + str(i), "photo_url": get_serving_url(picture.blob_key), "photo_file_url": get_serving_url(picture.blob_key), "longitude": random.randint(-150, 150), "latitude": random.randint(-85, 85), "width": 500, "height": 375, "upload_date": "04 February 2015", "owner_id": 161470, "owner_name": str(user.email()), "owner_url": " "}) raw_data['count'] = raw_data['count'] + 1 i = i + 1 data = json.dumps(raw_data) self.response.write(data)
def get(self): streams = Stream.query().order(-Stream.num_of_views).fetch(3) template_values = { 'streams': streams, } template = JINJA_ENVIRONMENT.get_template('trend.html') self.response.write(template.render(template_values))
def get(self): stream_name = self.request.get('stream_name') stream = Stream.query(Stream.name == stream_name).fetch(1)[0] picture_urls = [] for picture in stream.pictures: picture_urls.append(get_serving_url(picture.blob_key, size=None, crop=False)) dictPassed = {'picture_urls':picture_urls,"user_email":stream.author} jsonObj = json.dumps(dictPassed,sort_keys=True,indent=4, separators=(',', ': ')) self.response.write(jsonObj)
def get(self): stream_name = self.request.get('stream_name') # self.response.write(stream_name + " ") stream = Stream.query(Stream.name == stream_name).fetch(1)[0] # user = User.query(User.email == users.get_current_user().email) # Check if the user logs in streams_tags = '' user = users.get_current_user() if user: url = users.create_logout_url(self.request.uri) url_linktext = 'Logout' some_streams = CreateStream.Stream.query().fetch(50) for one_stream in some_streams: streams_tags = streams_tags + str(one_stream.name) + ' ' for tag in one_stream.tags: streams_tags = streams_tags + str(tag) + ' ' else: url = users.create_login_url(self.request.uri) url_linktext = 'Login' # if stream.num_of_views: stream.num_of_views = stream.num_of_views + 1 stream.num_of_late_views = stream.num_of_late_views + 1 Connexus.count_queue.append((stream.name, datetime.datetime.now())) stream.put() # self.response.write("stream has been viewed: " + str(stream.num_of_views)) upload_url = blobstore.create_upload_url('/upload_photo?stream_name='+str(stream_name)) # self.redirect('/img?stream_name='+str(stream_name)) cover_url = stream.cover tags='' for tag in stream.tags: tags = tags+' '+tag template_values = { 'stream_name': stream_name, # "stream.num_of_views":stream.num_of_views, "stream_tags": tags, "stream_pictures":stream.pictures, 'cover_url': cover_url, 'user_id': user.email(), 'url': url, 'url_linktext': url_linktext, 'upload_url': upload_url, } template = JINJA_ENVIRONMENT.get_template('/htmls/ViewASingleStream.html') self.response.write(template.render(template_values))
def post(self): try: stream_name = self.request.get('stream_name') stream = Stream.query(Stream.name == stream_name).fetch(1)[0] upload = self.get_uploads()[0] picture = Picture(blob_key=upload.key(), date=datetime.datetime.now()) picture.put() stream.pictures.append(picture) stream.num_of_pics += 1 stream.cover_url = '/view_photo/' + str(upload.key()) stream.put() self.redirect('/view?stream_name=' + str(stream_name)) except: self.error(500)
def get(self): stream_name = self.request.get('stream_name') stream = Stream.query(Stream.name == stream_name).fetch(1)[0] user = users.get_current_user() stream.num_of_views += 1 stream.put() upload_url = blobstore.create_upload_url('/upload_photo?stream_name=' + str(stream_name)) template_values = { 'stream_name': stream_name, 'upload_url': upload_url, 'pictures': stream.pictures } template = JINJA_ENVIRONMENT.get_template('ViewSingle.html') self.response.write(template.render(template_values))
def post(self): keyword = self.request.get('keyword') streams = Stream.query().fetch() searched_streams = [] for stream in streams: if keyword in stream.tags: searched_streams.append(stream) results_num = len(searched_streams) template_values = { 'results_num': results_num, 'keyword': keyword, 'streams': searched_streams, } template = JINJA_ENVIRONMENT.get_template('SearchResult.html') self.response.write(template.render(template_values))
def post(self): stream_name = self.request.params.get('stream_name') stream = Stream.query(Stream.name == stream_name).fetch(1)[0] tags = self.request.params.get('tags') stream.tags.append(tags) upload = self.get_uploads()[0] stream.pictures.append(Picture(blob_key = upload.key(), date = datetime.datetime.now(), # longitude = self.request.params.get('latitude'), # latitude = self.request.params.get('longitude') longitude = 100.0, latitude = 100.0)) stream.put(); stream.put();
def post(self): user = users.get_current_user() if user: getUser = User.query(User.email == user.email()) # self.response.write(str(getUser.fetch(1))) global currentUser if getUser.fetch(1): currentUser = getUser.fetch(1)[0] else: currentUser = User(identity = user.user_id(), email = user.email()) currentUser.put() stream_name = self.request.get('stream_name') stream = Stream.query(Stream.name == stream_name).fetch(1)[0] currentUser.streams_subscribed.append(stream.key) currentUser.put() currentUser.put() self.redirect('/') # User has not been logged in else: self.redirect(users.create_login_url(self.request.uri))