from ir import IR from moeda import Moeda from anexo3 import Anexo3 from anexo5 import Anexo5 from prolabore import Prolabore from nota_fiscal import Nota_fiscal valor_hora = int(input('Informe seu valor hora: ')) qtd_horas = int(input('Informe a quantidade de horas trabalhadas: ')) total_nf = Nota_fiscal.calcula_valor(qtd_horas, valor_hora) prolabore = Prolabore().calcula(total_nf) anexo_v = Anexo5.aplica_imposto(total_nf) imposto_anexo_iii = Anexo3.aplica_imposto(total_nf) inss = INSS(prolabore).calcula() ir = IR(prolabore).calcula(inss) tot_anexo_iii = Anexo3.calcula_desconto_total(imposto_anexo_iii, inss, ir) print('') print('Receita {}'.format(Moeda.real_brasil(total_nf))) print('Fator R {}%'.format(Prolabore().get_fator_r())) print('Prolabore {}'.format(Moeda.real_brasil(prolabore))) print('') print('Desconto DAS {}'.format(Moeda.real_brasil(imposto_anexo_iii))) print('Desconto INSS {}'.format(Moeda.real_brasil(inss))) print('Desconto IRPF {}'.format(Moeda.real_brasil(ir))) print('') print('Total Desconto Anexo III {}'.format(Moeda.real_brasil(tot_anexo_iii))) print('Total Desconto Anexo V {}'.format(Moeda.real_brasil(anexo_v))) print('Diferença {}'.format(Moeda.real_brasil(anexo_v - tot_anexo_iii))) print('----------------')
from datetime import datetime, timedelta from navigator import Navigator from driver import Driver from laser import Laser from gyro import Gyro from ir import IR from communicator import Communicator from eventbus import EventBus from position import Position from protocol import * from safety import Safety ir = IR() laser = Laser() gyro = Gyro() driver = Driver(gyro, laser) navigator = Navigator(Navigator.MANUAL, ir, driver, laser) position = Position(laser, ir, navigator) communicator = Communicator(ir, laser, gyro, driver, navigator, position) def setup(): Safety.setup_terminal_abort() EventBus.subscribe(BT_REQUEST_SENSOR_DATA, communicator.send_sensor_data) EventBus.subscribe(BT_REQUEST_SERVO_DATA, communicator.send_servo_data) EventBus.subscribe(BT_REQUEST_MAP_DATA, communicator.send_map_data) EventBus.subscribe(BT_DRIVE_FORWARD, communicator.drive_forward) EventBus.subscribe(BT_DRIVE_BACK, communicator.drive_backward)
def main(): ir = IR() while True: query = input('\n請輸入你的問題:') print('\n以下為可能回覆的答案:') print(ir.find_best_result(query))
def __init__(self): self.ir = IR() self.relay = Relay()
class Router(object): ir = None relay = None def __init__(self): self.ir = IR() self.relay = Relay() def stop(self): self.relay.stop() def post(self, path, data): """Respond to a POST request.""" if path == "/api/ir/save-ui-config/": result = 'Not saved.' with open("remotes-ui.json", "w") as f: f.write(data) result = 'Saved.' return result elif path == "/api/save-relay-ui-config/": result = 'Not saved.' with open("remotes-relay-ui.json", "w") as f: f.write(data) result = 'Saved.' return result elif path == "/api/ir/save-config/": return self.ir.save_config(data) else: return "Not found." def get(self, path): """Respond to a GET request.""" response = "" try: if path == "/api/ir/": if self.ir.launched: self.ir.kill() response = self.ir.launch() elif path.startswith("/api/relay/off/"): response = self.relay.off(path.replace("/api/relay/off/", "")) elif path.startswith("/api/relay/on/"): response = self.relay.on(path.replace("/api/relay/on/", "")) elif path.startswith("/api/relay/onoff/"): response = self.relay.onoff(path.replace("/api/relay/onoff/", "")) elif path.startswith("/api/relay/offon/"): response = self.relay.offon(path.replace("/api/relay/offon/", "")) elif path.startswith("/api/bluetooth/wait/"): print "Bluetooth wait" response = self.relay.btpair.wait() elif path.startswith("/api/bluetooth/stop/"): response = self.relay.btpair.stop() elif path.startswith("/api/config/wifi/scan/"): content = "" networks = [] p = pexpect.spawn('iwlist wlan0 scan') while True: out = p.readline() if out == '' and p.eof() is not None: break if out: content = content + out find_networks = re.findall("ESSID.*$",content,re.MULTILINE) find_levels = re.findall("Signal level.*$",content,re.MULTILINE) index = 0; for item in find_networks: networks.append(item.replace('ESSID:"','').replace('"\r','') + ':' + find_levels[index].replace("Signal level=","").replace(" dBm \r","")) index+=1 response = string.join(networks,",") elif path.startswith("/api/config/wifi/get/"): p = pexpect.spawn('iwgetid') response = p.readline().replace('wlan0 ESSID:"',"").replace('"','').replace('\r','').replace('\n','') p = pexpect.spawn('hostname -I') response += "," + p.readline() elif path.startswith("/api/config/wifi/set/"): data = urllib.unquote(path.replace('/api/config/wifi/set/','')).split(":") with open("/etc/wpa_supplicant/wpa_supplicant.conf", "w") as f: f.write("country=GB \n") f.write("ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev \n") f.write("update_config=1 \n") f.write("network={ \n") f.write("ssid=\"" + data[0] + "\" \n") f.write("psk=\"" + data[1] + "\" \n") f.write("proto=RSN \n") f.write("key_mgmt=WPA-PSK \n") f.write("pairwise=CCMP \n") f.write("auth_alg=OPEN \n") f.write("} \n") f.close() p = pexpect.spawn('ifdown wlan0') p.readline() p = pexpect.spawn('ifup wlan0') p.readline() response = "Connected." elif path == "/api/get-relay-ui-config/": if ospath.isfile("remotes-relay-ui.json"): content = "" with open("remotes-relay-ui.json", "r") as f: for line in f: content = content + line else: content = "File not found. \n" response = content elif path == "/api/get-ui-config/": if ospath.isfile("remotes-ui.json"): content = "" with open("remotes-ui.json", "r") as f: for line in f: content = content + line else: content = "File not found. \n" response = content elif path.startswith("/api/lirc/send/"): split_path = path.split('/') send = split_path[len(split_path)-1] cmd = send.split(',') self.ir.send_once(cmd[0], cmd[1]) response = "Command sent." elif path.startswith("/api/ir/"): if path.endswith("/send/"): split_path = path.split('/') response = self.ir.send(split_path[len(split_path)-3]) if path == "/api/ir/get-last-config/": response = self.ir.get_last_config() if path == "/api/ir/get-config/": response = self.ir.get_config() elif path == "/api/ir/get-namespace/": response = self.ir.get_namespace() elif path == "/api/ir/mode2/": response = self.ir.mode2() elif path == "/api/ir/stop-lirc-service/": response = self.ir.stop_lirc_service() elif path == "/api/ir/start-lirc-service/": response = self.ir.start_lirc_service() elif path.endswith("/save-last-config/"): split_path = path.split('/'); name = split_path[len(split_path)-3] response = self.ir.save_last_config(name) else: if not self.ir.launched: response = "IRRecord not launched." else: if path == "/api/ir/enter/": response = self.ir.enter() elif path == "/api/ir/status/": response = self.ir.status() elif path == "/api/ir/kill/": response = self.ir.kill() except IOError: response = "Error." #self.send_error(404,'File Not Found: %s' % path) return response
# # the main program reading out the IR controller # copyright U. Raich 6.May 2021 # # This program is part of the course on IoT # at the Université Cheikh Anta Diop, Dakar, Senegal # It is released under the MIT license from ir import IR ir = IR(21) IR_code = { 0xff6897: "0", 0xff30cf: "1", 0xff18e7: "2", 0xff7a85: "3", 0xff10ef: "4", 0xff38c7: "5", 0xff5aa5: "6", 0xff42bd: "7", 0xff4ab5: "8", 0xff52ad: "9", 0xffa25d: "CH-", 0xff629d: "CH", 0xffe21d: "CH+", 0xff22dd: "|<<", 0xff02fd: "|>>", 0xffc23d: ">||", 0xffe01f: "-", 0xffa857: "+", 0xff906f: "EQ", 0xff9867: "100+", 0xffb04f: "200+"
import socket import json from ir import IR # Processamneto aqui HOST = '127.0.0.1' PORT = 8484 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(2) score = IR() conn1, addr1 = s.accept() print 'Connected by', addr1 while 1: try: data = conn1.recv(1024) except socket.error: print '' if data: obj = data.decode('utf-8') obj_json = json.loads(obj) print obj_json obj_json['cidade']=str(obj_json['cidade']) #Rankeamento aqui score.setRequest(obj_json)