def main(): maxtool = client.Client(private.key, private.secret) # models = [mail_bot.mail_bot('ethtwd', 56000), # mail_bot.mail_bot('maxtwd', 15.1), # price_track_mail_bot.pt_mail_bot(maxtool, 'maxtwd', {'percent':[[0.1, 0.2, 0.3], [0.1, 0.2, 0.3]]})] while (True): for m in models: mail_list = m.get_mail(maxtool) for mail in mail_list: if mail: for t in config.EMAIL: print(f"send email to {t}!!") helpers.send_mail(t, mail) # buyList = m.getBuy(maxtool) # for buy in buyList: # maxTool.buy(buy) # sellList = m.getSell(maxtool) # for sell in sellList: # maxTool.sell(sell) m.count_down(config.SLEEP) time.sleep(config.SLEEP)
def authenticate(self, username, password): cfg = configparser.ConfigParser() cfg.read(setting.ACCOUNT_PATH) if username in cfg.sections( ) and password == cfg[username]["password"]: self.user = client.Client(username, password, cfg[username]['home'], cfg[username]['homemaxsize']) return username
def startmqtt(): global topic, mqc mqc = mqtt.Client() mqc.on_message = msghandler mqc.on_connect = connecthandler mqc.on_disconnect = disconnecthandler if __addon__.getSetting("mqttanonymousconnection") == 'false': mqc.username_pw_set(__addon__.getSetting("mqttusername"), __addon__.getSetting("mqttpassword")) mqttlogging("MQTT: Anonymous disabled, connecting as user: %s" % __addon__.getSetting("mqttusername")) if __addon__.getSetting( "mqtttlsconnection") == 'true' and __addon__.getSetting( "mqtttlsconnectioncrt") != '' and __addon__.getSetting( "mqtttlsclient") == 'false': mqc.tls_set(__addon__.getSetting("mqtttlsconnectioncrt")) mqttlogging("MQTT: TLS enabled, connecting using CA certificate: %s" % __addon__.getSetting("mqtttlsconnectioncrt")) elif __addon__.getSetting( "mqtttlsconnection") == 'true' and __addon__.getSetting( "mqtttlsclient") == 'true' and __addon__.getSetting( "mqtttlsclientcrt") != '' and __addon__.getSetting( "mqtttlsclientkey") != '': mqc.tls_set(__addon__.getSetting("mqtttlsconnectioncrt"), __addon__.getSetting("mqtttlsclientcrt"), __addon__.getSetting("mqtttlsclientkey")) mqttlogging( "MQTT: TLS with client certificates enabled, connecting using certificates CA: %s, client %s and key: %s" % (__addon__.getSetting("mqttusername"), __addon__.getSetting("mqtttlsclientcrt"), __addon__.getSetting("mqtttlsclientkey"))) topic = __addon__.getSetting("mqtttopic") if not topic.endswith("/"): topic += "/" mqc.will_set(topic + "connected", 0, qos=2, retain=True) sleep = 2 for attempt in range(10): try: mqttlogging("MQTT: Connecting to MQTT broker at %s:%s" % (__addon__.getSetting("mqtthost"), __addon__.getSetting("mqttport"))) mqc.connect(__addon__.getSetting("mqtthost"), __addon__.getSetting("mqttport"), 60) except socket.error: mqttlogging("MQTT: Socket error raised, retry in %d seconds" % sleep) monitor.waitForAbort(sleep) sleep = sleep * 2 else: break else: mqttlogging("MQTT: No connection possible, giving up") return (False) mqc.publish(topic + "connected", 2, qos=1, retain=True) mqc.loop_start() return (True)
def __init__(self): self.api = client.Client(private.key, private.secret) self.cur_price = None # lowest price in 7, 14, 30 days self.histroy_price = [0.0, 0.0, 0.0] self.mail_queue = [] # get price information self.get_history_price() self.get_cur_price()
def restart(self, args=None): self.sysMsg(self.lang['restarting']) if not args == None and args[0] != self.port: self.port = int(args[0]) if self.chatClient.isConnected: self.chatClient.send("\b/quit") time.sleep(0.2) self.chatClient.stop() self.chatServer.stop() self.chatClient = client.Client(self) self.chatClient.start() self.chatServer = server.Server(self) self.chatServer.daemon = True self.chatServer.start()
def __init(host: str, port: int = 4800) -> None: global __client, CMDS if misc.unix(): readline.parse_and_bind('tab: complete') readline.set_completer(__cmd_compl) else: misc.print_wrn( 'Consider using a UNIX-based OS for tab-completion ... ') try: __client = client.Client(host, port) for k, v in CMDS.items(): CMDS[k] = v(__client) except Exception as e: misc.print_err(str(e)) os._exit(1)
def main(argv): del argv repo, tag = "", "" if FLAGS.image: repo, tag = utils.parse(FLAGS.image) i = image.Image(repo, tag) c = client.Client() # c.tar(i) c.auth(i) c.pull(i) print("image name [{}]".format(i.string())) if FLAGS.pull: exit() if FLAGS.tag: c.tar(i) exit() # if FLAGS.cli: # exit() print("update successfully")
else: logger.setLevel(logging.WARN) logger.info("config.ini file read successfully") State_Machine += 1 except Exception, e: logger.exception( "******************* Error reading config.ini file (will use defaults): " + repr(e)) State_Machine = 1 attempts = 3 # -------------- MQTT ---------------- elif State_Machine == 1: try: logger.info("Attempting connection to MQTT Broker: " + MQTT_IP + ":" + str(MQTT_Port)) client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message if MQTT_Username is not None: client.username_pw_set(username=MQTT_Username, password=MQTT_Password) client.connect(MQTT_IP, MQTT_Port, MQTT_KeepAlive) client.loop_start() client.subscribe(Topic_Subscribe_Control + "#") logger.info("MQTT client subscribed to control messages on topic: " + Topic_Subscribe_Control + "#") client.publish(Topic_Publish_AppState,"State Machine 1, Connected to MQTT Broker",0,True)
import lib.alarm as alarm import lib.client as client import lib.peripherals as peripherals import lib.SoftwareTimer as SoftwareTimer import time REFRESH_RATE = 5 myClock = alarm.AlarmClock() client = client.Client() while not client.connect("192.168.2.3", 12345): time.sleep(REFRESH_RATE) refreshTimer = SoftwareTimer.OneShotTimer(REFRESH_RATE) refreshTimer.start() c = 0 while(True): ## check alarm ## myClock.checkAlarm() if refreshTimer.expired(): c = c + 1 refreshTimer.start() if client.refreshConnect(): ## CHECK FOR MSG ## cmd = client.receiveCmd() if cmd != '': print(cmd) if cmd[0] == "UPDATE_TIME":
def test_login(self): print("start login") c = client.Client() c.connect(env.get("login", "server"), int(env.get("login", "port"))) sl = c.call("get_server_list", {"platform": 1}) print(sl)
def onStart(self): # Try to find settings.json file and load its contents. # Change language according to settings.json # If settings.json is missing, load en.json try: jsonSettings = open('settings.json') self.settings = json.loads(jsonSettings.read()) jsonSettings.close() jsonFile = open('lang/{0}.json'.format(self.settings['language'])) except Exception: jsonFile = open('lang/en.json') self.lang = json.loads(jsonFile.read()) jsonFile.close() if os.name == "nt": os.system( "title P2P-Chat by flowei") # Set window title on windows self.ChatForm = self.addForm( 'MAIN', ChatForm, name='Peer-2-Peer Chat' ) # Add ChatForm as the main form of npyscreen #Get this PCs public IP and catch errors s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: s.connect(("8.8.8.8", 80)) self.hostname = s.getsockname()[0] s.close() except socket.error as error: self.sysMsg(self.lang['noInternetAccess']) self.sysMsg(self.lang['failedFetchPublicIP']) self.hostname = "0.0.0.0" #Define initial variables self.port = 3333 # Port the server runs on self.nickname = "" # Empty variable to be filled with users nickname self.peer = "" # Peer nickname self.peerIP = "0" # IP of peer self.peerPort = "0" # Port of peer self.historyLog = [] # Array for message log self.messageLog = [] # Array for chat log self.historyPos = 0 # Int for current position in message history # Start Server and Client threads self.chatServer = server.Server(self) self.chatServer.daemon = True self.chatServer.start() self.chatClient = client.Client(self) self.chatClient.start() # Dictionary for commands. Includes funtion to call and number of needed arguments self.commandDict = { "connect": [self.chatClient.conn, 2], "disconnect": [self.restart, 0], "nickname": [self.setNickname, 1], "quit": [self.exitApp, 0], "port": [self.restart, 1], "connectback": [self.connectBack, 0], "clear": [self.clearChat, 0], "eval": [self.evalCode, -1], "status": [self.getStatus, 0], "log": [self.logChat, 0], "help": [self.commandHelp, 0], "flowei": [self.flowei, 0], "lang": [self.changeLang, 1] } # Dictionary for command aliases self.commandAliasDict = { "nick": "nickname", "conn": "connect", "q": "quit", "connback": "connectback" }