def addMessage(self, nick, network_name, channel_name, message): user = self.addUser(nick) network = self.addNetwork(network_name) channel = self.addChannel(channel_name) message = Message(user, network, channel, message) db.add(message) if not self.commit(): raise ModelException("Problem committing message to %s by %s \n\t %s" % (network, user, message)) print "Committing add of %s" % message return user
def addUser(self, nick): user = User.query.filter(User.nick == nick).first() if user is not None: return user user = User(nick) db.add(user) if not self.commit(): raise ModelException("Problem committing user with nick " + nick) print "Committing add of %s" % nick return user
def addChannel(self, name): channel = Channel.query.filter(Channel.name == name).first() if channel is not None: return channel channel = Channel(name) db.add(channel) if not self.commit(): raise ModelException("Problem committing channel " + name) print "Committing add of %s" % name return channel
def addNetwork(self, network_name): network = Network.query.filter(Network.name == network_name).first() if network is not None: return network network = Network(network_name) db.add(network) if not self.commit(): raise ModelException("Problem committing network " + network_name) print "Committing add of %s" % network_name return network
def addURL(self, message_id, url): message = Message.query.filter(Message.mid == int(message_id)).first() if message is None: print "Unable to find message with ID %d" % int(message_id) return None url = Url(message_id, url) db.add(url) if not self.commit(): raise ModelException("Problem committing url %s for message_id %s" % (url, message_id)) print "Committing add of %s" % url return url
def addBot(self, nick, network_name): if network_name is None or len(network_name.strip()) == 0: raise ModelException("Network required when adding a bot.") network = self.addNetwork(network_name) bot = Bot.query.filter(Bot.nick == nick).filter(Bot.network == network).first() if bot is not None: return bot bot = Bot(nick, network_name) db.add(bot) if not self.commit(): raise ModelException("Error during commit of Bot " + nick + " for network " + network_name) print "Committing add of %s to %s" % (nick, network_name) return bot
def addServer(self, network_name, address, port=None, SSL=False): server = Server.query.filter(Server.address == address).first() if server is not None: return server #Make sure the network exists self.addNetwork(network_name) if port is None or len(port.strip()) == 0: port = None else: port = int(port) server = Server(network_name, address, port, SSL) db.add(server) if self.commit(): #TODO work out how to print out the server here using the toString shit raise ModelException("Problem committing server " + str(server)) print "Committing add of %s to %s" % (address, network_name) return server