def __init__(self, subreddit): Node.__init__(self, subreddit["id"], subreddit["display_name"], "subreddit") for key in subreddit: if key == "id": continue setattr(self, key, str(subreddit[key]))
def __init__(self, result): Node.__init__(self, str(result["id"]), "tweet_" + str(result["id"]), "tweet") self.created_at = result["created_at"] self.text = result["text"] self.source = result["source"] self.truncated = result["truncated"] self.is_quote_status = result["is_quote_status"] self.retweet_count = result["retweet_count"] self.favorite_count = result["favorite_count"] self.lang = result["lang"] entities = result["entities"] hashtags_list = [] for hashtag in entities["hashtags"]: hashtags_list.append(hashtag["text"]) self.hashtags = hashtags_list urls_list = [] for url in entities["urls"]: urls_list.append(url["url"]) self.urls = urls_list media_list = {} if 'media' in entities: for media in entities["media"]: media_list[media["type"]] = media["url"] self.media = media_list user_mentions_list = [] for user_mention in entities["user_mentions"]: user_mentions_list.append(user_mention["screen_name"]) self.user_mentions = user_mentions_list
def __init__(self, position): """ This class is the position node class which inherits from the BaseNode class It describes the position a user has The position node has following attribute: Id Title (Label for Gephi) Company (Json) Company Id Company Industry Company Name Company Size Comment Type Is Current Job (Boolean) Location Start Month End Month Summary """ Node.__init__(self, str(position["id"]), position["title"], "Position") self.company = position["company"] self.company_id = position["company"]["id"] self.company_industry = position["company"]["industry"] self.company_name = position["company"]["name"] self.company_size = position["company"]["size"] self.company_type = position["company"]["type"] self.is_current = position["isCurrent"] self.location = position["location"]["name"] self.start_month = position["startDate"]["month"] self.start_year = position["startDate"]["year"] self.summary = position["summary"]
def __init__(self, comment): Node.__init__(self, comment["id"], "comment_" + comment["id"], "comment") for key in comment: if key == "id" or key == "replies": continue setattr(self, key, str(comment[key]))
def __init__(self, submission): Node.__init__(self, submission["id"], "submission_" + submission["id"], "submission") for key in submission: if key == "id": continue setattr(self, key, str(submission[key]))
def __init__(self, video): if 'videoId' not in video['id']: video_id = video['id'] else: video_id = video['id']['videoId'] # initialize the video node with video id & label Node.__init__(self, video_id, video['snippet']['title'], "video") self.published_at = video['snippet']['publishedAt'] self.description = video['snippet']['description']
def __init__(self, playlist): if 'playlistId' not in playlist['id']: playlist_id = playlist['id'] else: playlist_id = playlist['id']['playlistId'] Node.__init__(self, playlist_id, playlist['snippet']['title'], "playlist") self.published_at = playlist['snippet']['publishedAt'] self.description = playlist['snippet']['description']
def __init__(self, result): Node.__init__(self, result["id"], result["name"], "board") self.name = result["name"] self.url = result["url"] self.image_url = result["image"]["60x60"]["url"] self.created_at = result["created_at"] self.privacy = result["privacy"] self.pins_count = result["counts"]["pins"] self.collaborators_count = result["counts"]["collaborators"] self.followers_count = result["counts"]["followers"] self.description = result["description"]
def __init__(self, comment): Node.__init__(self, comment['id'], comment['snippet']['textDisplay'], "comment") # Attributes: self.updated_at = comment['snippet']['updatedAt'] self.published_at = comment['snippet']['publishedAt'] self.view_rating = comment['snippet']['viewerRating'] self.can_rate = comment['snippet']['canRate'] self.text_original = comment['snippet']['textOriginal'] self.like_count = comment['snippet']['likeCount']
def __init__( self, blog ): Node.__init__(self, blog['name'], blog['title'], "blog") self.name = blog['name'] self.title = blog['title'] self.description = blog['description'] self.url = blog['url'] self.uuid = blog['uuid'] self.updated = blog['updated']
def __init__(self, comment): Node.__init__(self, comment['id'], comment['id'], "comment") self.created_time = comment['created_time'] self.creator_id = comment['from']['id'] self.creator_name = comment['from']['name'] if 'message' in comment: self.message = comment['message'] else: self.message = None
def __init__(self, result): Node.__init__(self, result["id"], "pin_" + result["id"], "pin") self.url = result["url"] self.image_url = result["image"]["original"]["url"] self.link = result["link"] self.media = result["media"]["type"] self.original_link = result["original_link"] self.created_at = result["created_at"] self.note = result["note"] self.color = result["color"] self.saves = result["counts"]["saves"] self.comments = result["counts"]["comments"]
def __init__(self, profile): """ This class is the profile node class which inherits from the BaseNode class It describes the user profile The position node has following attribute: Id Formatted name (Label for Gephi) First name Last Name Head line Industry Location (Json) Location Name Location Country Code Number of Connections Number of Connections Capped (Boolean) Picture Url Summary May have: Maiden Name Phonetic First Name Phonetic Last Name Formatted Phonetic Name Speicialities """ Node.__init__(self, str(profile["id"]), profile["formattedName"], "Profile") self.first_name = profile["firstName"] self.last_name = profile["lastName"] self.headline = profile["headline"] self.industry = profile["industry"] self.location = profile["location"] self.location_name = profile["location"]["name"] self.location_country = profile["location"]["country"]["code"] self.num_connections = profile["numConnections"] self.num_connections_capped = profile["numConnectionsCapped"] self.picture_url = profile["pictureUrl"] self.summary = profile["summary"] if "maidenName" in profile: self.maiden_name = profile["maidenName"] if "phonetic-first-name" in profile: self.phonetic_first_name = profile["phoneticFirstName"] if "phonetic-last-name" in profile: self.phonetic_last_name = profile["phoneticLastName"] if "formatted-phonetic-name" in profile: self.formatted_phonetic_name = profile["formattedPhoneticName"] if "specialities" in profile: self.specialties = profile["specialities"]
def __init__(self, result): label = result["first_name"] + " " + result["last_name"] Node.__init__(self, result["id"], label, "user") self.username = result["username"] self.first_name = result["first_name"] self.last_name = result["last_name"] self.bio = result["bio"] self.account_type = result["account_type"] self.url = result["url"] self.image_url = result["image"]["60x60"]["url"] self.created_at = result["created_at"] self.pins_count = result["counts"]["pins"] self.following_count = result["counts"]["following"] self.followers_count = result["counts"]["followers"] self.boards_count = result["counts"]["boards"]
def __init__(self, post): Node.__init__(self, post['id'], "post_" + post['id'], "post") self.created_time = post['created_time'] self.creator_id = post['id'].split('_')[0] if 'message' in post: self.message = post['message'] else: self.message = None if 'full_picture' in post: self.picture = post['full_picture'] else: self.picture = None if 'caption' in post: self.caption = post['caption'] else: self.caption = None
def __init__(self, channel): if 'channelId' not in channel['id']: channel_id = channel['id'] else: channel_id = channel['id']['channelId'] # initialize the channel node with node id & Label Node.__init__(self, channel_id, channel['snippet']['title'], "channel") self.description = channel['snippet']['description'] self.published_at = channel['snippet']['publishedAt'] self.view_count = channel['statistics']['viewCount'] self.comment_count = channel['statistics']['commentCount'] self.hidden_subscriber_count = channel['statistics'][ 'hiddenSubscriberCount'] self.video_count = channel['statistics']['videoCount'] if not channel['statistics']['hiddenSubscriberCount']: self.subscriber_count = channel['statistics']['subscriberCount'] if 'customUrl' in channel: self.custom_url = channel['snippet']['customUrl']
def __init__(self, result): self.name = result["name"] Node.__init__(self, str(result["id"]), self.name, "user") self.screen_name = result["screen_name"] self.location = result["location"] self.url = result["url"] self.description = result["description"] self.protected = result["protected"] self.verified = result["verified"] self.followers_count = result["followers_count"] self.friends_count = result["friends_count"] self.listed_count = result["listed_count"] self.favourites_count = result["favourites_count"] self.statuses_count = result["statuses_count"] self.created_at = result["created_at"] self.geo_enabled = result["geo_enabled"] self.lang = result["lang"] self.profile_background_color = result["profile_background_color"] self.profile_background_image_url = result["profile_background_image_url"] self.profile_image_url = result["profile_image_url"] self.profile_link_color = result["profile_link_color"] self.profile_text_color = result["profile_text_color"]
def __init__(self, community): Node.__init__(self, community['id'], community['name'], "community") if 'about' in community: self.about = community['about'] else: self.about = None if 'description' in community: self.description = community['description'] else: self.description = None if 'category' in community: self.category = community['category'] else: self.category = None if 'website' in community: self.website = community['website'] else: self.website = None
def __init__(self, user): Node.__init__(self, user['id'], user['name'], "user") self.name = user['name'] if 'email' in user: self.email = user['email'] else: self.email = None if 'gender' in user: self.gender = user['gender'] else: self.gender = None if 'birthday' in user: self.birthday = user['birthday'] else: self.birthday = None if 'hometown' in user: self.hometown = user['hometown']['name'] else: self.hometown = None
def __init__(self, redditor): Node.__init__(self, redditor["id"], redditor["name"], "redditor") for key in redditor: if key == "id": continue setattr(self, key, str(redditor[key]))
def __init__( self, post ): # print(post) Node.__init__(self, str(post['id']), str(post['id']), "post") self.type = post['type'] # Any one from text, photo, quote, link, chat, video, answer self.blog_name = post['blog_name'] self.post_url = post['post_url'] self.slug = post['slug'] # Short text summary to the end of the post URL self.date = post['date'] # The GMT date and time of the post, as a string self.timestamp = post['timestamp'] # The time of the post, in seconds since the epoch self.state = post['state'] # Indicates the current state of the post self.format = post['format'] # String The post format: html or markdown self.reblog_key = post["reblog_key"] # The key used to reblog this post self.tags = post['tags'] # Array(string) Tags applied to the post self.short_url = post['short_url'] self.summary = post['summary'] self.is_blocks_post_format = post['is_blocks_post_format'] self.recommended_source = post['recommended_source'] self.recommended_color = post['recommended_color'] self.followed = post['followed'] self.liked = post['liked'] self.note_count = post['note_count'] self.can_like = post['can_like'] self.can_reblog = post['can_reblog'] self.can_send_in_message = post['can_send_in_message'] self.can_reply = post['can_reply'] self.display_avatar = post['display_avatar'] try: if "text" in self.type: self.title = post['title'] self.body = post['body'] self.trail = post['trail'] self.reblog = post['reblog'] elif "photo" in self.type: self.caption = post['caption'] self.photos = post['photos'] self.trail = post['trail'] self.reblog = post['reblog'] elif "quote" in self.type: self.text = post['text'] self.source = post['source'] self.reblog = post['reblog'] elif "link" in self.type: self.title = post['title'] self.url = post['url'] self.link_author = post['link_author'] self.excerpt = post['excerpt'] self.publisher = post['publisher'] self.description = post['description'] self.trail = post['trail'] self.reblog = post['reblog'] elif "chat" in self.type: self.title = post['title'] self.body = post['body'] self.dialogue = post['dialogue'] elif "audio" in self.type: self.id3_title = post['id3_title'] self.caption = post['caption'] self.embed = post['embed'] self.plays = post['plays'] self.trail = post['trail'] self.reblog = post['reblog'] elif "video" in self.type: self.caption = post['caption'] if 'permalink_url' in post: self.permalink_url = post['permalink_url'] if 'video_url' in post: self.video_url = post['video_url'] self.html5_capable = post['html5_capable'] self.thumbnail_url = post['thumbnail_url'] self.thumbnail_width = post['thumbnail_width'] self.thumbnail_height = post['thumbnail_height'] if 'duration' in post: self.duration = post['duration'] self.video_type = post['video_type'] self.player = post['player'] self.trail = post['trail'] self.reblog = post['reblog'] elif "answer" in self.type: self.asking_name = post['asking_name'] self.asking_url = post['asking_name'] self.question = post['question'] self.answer = post['answer'] self.trail = post['trail'] self.reblog = post['reblog'] except KeyError as error: print(error) print(post)
def convert_graph(self, old_graph, _type, credentials=None): old_type = old_graph.graph_type() if old_type == _type: return old_graph if _type == "dictionary": new_graph = DictGraph() elif _type == "pandas": new_graph = PandasGraph() elif _type == "neo4j": if credentials is None: return old_graph new_graph = NeoGraph(credentials) else: return None old_nodes = old_graph.get_nodes() old_edges = old_graph.get_edges() if old_type == "dictionary": for key in old_nodes: for node in old_nodes[key].values(): new_graph.create_node(node) for key in old_edges: for edge in old_edges[key].values(): new_graph.create_edge(edge) elif old_type == "pandas": for df in old_nodes.values(): header = list(df.columns) for node in df.iterrows(): data = node[1] node = BaseNode(data["Id"], data["Label"], data["label_attribute"]) for attr in header: setattr(node, attr, data[attr]) new_graph.create_node(node) for df in old_edges.values(): header = list(df.columns) for edge in df.iterrows(): data = edge[1] edge = BaseEdge(data["Source"], data["Target"], data["Label"]) for attr in header: setattr(edge, attr, data[attr]) new_graph.create_edge(edge) elif old_type == "neo4j": for node in old_nodes: data = node["n"] node = BaseNode(data["Id"], data["Label"], data["label_attribute"]) for attr in data.keys(): setattr(node, attr, data[attr]) new_graph.create_node(node) for edge in old_edges: data = edge["r"] edge = BaseEdge(data["Source"], data["Target"], data["label_attribute"]) for attr in data.keys(): setattr(edge, attr, data[attr]) new_graph.create_edge(edge) else: return None return new_graph