def do_reserve(): if request.post_vars: opengnsys = Ognsys(db) if opengnsys.set_apikey(request.post_vars.ou_id): my_context = Storage(**request.post_vars) my_context['db'] = db my_context['user_id'] = auth.user_id my_context['num_retries'] = 0 connection = Connection(my_context) reserve = connection.do_reserve() logger.log(auth.user.first_name, auth.user.last_name, reserve['equipo_reservado']['name'], reserve['equipo_reservado']['ip'], "do_reserve") return json.dumps(reserve) else: return json.dumps({ 'error', 'Error de inicialización, compruebe configuración opengnsys' }) else: return json.dumps({'error', 'Error haciendo reserva status'})
def run(self): self.bot = Connection() self.bot.main() while True: buffer_msg = self.bot.irc_buffer_msg() self.analyzeText(buffer_msg) print(buffer_msg)
def addConnection(self, connection_repr): # Find BlockRepr ids for all starts and ends start = self.anchors[connection_repr.Start] end = self.anchors[connection_repr.End] item = Connection(connection_repr, start, end, self.styles) item.setFlag(QtGui.QGraphicsItem.ItemIsSelectable) item.applyStyle() self.addItem(item) self.anchors[connection_repr.Id] = item self.connections[connection_repr.Id] = connection_repr self.connection_items[connection_repr.Id] = item
def get_conn(): rnd = str(random.randint(0, 1000000)) params = request.json dic[rnd] = Connection(hostname=params['hostname'], username=params['username'], password=params['password']) return rnd
def check_pc_status(): print('check_status') if request.post_vars: opengnsys = Ognsys(db) if opengnsys.set_apikey(request.post_vars.ou_id): my_context = Storage(**request.post_vars) my_context['db'] = db connection = Connection(my_context) pc_status_info = connection.check_pc_status() if 'error' in pc_status_info: print('unreserve') client = Client(my_context) client.unreserve_remote_pc() logger.log(auth.user.first_name, auth.user.last_name, request.post_vars.name, request.post_vars.ip, "reserve_error") # Key db raise error in json.load if 'equipo_reservado' in pc_status_info: if 'db' in pc_status_info['equipo_reservado']: pc_status_info['equipo_reservado']['db'] = None return json.dumps(pc_status_info) else: return json.dumps({ 'error', 'Error de inicialización, compruebe configuración opengnsys' }) else: return json.dumps({'error', 'Error chequeando status'})
def __connection(self, url, proxy=None): if proxy is not None: return Connection(url, proxy) return Connection(url)
class Bot(): #connection object bot = "" #User info users = {} #local user to whom bot sents the message luser = "" #xada work kolist words = [ "mugi", "mug", "muji", "randy", "randi", "radi ", "f**k", "chikney", "rando", "kera ", "machis", "lado", "puti", "muj ", 'chik ', "lundo", "asshole", "bitch", "bhalu", "myachis", "myach" ] # No of chance to give if words is spoken chance = 4 # Message when user type !f**k fuckMessage = "You ass hole, Mother F****r" # Just a function, it will be implemented as plugins later on def send_date(self, msg): date = nepali_date.get_nepali_date() self.sendMsg(date) def send_weather(self, msg): if len(msg) == 2: condition = weather.get_weather(msg[1]) self.sendMsg(condition) else: self.sendMsg("Enter the city as !weather Kathmandu") def send_email(self, msg, message): if len(msg) >= 3: message = ' '.join(msg[2:]) data = emailsender.sentEmail(msg[1], message) if data == 1: self.sendMsg("Sent Successfully") else: self.sendMsg("Error in sending") else: self.sendMsg("Enter message as !email [emai-address] [message]") def send_jokes(self, msg): random = randint(0, 8) print(random) if len(msg) == 2: joke = jokes.get_jokes(msg[1], random + 1) self.sendMsg(joke[random]) else: joke = jokes.get_jokes(rand=random + 1) print(joke[random]) self.sendMsg(joke[random]) def change_bot_name(self, msg): if len(msg) == 2: self.bot.irc_send("NICK {}".format(msg[1])) else: self.sendMsg("Enter name of bot properly") def change_fuck_message(self, msg): if len(msg) >= 2: message = ' '.join(msg[1:]) self.fuckMessage = message else: self.sendMsg("Enter the message as !fuckmsg [MESSAGE]") def bot_reply(self, message): print(self.luser) msg = message.split(' ') print(message) # the message starts with ! marks then it is command if message[0] == "!": # Just for fun [will be removed] if msg[0] == "!f**k": self.sendMsg(self.fuckMessage) # Provides the date elif msg[0] == "!date": date = threading.Thread(target=self.send_date, args=(msg, )) date.start() # Sends the weather info to user elif msg[0] == "!weather": weather = threading.Thread(target=self.send_weather, args=(msg, )) weather.start() elif msg[0] == "!email": email = threading.Thread(target=self.send_email, args=(msg, message)) email.start() elif msg[0] == "!jokes": jokes = threading.Thread(target=self.send_jokes, args=(msg, )) jokes.start() # Change bot name through admin elif self.luser == self.bot.getadmin() and msg[0] == "!botnick": change_name = threading.Thread(target=self.change_bot_name, args=(msg, )) change_name.start() # Change f**k message elif self.luser == self.bot.getadmin() and msg[0] == "!fuckmsg": fuck_msg = threading.Thread(target=self.change_fuck_message, args=(msg, )) fuck_msg.start() # Provides help to the user elif msg[0] == "!help": self.sendMsg( " Currently available commads are !date, !weather location, !f**k, !jokes /tag/, !email [address] [message] -[Admin Only]- : !fuckmsg [MSG] !botnick [NAME] kill bot" ) self.bot.irc_send("NAMES {}".format(self.bot.getchannel())) # Exit the bots elif self.luser == self.bot.getadmin() and message == "kill bot": print(self.luser) self.bot.irc_send("QUIT") else: self.sendMsg("Unknown command: Type !help for more info") else: check_kick = threading.Thread(target=self.testKick, args=(message, )) check_kick.start() def analyzeText(self, msg): # Respond ping message if msg.find("PING :") != -1: ping_value = msg.split(":")[1] self.bot.irc_send("PONG :{}".format(ping_value)) if msg.find("PRIVMSG {}".format(self.bot.getchannel())) != -1: self.luser = msg.split('!')[0][1:] message = msg.split('PRIVMSG', 1)[1].split(':', 1)[1] self.bot_reply(message) # Kick user if the speak rude words # Function determines whether to kick the guy or not def testKick(self, msg): tempUser = self.luser if any(word in msg.lower() for word in self.words): if tempUser in self.users: self.users[tempUser] += 1 if self.users[tempUser] == self.chance: self.bot.irc_send("PRIVMSG chanserv :op {}".format( self.bot.getchannel())) time.sleep(2) self.bot.irc_send("KICK {} {}".format( self.bot.getchannel(), tempUser)) time.sleep(1) self.bot.irc_send("PRIVMSG chanserv :deop {}".format( self.bot.getchannel())) self.users.pop(tempUser) return self.sendMsg( "You have {} chances".format(self.chance - self.users[tempUser])) else: self.users[tempUser] = 0 # This functions sent the message to user directly def sendMsg(self, msg): self.bot.irc_send_priv("{} {}".format(self.luser, msg)) def run(self): self.bot = Connection() self.bot.main() while True: buffer_msg = self.bot.irc_buffer_msg() self.analyzeText(buffer_msg) print(buffer_msg)
#! /home/pi/.local/bin/python3.7 from connector import Connection import pathlib import os import json if __name__ == "__main__": confpath = os.path.join(str(pathlib.Path.home()),".hwk/config.json") with open(confpath, "r") as fp: config = json.load(fp) router_ip, port = config["router"], config["port"] config["ip"] = Connection(router_ip, port).result with open(confpath, "w") as fp: json.dump(config, fp, indent=4) import LineDisplay import display import sys import functools if sys.argv[1] == "display0": display.main(LineDisplay.CookLineProtocol, 3) elif sys.argv[1] == "display1": client = functools.partial(LineDisplay.DrinkLineProtocol, exclude=["Bottled", "Pie", "Cake"]) display.main(LineDisplay.DrinkLineProtocol, 2)
from connector import Connection x = Connection() print(x.get_file_structure('~'))