def saveTweets(self, term): tweets = self.getTweetsJSON(term) return if not tweets: logging.info("Saved 0 tweets") return 0 for tweet in tweets['statuses']: # Discard retweets if tweet.has_key('retweeted_status'): continue post = Posts() if not post.hasPost(tweet['id']): post.orig_post_id = int(tweet['id']) post.orig_user_id = int(tweet['user']['id']) post.date = int(time.mktime(time.strptime(tweet['created_at'], '%a %b %d %H:%M:%S +0000 %Y'))) post.username = tweet['user']['screen_name'] post.text = tweet['text'] post.image_small = [tweet['entities']['media'][0]['media_url'] if 'media' in tweet['entities'] else ''][0] post.image_full = [tweet['entities']['media'][0]['media_url'] if 'media' in tweet['entities'] else ''][0] post.service = 'twitter' post.likes = None post.orig_url = None post.save()
def saveMedia(self, term): media_json = self.getJSON(term) if not media_json: logging.info("Saved 0 media") return 0 for media in media_json['data']: post = Posts() if not post.hasPost(int(media['id'].split('_')[0])): post.orig_post_id = int(media['id'].split('_')[0]) post.orig_user_id = int(media['user']['id']) post.date = int(media['created_time']) post.username = media['user']['username'] post.text = media['caption']['text'] post.image_small = media['images']['low_resolution']['url'] post.image_full = media['images']['standard_resolution']['url'] post.service = 'instagram' post.likes = None post.orig_url = media['link'] post.save()
def saveTweets(self, term): tweets = self.getTweetsJSON(term) return if not tweets: logging.info("Saved 0 tweets") return 0 for tweet in tweets['statuses']: # Discard retweets if tweet.has_key('retweeted_status'): continue post = Posts() if not post.hasPost(tweet['id']): post.orig_post_id = int(tweet['id']) post.orig_user_id = int(tweet['user']['id']) post.date = int( time.mktime( time.strptime(tweet['created_at'], '%a %b %d %H:%M:%S +0000 %Y'))) post.username = tweet['user']['screen_name'] post.text = tweet['text'] post.image_small = [ tweet['entities']['media'][0]['media_url'] if 'media' in tweet['entities'] else '' ][0] post.image_full = [ tweet['entities']['media'][0]['media_url'] if 'media' in tweet['entities'] else '' ][0] post.service = 'twitter' post.likes = None post.orig_url = None post.save()
def post(self): if users.get_current_user(): error_str = "" #checking upload size upload_files = self.get_uploads('file') if upload_files.__sizeof__() > blobstore.MAX_BLOB_FETCH_SIZE: upload_files = None error_str = error_str + "<p>Picture size is too large.</p>" if upload_files: blob_info = upload_files[0] blob_key = blob_info.key() else: blob_key = None post_sub = self.request.get('subject') post_content = self.request.get('content') if self.request.get('video'): if MediaHelper().validate_vid_url(self.request.get('video')): vid_url = self.request.get('video') else: vid_url = None error_str = error_str + "<p>The youtube url you entered is invalid.</p>" else: vid_url = None date_str = self.request.get('date') #make datetime if not date_str == None: date = datetime.strptime(date_str,'%m/%d/%Y') time = datetime.time(datetime.now()) dt = datetime.combine(date, time) else: dt = None posttype = self.request.get('posttype') is_post = False post_stat = "" if str(posttype) == 'POST': post_stat = "Published" is_post = True else: post_stat = "Saved" #save/update post if not self.request.POST.get('id', None): post = Posts( title=post_sub, text=post_content, status=post_stat, video_url=vid_url, blob_key=blob_key, date=dt ) #editing else: post = db.get(self.request.get('id')) post.title = post_sub post.text = post_content post.status = post_stat post.video_url=vid_url post.date=dt if blob_key and post.blob_key: if not post.blob_key == blob_key: blobstore.delete(post.blob_key.key()) post.blob_key=blob_key elif blob_key: post.blob_key = blob_key elif post.blob_key: blobstore.delete(post.blob_key.key()) if not self.setPageTags(post) and is_post: error_str = error_str + "<p>Select at least one publish area.</p>" #save is error if error_str: post.status = "Saved" post.put() if error_str: self.redirect('/post?post_id=' + str(post.key()) + "&error=" + error_str) elif is_post: self.redirect('/') else: self.redirect('/post?post_id=' + str(post.key())) else: message= "You must login to access this page".encode("utf8") self.redirect('/logout?message=' + message)
def post(self): if users.get_current_user(): error_str = "" #checking upload size upload_files = self.get_uploads('file') if upload_files.__sizeof__() > blobstore.MAX_BLOB_FETCH_SIZE: upload_files = None error_str = error_str + "<p>Picture size is too large.</p>" if upload_files: blob_info = upload_files[0] blob_key = blob_info.key() else: blob_key = None post_sub = self.request.get('subject') post_content = self.request.get('content') if self.request.get('video'): if MediaHelper().validate_vid_url(self.request.get('video')): vid_url = self.request.get('video') else: vid_url = None error_str = error_str + "<p>The youtube url you entered is invalid.</p>" else: vid_url = None date_str = self.request.get('date') #make datetime if not date_str == None: date = datetime.strptime(date_str, '%m/%d/%Y') time = datetime.time(datetime.now()) dt = datetime.combine(date, time) else: dt = None posttype = self.request.get('posttype') is_post = False post_stat = "" if str(posttype) == 'POST': post_stat = "Published" is_post = True else: post_stat = "Saved" #save/update post if not self.request.POST.get('id', None): post = Posts(title=post_sub, text=post_content, status=post_stat, video_url=vid_url, blob_key=blob_key, date=dt) #editing else: post = db.get(self.request.get('id')) post.title = post_sub post.text = post_content post.status = post_stat post.video_url = vid_url post.date = dt if blob_key and post.blob_key: if not post.blob_key == blob_key: blobstore.delete(post.blob_key.key()) post.blob_key = blob_key elif blob_key: post.blob_key = blob_key elif post.blob_key: blobstore.delete(post.blob_key.key()) if not self.setPageTags(post) and is_post: error_str = error_str + "<p>Select at least one publish area.</p>" #save is error if error_str: post.status = "Saved" post.put() if error_str: self.redirect('/post?post_id=' + str(post.key()) + "&error=" + error_str) elif is_post: self.redirect('/') else: self.redirect('/post?post_id=' + str(post.key())) else: message = "You must login to access this page".encode("utf8") self.redirect('/logout?message=' + message)