Changeset 3:48f51eae9e71 in misc
- Timestamp:
- 02/10/07 06:35:43 (5 years ago)
- Branch:
- misc
- Convert:
- svn:e60e002c-0983-44b9-b2ae-8842d539f768/misc@6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
swirc.py
r2 r3 29 29 30 30 import sys 31 import pydot 31 32 from twisted.words.protocols import irc 32 33 from twisted.internet import reactor, protocol … … 43 44 44 45 def addNode(self, node, reachable): 45 print node, reachable46 46 try: 47 47 self.data[node] … … 49 49 self.data[node] = reachable 50 50 else: 51 self.data[node] += reachable 51 for e in reachable: 52 if e not in self.data[node]: 53 self.data[node] += reachable 52 54 53 55 class MakeGraph(object): … … 56 58 self.graph = Graph() 57 59 58 def fromList(self, params): 59 ''' ['swircbot', '=', '#etna', 'swircbot @mancausoft 60 @Eriol @KatolaZ @substa @AlpT_ '] ''' 61 62 nickslist = [] 63 for nick in params[3].split(): 64 if nick == BOT_NICKNAME: 65 continue 66 if nick[0] in '@+': 67 nick = nick[1:] 68 69 nickslist.append(nick) 60 def addNick(self, nickslist): 70 61 71 62 for nick in nickslist: … … 73 64 [node for node in nickslist if node != nick]) 74 65 75 def toPicture(self):76 import pydot77 edges = [(nick, x) for nick in self.graph.datafor x in self.graph.data[nick]]66 def _cleanEdges(self): 67 edges = [(nick, x) for nick in self.graph.data 68 for x in self.graph.data[nick]] 78 69 79 bon = edges[:]70 cleanedEdges = list(edges) 80 71 81 72 for x in edges: 82 if (x[1], x[0]) in bon:83 del bon[bon.index(x)]73 if (x[1], x[0]) in cleanedEdges: 74 del cleanedEdges[cleanedEdges.index(x)] 84 75 85 gr = pydot.graph_from_edges(bon) 86 gr.write_jpeg('swirc.jpg', prog='dot') 76 return cleanedEdges 87 77 88 mgi = MakeGraph() #ugly hack to make the picture of the graph after CTRL + C 78 def saveDot(self, fname): 79 gr = pydot.graph_from_edges(self._cleanEdges()) 80 gr.write_dot(fname, prog='dot') 81 82 mgi = MakeGraph() #ugly hack to make the dot file of the graph after CTRL + C 89 83 90 84 class SwircBot(irc.IRCClient): … … 93 87 94 88 knownchannels = [] 89 knownnicks = [] 95 90 maxdepth = 10 96 91 … … 108 103 SwircBot.knownchannels.append(channel) 109 104 105 def irc_RPL_ENDOFWHOIS(self, prefix, params): 106 nick = params[1] 107 SwircBot.knownnicks.append(nick) 108 110 109 def irc_RPL_WHOISCHANNELS(self, prefix, params): 111 110 for channel in params[2].split(): … … 116 115 len(SwircBot.knownchannels) < SwircBot.maxdepth): 117 116 self.join(channel[1:]) 117 #print channel 118 #print SwircBot.knownchannels 119 118 120 119 121 def irc_RPL_NAMREPLY(self, prefix, params): 120 self.graphmaker.fromList(params) 122 ''' ['swirc', '=', '#etna', 'swirc @Eriol @AlpT @mancausoft @markgreene '] ''' 123 nickslist = [] 124 for nick in params[3].split(): 125 if nick == BOT_NICKNAME: 126 continue 127 if nick[0] in '@+': 128 nick = nick[1:] 121 129 122 #print self.graphmaker.graph.data130 nickslist.append(nick) 123 131 124 for nick in self.graphmaker.graph.data: 125 self.sendLine("WHOIS %s" % nick) 132 self.graphmaker.addNick(nickslist) 133 134 for nick in nickslist: 135 if nick not in SwircBot.knownnicks: 136 self.sendLine("WHOIS %s" % nick) 126 137 127 138 class SwircBotFactory(protocol.ClientFactory): … … 147 158 reactor.run() 148 159 149 mgi. toPicture()160 mgi.saveDot('swirc.dot')
Note: See TracChangeset
for help on using the changeset viewer.
