def get_all_comments_user(self): activity_id = self.activity_id client = Streamio() self.client = client._connect() reactions = self.client.reactions.filter(activity_id=activity_id, kind='comment') # print(reactions['results']) for value in reactions['results']: # print(value) dynamodb = boto3.resource('dynamodb', region_name='us-east-1') table = dynamodb.Table('database-dev') response = table.query( KeyConditionExpression=Key('hk').eq(value["user_id"])) # print(response['Items']) self.temp_dict = value self.temp_dict['user_details'] = response["Items"][0] self.temp_list.append(self.temp_dict) # print(self.temp_dict) self.return_dict["results"] = self.temp_list return self.return_dict # return response['Items'] # return reactions # https://9q2d566izk.execute-api.us-east-1.amazonaws.com/dev/commentsfeed?activityid=bd3b9da6-33cc-11eb-a511-0a1200300037 # x = Get_comments_user(activity_id="b4c7397a-363e-11eb-8080-80004f33ba1c") # y = x.get_all_comments_user() # print(y)
def return_no_of_followers(self): temp_list = {} client = Streamio() self.client = client._connect() feed1 = self.client.feed('timeline', self.userid) a = feed1.following(limit=100) temp_list['followers'] = a['results'] temp_list['no_of_followers'] = len(a['results']) # print(temp_list) return temp_list
def follow_the_page(self): client = Streamio() self.client = client._connect() feed = self.client.feed('timeline', self.userid) for x in self.follow_list: feed.follow("pages", x.lower().replace(" ", ""), activity_copy_limit=500) return "users are followed" # x=Followpage(userid="1234userid",follow_list=['google']) # y=x.follow_the_page() # print(y)
def get_user_timelinesfeed(self): # client=Streamio() # self.client=client._connect() # feed = self.client.feed('timeline', self.userid) # activities = feed.get(reactions={"counts": True}) # # print(activities) # return json.dumps(activities, indent=4, sort_keys=True, default=str) client = Streamio() self.client = client._connect() feed = self.client.feed('timeline', self.userid) activities = feed.get(limit=self.limit, offset=self.offset, reactions={ "counts": True, "own": True }) for item, check_like in enumerate(activities["results"]): self.temp_dict = json.loads(activities["results"][item]["object"]) self.temp_dict["id"] = check_like["id"] self.temp_dict["actor"] = check_like["actor"] self.temp_dict["time"] = str(check_like["time"]) self.temp_dict["current_user_like"] = False if "like" in check_like["reaction_counts"].keys(): self.temp_dict["likes"] = check_like["reaction_counts"]["like"] else: self.temp_dict["likes"] = 0 if "comments" in check_like["reaction_counts"].keys(): self.temp_dict["no_of_comments"] = check_like[ "reaction_counts"]["like"] else: self.temp_dict["no_of_comments"] = 0 if ("like" in check_like['own_reactions'].keys()): for check_like_true in check_like['own_reactions']['like']: if (check_like_true['user_id'] == self.userid): self.temp_dict["current_user_like"] = True self.temp_list.append(self.temp_dict) return self.temp_list # x=Get_user_time_feed(userid="1234userid",limit="2",offset="2") # y=x.get_user_timelinesfeed() # print(y) # json.dumps(anObject, default=json_util.default)
def get_all_likes_user(self): dynamodb = boto3.resource('dynamodb', region_name='us-east-1') table = dynamodb.Table('database-dev') activity_id = self.activity_id client = Streamio() self.client = client._connect() reactions = self.client.reactions.filter(activity_id=activity_id, kind='like') object_return = {} capture_results = reactions['results'] for values in capture_results: response = table.query( KeyConditionExpression=Key('hk').eq(values['user_id'])) object_return[values['user_id']] = response['Items'] return object_return
def get_pagesfeed(self): client = Streamio() self.client = client._connect() feed = self.client.feed('pages',self.pagename) activities = feed.get(limit=self.limit, offset=self.offset,reactions={"counts": True,"own": True}) # print(activities,"activities") for item,check_like in enumerate(activities["results"]): # print(activities["results"][item]["time"]) self.temp_dict = json.loads(activities["results"][item]["object"]) self.temp_dict["id"] = check_like["id"] self.temp_dict["actor"] = check_like["actor"] self.temp_dict["time"] = str(check_like["time"]) # self.temp_dict["to"] = check_like["to"] self.temp_dict["current_user_like"] = False if "like" in check_like["reaction_counts"].keys(): self.temp_dict["likes"] = check_like["reaction_counts"]["like"] else: self.temp_dict["likes"] = 0 if "comments" in check_like["reaction_counts"].keys(): self.temp_dict["no_of_comments"] = check_like["reaction_counts"]["like"] else: self.temp_dict["no_of_comments"] = 0 if("like" in check_like['own_reactions'].keys()): for check_like_true in check_like['own_reactions']['like']: if(check_like_true['user_id']==self.userid): self.temp_dict["current_user_like"] = True self.temp_list.append(self.temp_dict) # # print(activities["results"][0]) # print(self.temp_list) return self.temp_list # return json.dumps(activities,default=self.json_serial) # x=Get_pages_feed(pagename="google",userid="1234userid",limit="2",offset="0") # y=x.get_pagesfeed() # print(y)
def likingfeed(self): client = Streamio() self.client = client._connect() # feed = self.client.feed('pages',self.pagename) reactions = self.client.reactions.filter(activity_id=self.activityid, kind='like') # print("reaction",reactions["results"]) x = 0 self.capturereation = False for checkreaction in reactions["results"]: if (x == 0): if (checkreaction["user_id"] == self.userid): self.capturereation = True self.captureid = checkreaction["id"] x = 1 else: self.capturereation = False # print("true") if (self.capturereation == True): self.client.reactions.delete(self.captureid) return "successfully unliked the feed" else: self.client.reactions.add("like", self.activityid, user_id=self.userid) return "successfully liked the feed" # result = feed.get(offset=0, limit=1, id_lt=last_activity.id) # feed->getActivities(offset=0, limit=1, ['id_gte' => $id]); # 'b7bcd2a2-363e-11eb-8080-800160b53eae' # self.client.reactions.add("like", self.activityid, user_id=self.userid) # return "successfully liked the feed" # x=Likefeed(userid="seconduserid",activityid='b85613f4-363e-11eb-8080-80000b6503b3') # y=x.likingfeed() # print(y)
def commentingfeed(self): client = Streamio() self.client = client._connect() x = self.client.reactions.add("comment", self.activityid, user_id=self.userid, data={"text": self.text}) self.temp_dict = x self.temp_dict["message"] = "successfully commented the feed" dynamodb = boto3.resource('dynamodb', region_name='us-east-1') table = dynamodb.Table('database-dev') response = table.query( KeyConditionExpression=Key('hk').eq(x["user_id"])) self.temp_dict['user_details'] = response["Items"][0] return self.temp_dict # print(x) # self.client.reactions.add("like", self.activityid, user_id=self.userid) # return "successfully commented the feed" # x=Commentfeed(userid="1234userid",activityid="77dc977e-3618-11eb-8080-80001ae9b3e2",text="this is post comment") # y=x.commentingfeed() # print(y)
def unlikingfeed(self): client = Streamio() self.client = client._connect() self.client.reactions.delete(self.reactionid) return "successfully unliked the feed"
def unfollowpages(self): client=Streamio() self.client=client._connect() feed = self.client.feed('timeline', self.userid) feed.unfollow("pages",self.pagename) return "page is unfollowed"
def followusers(self): client = Streamio() self.client = client._connect() feed = self.client.feed('timeline', self.userid) feed.follow("user", self.followuserid) return "user is followed"
dynamodb = boto3.resource('dynamodb', region_name='us-east-1') table = dynamodb.Table('database-dev') # user_id="ac211c30-ffdd-40af-9402-d3b36a671a7b" # activity_id="5f09e455-1fa0-11eb-bec3-128a130028af" # client = stream.connect('q2hzgpctc2e5', 'cgrx2vxsy6kmr4m76mt648azhfcucjkyev2v27au2envsgujxer3zs62fpwtm4xb') # reactions = client.reactions.filter( # activity_id=activity_id, # kind='like', # ) # print(len(reactions)) user_id = "1234userid" activity_id = "77dc977e-3618-11eb-8080-80001ae9b3e2" # client = stream.connect('q2hzgpctc2e5', 'cgrx2vxsy6kmr4m76mt648azhfcucjkyev2v27au2envsgujxer3zs62fpwtm4xb') # client.reactions.add("comment", activity_id, user_id=user_id,data={"text": "awesome post!"}) client1 = Streamio() client2 = client1._connect() reactions = client2.reactions.filter( activity_id=activity_id, kind='like', ) # feed = client2.feed('hashtag', 'trending') # activities = feed.get(reactions={"counts": True}) object_return = {} capture_results = reactions['results'] for values in capture_results: # print(values['user_id']) response = table.query( KeyConditionExpression=Key('hk').eq(values['user_id'])) # print(response['Items']) object_return[values['user_id']] = response['Items']