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()