def get_googleplus_data(self, keyword, limit): mentionList = [] activity = self.GPLUS.activities().search(query=keyword, maxResults=20).execute() counter = 0 while (True): nextToken = activity['nextPageToken'] items = activity.get('items', []) for data in items: post = ' '.join(data['title'].strip().split()) if post: mention = Mention() user = User() # print(TMPL % (data['actor']['displayName'], # data['published'], post) ) print(data) print("----------------Post Info-----------------------") mention.set_source('GooglePlus') print("Post url: " + data["url"]) url = data["url"].split("/") mention.set_status_id(url[-1]) print("Resharer Count: " + str(data["object"]["resharers"]['totalItems'])) mention.set_reshare_count( str(data["object"]["resharers"]['totalItems'])) print("Replies Count: " + str(data["object"]["replies"]['totalItems'])) print("Plusoners Count: " + str(data["object"]["plusoners"]['totalItems'])) print("Text: " + data["object"]['content']) mention.set_text(data["object"]['content']) for s in data['object']: if s == 'attachments': attachments = data["object"]['attachments'] for attachment in attachments: print("attachments:" + attachment["url"]) print("----------------User Info-----------------------") user.set_user_id(data['actor']["id"]) print("Diplay Name:" + data['actor']['displayName']) user.set_display_name(data['actor']['displayName']) user.set_display_picture(data['actor']['image']['url']) print("Display Image:" + data['actor']['image']['url']) print("Created at: " + data["published"]) m = moment.date(data["published"], '%Y-%m-%dT%H:%M:%SZ') sql_format = m.format('YYYY-M-D H:mm:ss') print(sql_format) user.set_time(sql_format) mention.set_user(user) mentionList.append(mention) counter = counter + 1 print("--------------------------------------------" + str(counter)) if counter >= limit: break if counter < limit: activity = self.GPLUS.activities().search( query=keyword, maxResults=20, pageToken=nextToken).execute() else: break return mentionList
def get_data(self, tweets_list, mentionlist): for tweet in tweets_list: if (self.count < self.limit): mention = Mention() user = User() # print("----------------Post Info-----------------------") mention.set_source("Twitter") mention.set_reshare_count(str(tweet["retweet_count"])) mention.set_text(tweet['text']) # # print(json.dumps(tweet, sort_keys=True, indent=4)) mention.set_status_id(tweet["id_str"]) print("Tweet ID: " + tweet["id_str"]) # print("Created at: " + tweet["created_at"]) sql_format = datetime.strptime(tweet["created_at"], '%a %b %d %H:%M:%S %z %Y') user.set_time(sql_format.strftime('%Y-%m-%d %H:%M:%S')) # t=datetime.strptime(tweet["created_at"], '%a %b %d %H:%M:%S %z %Y') # t.strftime('%Y-%m-%d %H:%M:%S') # m = moment.date(tweet["created_at"], '%a %b %d %H:%M:%S %z %Y') # sql_format = m.format('YYYY-M-D H:mm:ss') # print(sql_format) # print("Tweet Language: " + tweet["lang"]) if tweet["retweet_count"] != 0: user.set_display_name( tweet["retweeted_status"]["user"]["screen_name"]) user.set_display_picture( tweet["retweeted_status"]['user']['profile_image_url']) mention.set_status_id(str(tweet["retweeted_status"]['id'])) # print("----------------Retweeted User Info-----------------------") user.set_user_id( tweet["retweeted_status"]["user"]["id_str"]) # print("User Name: " + tweet["retweeted_status"]["user"]["name"]) # print("User Location: " + tweet["retweeted_status"]["user"]["location"]) user.set_total_post( str(tweet["retweeted_status"]['user'] ['statuses_count'])) user.set_following_count( str(tweet["retweeted_status"]['user'] ['friends_count'])) user.set_follower_count( str(tweet["retweeted_status"]['user'] ['followers_count'])) user.set_total_likes( str(tweet["retweeted_status"]['user'] ['favourites_count'])) # print("fav: " + str(tweet["retweeted_status"]['favorite_count'])) retweets = self.twitter.statuses.retweets._id( _id=str(tweet["retweeted_status"]['id'])) retweeterlist = [] for retweet in retweets: retweeter = User() retweeter.set_display_name( retweet["user"]["screen_name"]) #dt_str = datetime.datetime.strftime(retweet["created_at"], '%Y-%m-%d %H:%M:%S') retweeter.set_time(retweet["created_at"]) retweeter.set_display_picture( retweet["user"]["profile_image_url"]) retweeter.set_user_id(retweet["user"]["id_str"]) retweeter.set_total_post( str(retweet['user']['statuses_count'])) retweeter.set_following_count( str(retweet['user']['friends_count'])) retweeter.set_follower_count( str(retweet['user']['followers_count'])) retweeter.set_total_likes( str(retweet['user']['favourites_count'])) retweeterlist.append(retweeter) # print(" - retweeted by %s" % (retweet["user"]["screen_name"])) # print("retweet time:" +retweet["created_at"] ) mention.set_resharer(retweeterlist) else: # print("----------------User Info-----------------------") user.set_user_id(tweet["user"]["id_str"]) # print("User Name: " + tweet["user"]["name"]) # print("User Location: " + tweet["user"]["location"]) user.set_display_picture( tweet['user']['profile_image_url']) user.set_display_name(tweet['user']['screen_name']) user.set_total_post(str(tweet['user']['statuses_count'])) user.set_following_count( str(tweet['user']['friends_count'])) user.set_follower_count( str(tweet['user']['followers_count'])) user.set_total_likes(str( tweet['user']['favourites_count'])) mention.set_user(user) mentionlist.append(mention) self.count = self.count + 1 print("<---------------------" + str(self.count) + "---------------------------->") else: return mentionlist return mentionlist