def main(): processor = EventProcessor() board = Wiiboard(processor, disabled = False) ## Communicate via UART - debugging with serial.Serial( port = '/dev/ttyUSB0', baudrate = 19200, parity = serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=None) as ser: r_t = threading.Thread(target = read_cmd, args=(ser,)) r_t.daemon = True r_t.start() print 'connect with pic now!' pic = PICInterface() pic.write_ip(get_ip('wlan0')) print 'connect to wii board!' board.connect() if board.isConnected(): board.async_receive() while True: if pic.connected: t_x, t_y = processor.t_x, processor.t_y # tilt angles t_x, t_y = -t_y, t_x # this is flipped due to servo position #s_x, s_y = tilt2servo(t_x, rad=False), tilt2servo(t_y, rad=False) # servo angles s_x, s_y = 6 * t_x, 6 * t_y # 15 -> 90 wii = board.isConnected() if not (pic.write_x(s_x) and pic.write_y(s_y) and pic.write_wii(wii)): pic.connected = False if not wii: # try to connect to wii again board.connect() # try connecting again if board.isConnected(): board.setLight(False) board.wait(500) board.setLight(True) board.async_receive() else: print 'pic not connected' pic.connect() pic.write_ip(get_ip('wlan0')) time.sleep(0.05) pic.close()
def main(): while 1: current_ip = get_ip() if current_ip: # 对于拥有多个出口 IP 负载均衡的服务器,上面的 get_ip() 函数会在几个 ip 之间不停切换 # 然后频繁进入这个判断,进行 update_record(),然后很快就会触发 API Limited 了 # 于是建立一个IP池记载这个服务器的几个出口IP,以免频繁切换 ip_count = int(cfg['ip_count']) ip_pool = cfg['ip_pool'].split(',')[:ip_count] cfg['current_ip'] = current_ip if current_ip not in ip_pool: # new ip found logging.info("new ip found: %s", current_ip) ip_pool.insert(0, current_ip) cfg['ip_pool'] = ','.join([str(x) for x in ip_pool[:ip_count]]) try: update_record() save_config() except Exception as e: logging.warning('update_recoud or save_config failed: %s', str(e)) else: logging.error('get current ip FAILED.') try: interval = int(cfg['interval']) except ValueError: interval = 5 # await asyncio.sleep(interval) time.sleep(interval)
def main(): while 1: if not need_check_ip(): try: interval = int(cfg['check_interval']) except ValueError: interval = 1 time.sleep(interval) continue current_ip = get_ip() if current_ip: # 对于拥有多个出口 IP 负载均衡的服务器,上面的 get_ip() 函数会在几个 ip 之间不停切换 # 然后频繁进入这个判断,进行 update_record(),然后很快就会触发 API Limited 了 # 于是建立一个IP池记载这个服务器的几个出口IP,以免频繁切换 ip_count = int(cfg['ip_count']) ip_pool = cfg['ip_pool'].split(',')[:ip_count] cfg['current_ip'] = current_ip if current_ip not in ip_pool: # new ip found logging.info("new ip found: %s", current_ip) ip_pool.insert(0, current_ip) cfg['ip_pool'] = ','.join([str(x) for x in ip_pool[:ip_count]]) update_record() else: logging.error('get current ip FAILED.') try: interval = int(cfg['interval']) except ValueError: interval = 5 time.sleep(interval)
def main(): login_token = os.getenv('LOGIN_TOKEN') domain = os.getenv('DOMAIN') sub_domain = os.getenv('SUB_DOMAIN') print("Updating Domain: %s.%s at %s" % (sub_domain, domain, datetime.datetime.now().isoformat())) current_ip = get_ip() print("Host Ip: %s" % current_ip) api = apicn.DomainInfo(domain_id='', domain=domain, login_token=login_token) domain_id = api().get("domain", {}).get("id") api = apicn.RecordList(domain_id, sub_domain=sub_domain, record_type='A', login_token=login_token) record = api().get('records')[0] record_ip = record.get('value') record_id = record.get('id') record_line = record.get('line') print("Last Ip: %s" % record_ip) if current_ip != record_ip: api = apicn.RecordDdns(record_id, sub_domain, record_line, domain_id=domain_id, value=current_ip, login_token=login_token) ret = api() new_ip = ret.get('record').get('value') print('Updated: %s at %s' % (new_ip, datetime.datetime.now().isoformat())) else: print('Last IP is the same as current IP!')
def check_network_machines(db): ip = get_ip() services = load_services() all_services = check_local_services(db) ip = ip.split('.') for i in range(1,256): if i == int(ip[-1]): continue try: r = requests.get('http://'+ip[0]+'.'+ip[1]+'.'+ip[2]+'.'+str(i)+':2357/services') if r.status_code == 200: new_services = json.loads(r.text) for i in new_services: if i in all_services: for j in new_services[i]: all_services[i].append(j) else: all_services[i] = [] for j in new_services[i]: all_services[i].append(j) except: continue with open('all_available_services.json', 'w') as json_file: json.dump(all_services, json_file) return all_services
def main(): ip = get_ip.get_ip() bus = smbus.SMBus(bus_nr) i2c_display.init_display(bus, address) i2c_display.display_write_string(bus, address, 0, ip) content = "Hallo Martin" i2c_display.display_write_string(bus, address, 1, content) return
def test_example(): ips = set(get_ip('11211')) assert ips == set([ '1.1.2.11', '1.1.21.1', '1.12.1.1', '11.2.1.1', ])
def main(security_token_file=SECURITY_TOKEN_FILE, interval=INTERVAL): # Creating logger logger = logging.getLogger('twitter-bot-logger') logger.setLevel(logging.DEBUG) # Creating file handler filehandler = logging.FileHandler(LOGFILE) filehandler.setLevel(logging.DEBUG) # Create a formatter (ToDo: Add new style formatter) formatted=logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') filehandler.setFormatter(formatted) # Add handler to logger logger.addHandler(filehandler) # Main Code tokens=lt.load_tokens(security_token_file) logger.debug('Tokens loaded') bot=twitter_bot.create_bot( ( tokens['OAUTH_TOKEN'], tokens['OAUTH_SECRET'], tokens['CONSUMER_KEY'], tokens['CONSUMER_SECRET'] ) ) logger.debug('Bot created') last_ip='' while True: current_ip=get_ip.get_ip() logger.debug('Current ip obtained. IP is {0}'.format(current_ip)) if not current_ip==last_ip: logger.debug('Posting ip to twitter.') last_ip=current_ip scrambled=scrambler.scramble(current_ip) # This part posts the ip on twitter. I have disabled it in favour of sending # direct messages # twitter_bot.post_status(bot,scrambled) logger.debug('Sending dm to {}'.format(RECIPIENT)) logger.debug(scrambled) twitter_bot.message_user(bot,RECIPIENT, scrambled) else: logger.debug('IP not changed.') logger.debug('Current ip is {}'.format(current_ip)) logger.debug('Last ip was {}'.format(last_ip)) logger.debug('Sleeping for {} seconds'.format(INTERVAL)) time.sleep(INTERVAL)
def main(): ip = get_ip.get_ip() bus = smbus.SMBus(bus_nr) i2c_display.init_display(bus, displ_addr) i2c_display.display_write_string(bus, displ_addr, 0, ip) temp = temperature.get_temperature(bus, temp_addr) line2 = "T: " + str(temp) + "C" i2c_display.display_write_string(bus, displ_addr, 1, line2) return
def get_ip_hook(user, command, args, msg): # print '>>> get_ip_hook' # print 'user:'******'command:', command # print 'args:', args # print 'msg:', msg for i in WHITE_LIST_USERS: if str(user).find(i) != -1: return str(get_ip()).strip()
def get_ip_hook(user, command, args, msg): # print '>>> get_ip_hook' # print 'user:'******'command:', command # print 'args:', args # print 'msg:', msg for i in WHITE_LIST_USERS: if str(user).find(i) != -1: return "IP of bot: %s" % (str(get_ip()).strip()) return "COMMAND ERROR", 'User "%s" is not authortied to cmd "%s"' % (user, command)
def main(): print "Initiating finding host..." my_ip = get_ip() # Retrieve the ip of the current working interface... print("ip obtained..." + my_ip) ip = my_ip #subnetter take an ip address in format "192.168.43.236" and return the form #"192.168.43." removing the last part subnet = subnetter(ip) print("subnetted..." + subnet) hosts = discover(subnet) print hosts
def get_list(base_url, ): try: ip = get_ip() proxi = { 'http': 'http://' + ip + "'", } print("当前ip---" + str(ip)) end_time = time.time() time1 = end_time - start_time time1 = math.trunc(time1) print("用时:" + str(time1) + 's') video_list = [] m = requests.get(base_url, headers=get_user_agent(), proxies=proxi) m = json.loads(m.text) for i in m['data']['Related']: video_list.append(i['aid']) for i in video_list: #遍历推荐视频 if i in list1: continue else: ip = get_ip() proxi = { 'http': 'http://' + ip + "'", } m = requests.get( 'https://api.bilibili.com/x/web-interface/view/detail?bvid=&aid=' + str(i) + '&jsonp=jsonp', headers=get_user_agent(), proxies=proxi) m = json.loads(m.text) w1 = m['data']['View']['title'] w2 = m['data']['View']['stat']['view'] list1.append(i) f.writelines(str(i) + ',' + str(w2) + "," + w1 + '\n') time.sleep(0.2) print(len(list1)) get_list( 'https://api.bilibili.com/x/web-interface/view/detail?bvid=&aid=%s&jsonp=jsonp' % list1[-1], ) #递归调用 except Exception as error: print(error)
def debug(): if 'username' in session: user = escape(session['username']) else: user = None return render_template('server_up.html', title='Debug', content='Server is Up!', paragraph='The Server is Up and running (' + get_ip() + ')', user=user, services=get_services(), header_title='Prime Networks Server')
def connect(ovpn_path, wait_connect_time, ip_maintain_time): while True: try: original_ip = get_ip.get_ip() if (original_ip != '0.0.0.0'): break except: continue for folder in os.listdir(ovpn_path): cmd = '''osascript -e "tell application \\"Tunnelblick\\"" -e "connect \\"''' + folder[ 0:-5] + '''\\"" -e "end tell" > /dev/null''' os.system(cmd) connection_time = 0 while True: time.sleep(3) connection_time += 3 if (connection_time >= wait_connect_time): break try: new_ip = get_ip.get_ip() if (new_ip != '0.0.0.0') and (new_ip != original_ip): break except KeyboardInterrupt: raise except: continue if original_ip != new_ip: print(new_ip) time.sleep(ip_maintain_time) cmd = '''osascript -e "tell application \\"Tunnelblick\\"" -e "disconnect all" -e "end tell" > /dev/null''' os.system(cmd) time.sleep(3) cmd = 'killall Tunnelblick' os.system(cmd) time.sleep(2)
def scramble(ip_address=None, only_timestamp=True): """ Scrambles the ip address. If no argument is given the ip_address is determined on its own. """ if not ip_address: ip_address=ip.get_ip() now=datetime.datetime.now() timestamp=", {3}:{4}:{5}, {0}/{1}/{2}.".format(now.day, now.month, now.year, str(now.hour).zfill(2), str(now.minute).zfill(2), str(now.second).zfill(2)) scrambled_text="{0} years a slave. {1} hours. {2} days of misery. Core temperature {3} degree celsius.".format(*ip_address.split('.')) if not only_timestamp: return scrambled_text+timestamp else: return ip_address+timestamp
def check_local_services(db): ip = get_ip() services = load_services() r = None #PNCmdr available_services['PNCmdr'] = [str('http://'+ip+':'+services['PNCmdr'][2])] #Emby try: r = None r = requests.get(str('http://'+ip+':'+services['emby'][2])).text except: pass if not r is None and r.find('emby'): # return 'user Registered' available_services['emby'] = [str('http://'+ip+':'+services['emby'][2])] #Temp Monitor api try: r = None r = requests.get(str('http://'+ip+':'+services['temp_monitor_api'][2])).text except: pass if not r is None and not r.find('temp_monitor_api') == -1 : available_services['temp_monitor_api'] = [str('http://'+ip+':'+services['temp_monitor_api'][2])] #Temp Monitor webui try: r = None r = requests.get(str('http://'+ip+':'+services['temp_monitor'][2])).text except: pass if not r is None and r.find('temp_monitor') : available_services['temp_monitor'] = [str('http://'+ip+':'+services['temp_monitor'][2])] with open('available_services.json', 'w') as json_file: json.dump(available_services, json_file) return available_services
def scramble(ip_address=None, only_timestamp=True): """ Scrambles the ip address. If no argument is given the ip_address is determined on its own. """ if not ip_address: ip_address = ip.get_ip() now = datetime.datetime.now() timestamp = ", {3}:{4}:{5}, {0}/{1}/{2}.".format(now.day, now.month, now.year, str(now.hour).zfill(2), str(now.minute).zfill(2), str(now.second).zfill(2)) scrambled_text = "{0} years a slave. {1} hours. {2} days of misery. Core temperature {3} degree celsius.".format( *ip_address.split('.')) if not only_timestamp: return scrambled_text + timestamp else: return ip_address + timestamp
def main(): running = True def handler(signum, frame): logging.info("killed") nonlocal running running = False signal.signal(signal.SIGTERM, handler) try: interval = int(cfg['interval']) except ValueError: interval = 5 while running: current_ip = get_ip(cfg['using_local_ip']) if current_ip: # 对于拥有多个出口 IP 负载均衡的服务器,上面的 get_ip() 函数会在几个 ip 之间不停切换 # 然后频繁进入这个判断,进行 update_record(),然后很快就会触发 API Limited 了 # 于是建立一个IP池记载这个服务器的几个出口IP,以免频繁切换 ip_count = int(cfg['ip_count']) ip_pool = cfg['ip_pool'].split(',')[:ip_count] cfg['current_ip'] = current_ip if current_ip not in ip_pool: # new ip found logging.info("new ip found: %s", current_ip) try: ok = update_record(current_ip) if ok: ip_pool.insert(0, current_ip) cfg['ip_pool'] = ','.join( [str(x) for x in ip_pool[:ip_count]]) save_config() except Exception as e: logging.error("update_record failed, err=%s" % (e)) else: logging.error('get current ip FAILED.') time.sleep(interval)
def send_email(image_path, ssocr_output): msg = MIMEMultipart() msg['From'] = fromaddr msg['To'] = toaddr msg['Subject'] = "[TEST IMAGE] %s - %s %s" % (machine_number, hall, machine_type) body = "My IP %s \n SSOCR output is %s \n\n\n\n\n\n\n" % (get_ip.get_ip(), ssocr_output) msg.attach(MIMEText(body, 'plain')) filename = "test_image.jpg" attachment = open(image_path, "rb") part = MIMEBase('application', 'octet-stream') part.set_payload((attachment).read()) encoders.encode_base64(part) part.add_header('Content-Disposition', "attachment; filename= %s" % filename) msg.attach(part) tries = 0 while True: if (tries > 60): exit() try: server = smtplib.SMTP('smtp.gmail.com', 587) break except Exception as e: tries = tries + 1 time.sleep(1) server.starttls() server.login(fromaddr, "I_am_a_laundry") text = msg.as_string() server.sendmail(fromaddr, toaddr, text) print('Send Email Successfully') server.quit()
#!/usr/bin/python #coding=utf-8 from time import sleep from baidu.speech import speech from get_ip import get_ip if __name__ == '__main__': #say_boot() #say_ip() sleep(5) speech('勇哥勇哥,系统已经启动!', 'boot', False) ip = get_ip() speech('IP地址是:' + ip, 'ip_address', True)
self.ball.dx = -self.ball.dx * self.ball.bounce self.ball.spin = -self.ball.dy if self.score > self.highscore: self.highscore = self.score self.ball.update() print(self.tries) if self.tries <= 0: self.game_over = True self.SendToAll({'action': 'game_over', 'data': self.get_json(), 'highscore': self.highscore}) self.DelPlayer(player) pygame.quit() def get_json(self): return json.dumps( {'images': {str(id(self)): {'image': 'ball', 'x': self.ball.x, 'y': self.ball.y}}}) def Launch(self): while True: self.Pump() sleep(0.0001) if __name__ == "__main__": host = get_ip() s = Game(localaddr=(host, int(31425))) s.Launch()
def test_no_ips_if_too_small(n): ips = list(get_ip(str(n))) assert ips == []
def main(): # ***Initalize the variables*** # The filter coefficients for the FIR-Filter i = 0 # temperature integral filt_coeff = [ -0.00406900049466597, 0.0014901583160827512, 0.0022278714276290482, 0.0034863421930641913, 0.005262349013769549, 0.007526937975321521, 0.010265872128229686, 0.013462614002518912, 0.017080624262474767, 0.021064542544973485, 0.025343688456984637, 0.029828825716452217, 0.034413765259578025, 0.03898213878353851, 0.04341086645098334, 0.047573306814647984, 0.0513458497439482, 0.05461325635763496, 0.05727219604594146, 0.059236523087357246, 0.06044200599455753, 0.060848468662696956, 0.06044200599455753, 0.059236523087357246, 0.05727219604594146, 0.05461325635763496, 0.0513458497439482, 0.047573306814647984, 0.04341086645098334, 0.03898213878353851, 0.034413765259578025, 0.029828825716452217, 0.025343688456984637, 0.021064542544973485, 0.017080624262474767, 0.013462614002518912, 0.010265872128229686, 0.007526937975321521, 0.005262349013769549, 0.0034863421930641913, 0.0022278714276290482, 0.0014901583160827512, -0.00406900049466597 ] time_w = 0 # Initialize the timeout for warning messages time_c = 0 # Initialize the timeout for repeatet crtitical messages ip = get_ip.get_ip() # Get the IP-Address wd = wdt.wdt() # initialize the watchdog wd.open() # open the watchdog file (and arm the watchdog) wd.refresh() # give the watchdog a first kick # bus = smbus.SMBus(bus_nr) # Make the bus object for communication with i2c devices with i2c.I2CMaster(bus_nr) as bus: display = i2c_display.i2c_display(bus, addr_d) # Initialze the display display.clear() # Clear the display write_line1(display, ip) t = check_temperature(bus, addr_t) # Read the tempearture a first time to initialize the filter fv = fir.filtr(len(filt_coeff), t) # Create the filter object fv.set_filter(filt_coeff) # load the coefficients into the FIR filter # DEBUG Output if debug: print(ip) hb_cnt = 0 syslog.syslog("fan-control: Program started") # The real work is done in this loop! while True: try: wd.refresh() # Kick the watchdog # Collect tp = check_temperature(bus, addr_t) # read temperature # Process t = fv.filt(tp) # filter temperature dac_value, i = calculate_output(t, i) # calculate the DAC-Value from temperature line2 = 'T:{0:2.2f}'.format(t) + chr(0xDF) + 'C D:{0:4d}'.format(dac_value) # Format the information for dipslay # Output dac_write(bus, addr_v, dac_value) # write the calculate value to the DAC display.write_string(1, line2) # Write information to diplay time_w, time_c = handle_email(t, time_w, time_c) # Call the email handler # Write heartbeat signal hb_cnt = hb_cnt + 1 # if hb_cnt >= 4: # hb_cnt = 0 display.write_xy(15, 0, hb_chars[hb_cnt % 4]) if (hb_cnt % 600) == 0: # Every 600 iterations (5min) ip = get_ip.get_ip() if (hb_cnt % 20) == 0: # Every 20 iterations (10s) write_line1(display, ip) # Update CGRAM and IP Address file_write_dac(dacval_file, dac_value) # Wait time.sleep(sleeptime) # Debug output if debug: print( line2 + " " + str(tp) + " " + str(time_w) + " " + str(time_c) ) except KeyboardInterrupt: sys.stderr.write("\nReceived ctrl+c, will terminate\n") #sys.exit() wd.deactivate() # Disarm the watchdog wd.finish() # Close the file syslog.syslog("fan-control: Program terminated by keyboard interrupt") # Write Message to syslog unlink(dacval_file) #remove the dacval file # os.sync() # write all open changes to disk fs_sync() sys.exit() except: sys.stderr.write("An unknow error has occured! Terminating...\n") print( "Error: ", sys.exc_info()[0]) print( "Error: ", sys.exc_info()[1]) print( "Error: ", sys.exc_info()[2]) syslog.syslog(syslog.LOG_ERR, "fan-control: Terminating because of error!") # Write error to syslog syslog.syslog(syslog.LOG_ERR, "fan-control:" + str(sys.exc_info()[0])) syslog.syslog(syslog.LOG_ERR, "fan-control:" + str(sys.exc_info()[1])) syslog.syslog(syslog.LOG_ERR, "fan-control:" + str(sys.exc_info()[2])) # os.sync() # write all pending data to disk unlink(dacval_file) #remove the dacval file fs_sync() sys.exit(1)
def test_no_ips_if_too_big(n): ips = list(get_ip(str(n))) for ip in ips: assert is_ip(ip)
from get_ip import get_ip from multiprocessing import Pool if __name__ == '__main__': urls = [ 'https://www.xicidaili.com/nn/{}'.format(x) for x in range(128, 2000) ] pool = Pool(4) for url in urls: pool.apply_async(get_ip().get_ips(url)) pool.close() pool.join()
def main(): # ***Initalize the variables*** # The filter coefficients for the FIR-Filter i = 0 # temperature integral filt_coeff = [ -0.00406900049466597, 0.0014901583160827512, 0.0022278714276290482, 0.0034863421930641913, 0.005262349013769549, 0.007526937975321521, 0.010265872128229686, 0.013462614002518912, 0.017080624262474767, 0.021064542544973485, 0.025343688456984637, 0.029828825716452217, 0.034413765259578025, 0.03898213878353851, 0.04341086645098334, 0.047573306814647984, 0.0513458497439482, 0.05461325635763496, 0.05727219604594146, 0.059236523087357246, 0.06044200599455753, 0.060848468662696956, 0.06044200599455753, 0.059236523087357246, 0.05727219604594146, 0.05461325635763496, 0.0513458497439482, 0.047573306814647984, 0.04341086645098334, 0.03898213878353851, 0.034413765259578025, 0.029828825716452217, 0.025343688456984637, 0.021064542544973485, 0.017080624262474767, 0.013462614002518912, 0.010265872128229686, 0.007526937975321521, 0.005262349013769549, 0.0034863421930641913, 0.0022278714276290482, 0.0014901583160827512, -0.00406900049466597 ] time_w = 0 # Initialize the timeout for warning messages time_c = 0 # Initialize the timeout for repeatet crtitical messages ip = get_ip.get_ip() # Get the IP-Address wd = wdt.wdt() # initialize the watchdog wd.open() # open the watchdog file (and arm the watchdog) wd.refresh() # give the watchdog a first kick # bus = smbus.SMBus(bus_nr) # Make the bus object for communication with i2c devices with i2c.I2CMaster(bus_nr) as bus: display = i2c_display.i2c_display(bus, addr_d) # Initialze the display display.clear() # Clear the display write_line1(display, ip) t = check_temperature( bus, addr_t ) # Read the tempearture a first time to initialize the filter fv = fir.filtr(len(filt_coeff), t) # Create the filter object fv.set_filter(filt_coeff) # load the coefficients into the FIR filter # DEBUG Output if debug: print(ip) hb_cnt = 0 syslog.syslog("fan-control: Program started") # The real work is done in this loop! while True: try: wd.refresh() # Kick the watchdog # Collect tp = check_temperature(bus, addr_t) # read temperature # Process t = fv.filt(tp) # filter temperature dac_value, i = calculate_output( t, i) # calculate the DAC-Value from temperature line2 = 'T:{0:2.2f}'.format(t) + chr( 0xDF) + 'C D:{0:4d}'.format( dac_value) # Format the information for dipslay # Output dac_write(bus, addr_v, dac_value) # write the calculate value to the DAC display.write_string(1, line2) # Write information to diplay time_w, time_c = handle_email(t, time_w, time_c) # Call the email handler # Write heartbeat signal hb_cnt = hb_cnt + 1 # if hb_cnt >= 4: # hb_cnt = 0 display.write_xy(15, 0, hb_chars[hb_cnt % 4]) if (hb_cnt % 600) == 0: # Every 600 iterations (5min) ip = get_ip.get_ip() if (hb_cnt % 20) == 0: # Every 20 iterations (10s) write_line1(display, ip) # Update CGRAM and IP Address file_write_dac(dacval_file, dac_value) # Wait time.sleep(sleeptime) # Debug output if debug: print(line2 + " " + str(tp) + " " + str(time_w) + " " + str(time_c)) except KeyboardInterrupt: sys.stderr.write("\nReceived ctrl+c, will terminate\n") #sys.exit() wd.deactivate() # Disarm the watchdog wd.finish() # Close the file syslog.syslog( "fan-control: Program terminated by keyboard interrupt" ) # Write Message to syslog unlink(dacval_file) #remove the dacval file # os.sync() # write all open changes to disk fs_sync() sys.exit() except: sys.stderr.write( "An unknow error has occured! Terminating...\n") print("Error: ", sys.exc_info()[0]) print("Error: ", sys.exc_info()[1]) print("Error: ", sys.exc_info()[2]) syslog.syslog(syslog.LOG_ERR, "fan-control: Terminating because of error!" ) # Write error to syslog syslog.syslog(syslog.LOG_ERR, "fan-control:" + str(sys.exc_info()[0])) syslog.syslog(syslog.LOG_ERR, "fan-control:" + str(sys.exc_info()[1])) syslog.syslog(syslog.LOG_ERR, "fan-control:" + str(sys.exc_info()[2])) # os.sync() # write all pending data to disk unlink(dacval_file) #remove the dacval file fs_sync() sys.exit(1)
def test_answer_contains_ip(ip): s = str(ip) ips = list(get_ip(no_dots(s))) assert s in ips
@app.route('/manage/services', methods=['GET', 'POST']) def manage_page_services(): if request.method == 'POST': if request.form['submit-service'] == 'Create': try: # ciphered_pwd = generate_password_hash(request.form["password"], method='sha256') new_service = Services( name=request.form["name"], port=request.form['port'], access_name=request.form['access_name'], access_code=access[request.form['access_name']]) db.session.add(new_service) db.session.commit() except: pass return render_template('manage.html', header_title='Manage Services', login='******', user='******', property='services', data=get_data('services')) if __name__ == '__main__': db.create_all() os.popen("sass static/scss/style.scss:static/css/style.css") app.run(debug=True, host=get_ip(), port=2357)
def test_all_are_ips(n): ips = list(get_ip(str(n))) for ip in ips: assert is_ip(ip)
import re from get_ip import get_ip get_ip()
def test_concatenate_answers(n): s = str(n) ips = list(get_ip(str(n))) for ip in ips: assert no_dots(ip) == s