def all_metadata_access(session, api_location, username, target_channel_name): target_channel_name = "%s@%s" % (obtainActualName( session, target_channel_name.split("@")[0]), target_channel_name.split("@")[1]) if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request( 'GET', "%s%s/metadata/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request( 'GET', "%s%s/metadata/posts" % (api_location, target_channel_name)) if status: try: response = json.loads(response.content) return ('title' in response and 'description' in response and 'access_model' in response and 'creation_date' in response and 'channel_type' in response and 'default_affiliation' in response) except ValueError: pass return False
def banned_subscribers_access(api_location, username, target_channel_name): target_channel_name = "%s@%s" % (obtainActualName(target_channel_name.split("@")[0]), target_channel_name.split("@")[1]) if username != None: username = obtainActualName(username) (status, response) = prepare_and_send_request('GET', "%s%s/subscribers/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request('GET', "%s%s/subscribers/posts" % (api_location, target_channel_name)) if status: try: response = json.loads(response.content) for jid in response.keys(): if response[jid] == 'outcast': return True except ValueError: pass return False
def banned_subscribers_access(session, api_location, username, target_channel_name): target_channel_name = "%s@%s" % (obtainActualName( session, target_channel_name.split("@")[0]), target_channel_name.split("@")[1]) if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request( 'GET', "%s%s/subscribers/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request( 'GET', "%s%s/subscribers/posts" % (api_location, target_channel_name)) if status: try: response = json.loads(response.content) for jid in response.keys(): if response[jid] == 'outcast': return True except ValueError: pass return False
def all_metadata_access(api_location, username, target_channel_name): target_channel_name = "%s@%s" % (obtainActualName(target_channel_name.split("@")[0]), target_channel_name.split("@")[1]) if username != None: username = obtainActualName(username) (status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location, target_channel_name)) if status: try: response = json.loads(response.content) return ( 'title' in response and 'description' in response and 'access_model' in response and 'creation_date' in response and 'channel_type' in response and 'default_affiliation' in response ) except ValueError: pass return False
def remove_post_created_by_moderator(session, api_location, username, target_channel_name): target_username = obtainActualName(session, target_channel_name.split("@")[0]) domain_url = target_channel_name.split("@")[1] target_channel_name = "%s@%s" % (target_username, domain_url) owner_username = '******' owner_username = obtainActualName(session, owner_username) content_posted = "By the way, what happened to Waaaaaalt?" data = {"content": content_posted} (status, response) = prepare_and_send_request( 'POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data, authorization=owner_username) if status: try: response = json.loads(response.content) post_id = response['id'] post_author = response['author'] content_obtained = response['content'] if (post_author != "%s@%s" % (owner_username, domain_url.replace("topics.", "")) or content_obtained != content_posted): return False if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request( 'DELETE', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id), authorization=username) else: (status, response) = prepare_and_send_request( 'DELETE', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id)) return status except ValueError: pass return False
def remove_post_created_by_owner(session, api_location, username, target_channel_name): target_username = obtainActualName(session, target_channel_name.split("@")[0]) domain_url = target_channel_name.split("@")[1] target_channel_name = "%s@%s" % (target_username, domain_url) if ( 'open' in target_username ): owner_username = '******' else: owner_username = '******' owner_username = obtainActualName(session, owner_username) content_posted = "By the way, what happened to Waaaaaalt?" data = { "content" : content_posted } (status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data, authorization=owner_username) if status: try: response = json.loads(response.content) post_id = response['id'] post_author = response['author'] content_obtained = response['content'] if ( post_author != "%s@%s" % (owner_username, domain_url.replace("topics.", "")) or content_obtained != content_posted ): return False if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request('DELETE', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id), authorization=username) else: (status, response) = prepare_and_send_request('DELETE', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id)) return status except ValueError: pass return False
def remove_own_post(session, api_location, username, target_channel_name): target_username = obtainActualName(session, target_channel_name.split("@")[0]) domain_url = target_channel_name.split("@")[1] target_channel_name = "%s@%s" % (target_username, domain_url) content_posted = "The Lost finale was pretty bad." data = { "content" : content_posted } if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data, authorization=username) else: (status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data) if status: try: response = json.loads(response.content) post_id = response['id'] post_author = response['author'] content_obtained = response['content'] if ( post_author != "%s@%s" % (username, domain_url.replace("topics.", "")) or content_obtained != content_posted ): return False if username != None: (status, response) = prepare_and_send_request('DELETE', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id), authorization=username) else: (status, response) = prepare_and_send_request('DELETE', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id)) return status except ValueError: pass return False
def outside_roles_access(api_location, username, target_channel_name): target_channel_name = "%s@%s" % (obtainActualName(target_channel_name.split("@")[0]), target_channel_name.split("@")[1]) if username != None: username = obtainActualName(username) (status, response) = prepare_and_send_request('GET', "%ssubscribed" % (api_location), authorization=username) else: (status, response) = prepare_and_send_request('GET', "%ssubscribed" % (api_location)) return status
def posts_read_access(api_location, username, target_channel_name): target_channel_name = "%s@%s" % (obtainActualName(target_channel_name.split("@")[0]), target_channel_name.split("@")[1]) if username != None: username = obtainActualName(username) (status, response) = prepare_and_send_request('GET', "%s%s/content/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request('GET', "%s%s/content/posts" % (api_location, target_channel_name)) return status
def posts_read_access(session, api_location, username, target_channel_name): target_channel_name = "%s@%s" % (obtainActualName( session, target_channel_name.split("@")[0]), target_channel_name.split("@")[1]) if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request( 'GET', "%s%s/content/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request( 'GET', "%s%s/content/posts" % (api_location, target_channel_name)) return status
def outside_roles_access(session, api_location, username, target_channel_name): target_channel_name = "%s@%s" % (obtainActualName( session, target_channel_name.split("@")[0]), target_channel_name.split("@")[1]) if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request('GET', "%ssubscribed" % (api_location), authorization=username) else: (status, response) = prepare_and_send_request('GET', "%ssubscribed" % (api_location)) return status
def update_metadata_info(api_location, username, target_channel_name, metadata_field, metadata_value): target_channel_name = "%s@%s" % (obtainActualName(target_channel_name.split("@")[0]), target_channel_name.split("@")[1]) if username != None: username = obtainActualName(username) (status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location, target_channel_name)) if status: try: response = json.loads(response.content) if metadata_value.startswith("*"): metadata_value = response[metadata_field] + metadata_value.replace("*", "") else: metadata_value = metadata_value.replace("/", "").replace(response[metadata_field], "") except ValueError: pass data = { metadata_field : metadata_value } if username != None: (status, response) = prepare_and_send_request('POST', "%s%s/metadata/posts" % (api_location, target_channel_name), payload=data, authorization=username) else: (status, response) = prepare_and_send_request('POST', "%s%s/metadata/posts" % (api_location, target_channel_name), payload=data) if status: if username != None: (status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request('GET', "%s%s/metadata/posts" % (api_location, target_channel_name)) if status: try: response = json.loads(response.content) return response[metadata_field] == metadata_value except ValueError: pass return False
def remove_own_post(session, api_location, username, target_channel_name): target_username = obtainActualName(session, target_channel_name.split("@")[0]) domain_url = target_channel_name.split("@")[1] target_channel_name = "%s@%s" % (target_username, domain_url) content_posted = "The Lost finale was pretty bad." data = {"content": content_posted} if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request( 'POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data, authorization=username) else: (status, response) = prepare_and_send_request( 'POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data) if status: try: response = json.loads(response.content) post_id = response['id'] post_author = response['author'] content_obtained = response['content'] if (post_author != "%s@%s" % (username, domain_url.replace("topics.", "")) or content_obtained != content_posted): return False if username != None: (status, response) = prepare_and_send_request( 'DELETE', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id), authorization=username) else: (status, response) = prepare_and_send_request( 'DELETE', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id)) return status except ValueError: pass return False
def add_new_post_and_get_by_matching_id(session, api_location, username, target_channel_name): target_username = obtainActualName(session, target_channel_name.split("@")[0]) domain_url = target_channel_name.split("@")[1] target_channel_name = "%s@%s" % (target_username, domain_url) content_posted = "'Don't tell me what I can't do' is a frequently spoken phrase on Lost." data = {"content": content_posted} if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request( 'POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data, authorization=username) else: (status, response) = prepare_and_send_request( 'POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data) if status: try: response = json.loads(response.content) post_id = response['id'] post_author = response['author'] content_obtained = response['content'] if (post_author != "%s@%s" % (username, domain_url.replace("topics.", "")) or content_obtained != content_posted): return False if username != None: (status, response) = prepare_and_send_request( 'GET', "%s%s/content/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request( 'GET', "%s%s/content/posts" % (api_location, target_channel_name)) if status: try: response = json.loads(response.content) for item in response: if (item['id'] == post_id and item['author'] == post_author and item['content'] == content_obtained): return True except ValueError: pass except ValueError: pass return False
def add_new_post_and_get_by_id_direct_access(session, api_location, username, target_channel_name): target_username = obtainActualName(session, target_channel_name.split("@")[0]) domain_url = target_channel_name.split("@")[1] target_channel_name = "%s@%s" % (target_username, domain_url) content_posted = "'You all everybody' by Drive Shaft is the best song ever." data = { "content" : content_posted } if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data, authorization=username) else: (status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data) if status: try: response = json.loads(response.content) post_id = response['id'] post_author = response['author'] content_obtained = response['content'] if ( post_author != "%s@%s" % (username, domain_url.replace("topics.", "")) or content_obtained != content_posted ): return False if username != None: (status, response) = prepare_and_send_request('GET', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id), authorization=username) else: (status, response) = prepare_and_send_request('GET', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id)) if status: try: response = json.loads(response.content) return ( post_id == response['id'] and post_author == response['author'] and content_obtained == response['content'] ) except ValueError: pass except ValueError: pass return False
def add_new_post_and_get_by_id_direct_access(session, api_location, username, target_channel_name): target_username = obtainActualName(session, target_channel_name.split("@")[0]) domain_url = target_channel_name.split("@")[1] target_channel_name = "%s@%s" % (target_username, domain_url) content_posted = "'You all everybody' by Drive Shaft is the best song ever." data = {"content": content_posted} if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request( 'POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data, authorization=username) else: (status, response) = prepare_and_send_request( 'POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data) if status: try: response = json.loads(response.content) post_id = response['id'] post_author = response['author'] content_obtained = response['content'] if (post_author != "%s@%s" % (username, domain_url.replace("topics.", "")) or content_obtained != content_posted): return False if username != None: (status, response) = prepare_and_send_request( 'GET', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id), authorization=username) else: (status, response) = prepare_and_send_request( 'GET', "%s%s/content/posts/%s" % (api_location, target_channel_name, post_id)) if status: try: response = json.loads(response.content) return (post_id == response['id'] and post_author == response['author'] and content_obtained == response['content']) except ValueError: pass except ValueError: pass return False
def add_new_post_and_get_by_matching_id(session, api_location, username, target_channel_name): target_username = obtainActualName(session, target_channel_name.split("@")[0]) domain_url = target_channel_name.split("@")[1] target_channel_name = "%s@%s" % (target_username, domain_url) content_posted = "'Don't tell me what I can't do' is a frequently spoken phrase on Lost." data = { "content" : content_posted } if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data, authorization=username) else: (status, response) = prepare_and_send_request('POST', "%s%s/content/posts" % (api_location, target_channel_name), payload=data) if status: try: response = json.loads(response.content) post_id = response['id'] post_author = response['author'] content_obtained = response['content'] if ( post_author != "%s@%s" % (username, domain_url.replace("topics.", "")) or content_obtained != content_posted ): return False if username != None: (status, response) = prepare_and_send_request('GET', "%s%s/content/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request('GET', "%s%s/content/posts" % (api_location, target_channel_name)) if status: try: response = json.loads(response.content) for item in response: if ( item['id'] == post_id and item['author'] == post_author and item['content'] == content_obtained ): return True except ValueError: pass except ValueError: pass return False
def add_new_status_and_check(session, api_location, username, target_channel_name): target_username = obtainActualName(session, target_channel_name.split("@")[0]) domain_url = target_channel_name.split("@")[1] target_channel_name = "%s@%s" % (target_username, domain_url) new_mood = "I'm sad that Lost is over." data = { "content" : new_mood } if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request('POST', "%s%s/content/status" % (api_location, target_channel_name), payload=data, authorization=username) else: (status, response) = prepare_and_send_request('POST', "%s%s/content/status" % (api_location, target_channel_name), payload=data) if status: try: response = json.loads(response.content) new_mood_id = response['id'] new_mood_author = response['author'] current_mood = response['content'] if ( new_mood_author != "%s@%s" % (username, domain_url.replace("topics.", "")) or current_mood != new_mood ): return False if username != None: (status, response) = prepare_and_send_request('GET', "%s%s/content/status/%s" % (api_location, target_channel_name, new_mood_id), authorization=username) else: (status, response) = prepare_and_send_request('GET', "%s%s/content/status/%s" % (api_location, target_channel_name, new_mood_id)) if status: try: response = json.loads(response.content) return ( new_mood_id == response['id'] and new_mood_author == response['author'] and current_mood == response['content'] ) except ValueError: pass except ValueError: pass return False
def update_metadata_info(session, api_location, username, target_channel_name, metadata_field, metadata_value): target_channel_name = "%s@%s" % (obtainActualName( session, target_channel_name.split("@")[0]), target_channel_name.split("@")[1]) if username != None: username = obtainActualName(session, username) (status, response) = prepare_and_send_request( 'GET', "%s%s/metadata/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request( 'GET', "%s%s/metadata/posts" % (api_location, target_channel_name)) if status: try: response = json.loads(response.content) if metadata_value.startswith("*"): metadata_value = response[ metadata_field] + metadata_value.replace("*", "") else: metadata_value = metadata_value.replace("/", "").replace( response[metadata_field], "") except ValueError: pass data = {metadata_field: metadata_value} if username != None: (status, response) = prepare_and_send_request( 'POST', "%s%s/metadata/posts" % (api_location, target_channel_name), payload=data, authorization=username) else: (status, response) = prepare_and_send_request( 'POST', "%s%s/metadata/posts" % (api_location, target_channel_name), payload=data) if status: if username != None: (status, response) = prepare_and_send_request( 'GET', "%s%s/metadata/posts" % (api_location, target_channel_name), authorization=username) else: (status, response) = prepare_and_send_request( 'GET', "%s%s/metadata/posts" % (api_location, target_channel_name)) if status: try: response = json.loads(response.content) return response[metadata_field] == metadata_value except ValueError: pass return False