def __init__(self, parameters, out): self.known_users = {} if "q" in parameters: q = parameters["q"][0] self.terms = q.split(",") print "Request for retweets, query '%s'" % q else: self.terms = None print "Request for retweets, no query string" self.handler = GephiFileHandler(out)
class RequestProcessor(): def __init__(self, out): self.known_nodes = {} self.handler = GephiFileHandler(out) def process(self, event): etype = event['type'] source = event['source'] target = event['target'] default_node_attr = {'size':5, 'r':84./255., 'g':148./255., 'b':183./255.} if source not in self.known_nodes: self.known_nodes[source] = source attributes = default_node_attr.copy() attributes['label'] = source self.handler.add_node(source, **attributes) if target not in self.known_nodes: self.known_nodes[target] = target attributes = default_node_attr.copy() attributes['label'] = target self.handler.add_node(target, **attributes) eid = source + '_' + target if etype == 'ae': attributes = {'directed':True, 'weight':2.0} self.handler.add_edge(eid, source, target, **attributes) if etype == 'de': self.handler.delete_edge(eid)
def __init__(self, parameters, out): self.known_users = {} if "q" in parameters: q = parameters["q"][0] self.terms = q.split(",") print "Request for retweets, query '%s'"%q else: self.terms = None print "Request for retweets, no query string" self.handler = GephiFileHandler(out)
class RequestProcessor(): def __init__(self, parameters, out): self.known_users = {} if "q" in parameters: q = parameters["q"][0] self.terms = q.split(",") print "Request for retweets, query '%s'" % q else: self.terms = None print "Request for retweets, no query string" self.handler = GephiFileHandler(out) def process(self, status): messages = [] found = False if (self.terms): for term in self.terms: if re.search(term, status.text.lower()): found = True break if not found: return messages default_node_attr = { 'size': 5, 'r': 84. / 255., 'g': 148. / 255., 'b': 183. / 255. } if status.source not in self.known_users: self.known_users[status.source] = status.source attributes = default_node_attr.copy() attributes['label'] = status.source self.handler.add_node(status.source, **attributes) if status.target not in self.known_users: self.known_users[status.target] = status.target attributes = default_node_attr.copy() attributes['label'] = status.target self.handler.add_node(status.target, **attributes) attributes = { 'directed': True, 'weight': 2.0, 'date': str(status.date) } self.handler.add_edge(status.status_id, status.source, status.target, status.text, **attributes)
class RequestProcessor(): def __init__(self, parameters, out): self.known_users = {} if "q" in parameters: q = parameters["q"][0] self.terms = q.split(",") print "Request for retweets, query '%s'"%q else: self.terms = None print "Request for retweets, no query string" self.handler = GephiFileHandler(out) def process(self, status): messages = [] found = False if (self.terms): for term in self.terms: if re.search(term, status.text.lower()): found = True break if not found: return messages default_node_attr = {'size':5, 'r':84./255., 'g':148./255., 'b':183./255.} if status.source not in self.known_users: self.known_users[status.source] = status.source attributes = default_node_attr.copy() attributes['label'] = status.source self.handler.add_node(status.source, **attributes) if status.target not in self.known_users: self.known_users[status.target] = status.target attributes = default_node_attr.copy() attributes['label'] = status.target self.handler.add_node(status.target, **attributes) attributes = {'directed':True, 'weight':2.0, 'date':str(status.date)} self.handler.add_edge(status.status_id, status.source, status.target, **attributes)
def __init__(self, out): self.known_nodes = {} self.handler = GephiFileHandler(out)