def command(self): print("Commands: send, badge, enter, leave, laser, authorize, stop, fire") command = input('-> ') if command == 'send': msg = Message(Message.DATA, input('Message data -> ')) self.msg(input('Message target -> '), msg) if command == 'enter': self.msg('Entry Reader', Message(Message.DATA, self.badge)) if command == 'leave': self.msg('Exit Reader', Message(Message.DATA, self.badge)) if command == 'laser': self.msg('Laser', Message(Message.DATA, '')) if command == 'badge': self.badge = Badge(input('Badge name -> ')) if command == 'authorize': self.msg('Entry Reader', Message(Message.AUTHORIZE, self.badge)) if command == 'fire': self.msg('Fire Detector', Message(Message.DATA, '')) if command == 'stop': return False return True
def main(args: argparse.Namespace): pseudo = args.pseudo theme = args.theme rm = RootMe() try: data = rm.get_user_stats(pseudo) except UserNotFoundError as e: print("ERROR: This user does not exist") quit(1) if data["avatar_url"]: download_file(rm.get_session(), data["avatar_url"], "pp.png") badge = Badge( pseudo=data["username"], profile_picture="pp.png", score=data["score"], title=data["rank"], ranking=data["ranking"], total_users=data["total_users"], theme=theme ) badge.create() if isfile("pp.png"): remove("pp.png") if args.save: badge.save(args.outfile) if args.show: badge.show(args.viewer)
def test_add_badge_should_add_1_item_to_list(self): # Arrange - done in setUp() new_badge = Badge(2, ["b1", "b2", "c1"]) # Act self.badge_repo.badges_list.append(new_badge) expected = 2 actual = len(self.badge_repo.badges_list) # Assert self.assertEqual(expected, actual)
def send_time(addr=""): logger.info("Sending date to {}".format(addr)) retcode = 0 bdg = None try: bdg = Badge(addr) logger.info("Connected") bdg.sendDateTime() logger.info("Sent date") except BTLEException, e: retcode = -1 logger.error("failed sending time,{},{}".format(e.code, e.message))
def _read_file(self, device_file): """ refreshes an internal list of devices included in device_macs.txt Format is device_mac<space>badge_id<space>project_id<space>device_name :param device_file: :return: """ if not os.path.isfile(device_file): self.logger.error( "Cannot find devices file: {}".format(device_file)) exit(1) self.logger.info("Reading devices from file: {}".format(device_file)) #extracting badge id, project id and mac address with open(device_file, 'r') as devices_macs: badge_project_ids = [] devices = [] for line in devices_macs: if not line.lstrip().startswith('#'): device_details = line.split() devices.append({ "mac": device_details[0], "badge_id": device_details[1], "project_id": device_details[2], }) for d in devices: self.logger.debug(" {}".format(d)) badges = { device["mac"]: Badge( device["mac"], self.logger, key=device[ "mac"], # using mac as key since no other key exists badge_id=int(device["badge_id"]), project_id=int(device["project_id"]), init_audio_ts_int=self._init_ts, init_audio_ts_fract=self._init_ts_fract, init_proximity_ts=self._init_ts, ) for device in devices } badges = collections.OrderedDict( sorted(badges.items(), key=lambda t: t[1].badge_id)) return badges
def get_score(): repo_name = request.args.get('repo') account_info = github.get('/user') account_data = account_info.json() owner = account_data['login'] github_gql = Github(github.access_token) constable = Constable(repo_name, owner, github_gql) score = constable.get_score() print(score) grade = constable.get_grade(score['total_score']) branch = 'master' key = '{}/{}/{}'.format(owner, repo_name, branch) badge = Badge(key).get_shield_url(grade=grade) return {"score": score, "grade": grade, "badge": badge}
def _read_file(self, device_file): """ refreshes an internal list of devices included in device_macs.txt Format is device_mac<space>badge_id<space>project_id<space>device_name :param device_file: :return: """ if not os.path.isfile(device_file): self.logger.error( "Cannot find devices file: {}".format(device_file)) exit(1) self.logger.info("Reading devices from file: {}".format(device_file)) #extracting badge id, project id and mac address with open(device_file, 'r') as devices_macs: badge_project_ids = [] devices = [] for line in devices_macs: if not line.lstrip().startswith('#'): device_details = line.split() devices.append(device_details[0]) badge_project_ids.append(device_details[1:3]) #mapping badge id and project id to mac address mac_id_map = {} for i in range(len(devices)): mac_id_map[devices[i]] = badge_project_ids[i] for d in devices: self.logger.debug(" {}".format(d)) beacons = { mac: Badge( mac, self.logger, key=mac, # using mac as key since no other key exists badge_id=int(mac_id_map[mac][0]), project_id=int(mac_id_map[mac][1]), ) for mac in mac_id_map.keys() } return beacons
def _read_file(self, device_file): """ refreshes an internal list of devices included in device_macs.txt Format is device_mac<space>device_name :param device_file: :return: """ if not os.path.isfile(device_file): self.logger.error( "Cannot find devices file: {}".format(device_file)) exit(1) self.logger.info("Reading devices from file: {}".format(device_file)) regex = re.compile(r'^([A-Fa-f0-9]{2}(?::[A-Fa-f0-9]{2}){5}).*') with open(device_file, 'r') as devices_macs: devices = [regex.findall(line) for line in devices_macs] devices = filter(lambda x: x, map(lambda x: x[0] if x else False, devices)) devices = [d.upper() for d in devices] for d in devices: self.logger.debug(" {}".format(d)) badges = { mac: Badge( mac, self.logger, key=mac, # using mac as key since no other key exists init_audio_ts_int=self._init_ts, init_audio_ts_fract=self._init_ts_fract, init_proximity_ts=self._init_ts, ) for mac in devices } return badges
def dialogue(addr=""): logger.info("Talking with {}".format(addr)) retcode = 0 bdg = None try: bdg = Badge(addr) logger.info("Connected") while not bdg.dlg.gotStatus: bdg.RfdReadWrite.write("s") # ask for status bdg.waitForNotifications(1.0) # waiting for status report logger.info("Got status") if bdg.dlg.needDate: bdg.sendDateTime() logger.info("Date sent") else: logger.info("Already synced") if bdg.dlg.dataReady: logger.info("Requesting data...") bdg.RfdReadWrite.write("d") # ask for data wait_count = 0 while True: if bdg.waitForNotifications(1.0): # if got data, don't inrease the wait counter continue logger.info("Waiting for more data...") wait_count = wait_count + 1 if wait_count >= PULL_WAIT: break logger.info("finished reading data") except BTLEException, e: retcode = -1 logger.error("failed pulling data") logger.error(e.code) logger.error(e.message)
def setUp(self): self.badge_repo = BadgeRepository([]) self.new_badge = Badge(1, ["a1", "a2"]) self.badge_repo.badges_list.append(self.new_badge)
def dialogue(addr=""): logger.info("Connecting to {}".format(addr)) retcode = 0 bdg = None try: with timeout(seconds=5, error_message="Connect timeout"): bdg = Badge(addr) logger.info("Connected") with timeout( seconds=5, error_message="Dialogue timeout (wrong firmware version?)"): while not bdg.dlg.gotStatus: bdg.sendStatusRequest() # ask for status bdg.waitForNotifications(1.0) # waiting for status report logger.info("Got status") #while not bdg.dlg.gotDateTime: # bdg.NrfReadWrite.write("t") # ask for time # bdg.waitForNotifications(1.0) logger.info( "Badge datetime: {},{}, Voltage: {}, Recording? {}".format( bdg.dlg.timestamp_sec, bdg.dlg.timestamp_ms, bdg.dlg.voltage, bdg.dlg.recording)) with timeout( seconds=5, error_message="Dialogue timeout (wrong firmware version?)"): while not bdg.dlg.sentStartRec: bdg.sendStartRecRequest( RECORDING_TIMEOUT) # ask to start recoding #bdg.sendStatusRequest() # ask for status instead bdg.waitForNotifications(1.0) # waiting for status report logger.info("Got Ack for start recording") # data request using the "r" command - data since time X logger.info("Requesting data...") lastChunkDate = None with badgeDB() as db: lastChunkDate = db.getLastChunkDate(addr) if (lastChunkDate == None): lastChunkDate = datetime.datetime.now() logger.info( "Cannot find saved chunks. Setting last chunk date to: {}". format(lastChunkDate)) else: logger.info("Last chunk date: {}".format(lastChunkDate)) bdg.sendDataRequest(lastChunkDate) # ask for data wait_count = 0 while True: if bdg.dlg.gotEndOfData == True: logger.info("End of data") break if bdg.waitForNotifications(1.0): # if got data, don't inrease the wait counter continue logger.info("Waiting for more data...") wait_count = wait_count + 1 if wait_count >= PULL_WAIT: break logger.info("finished reading data") except BTLEException, e: retcode = -1 logger.error("failed pulling data") logger.error(e.code) logger.error(e.message)
#!/usr/bin/env python3 ''' Get differentially expressed genes. ''' import argparse from badge import Badge from utils import str2bool ap = argparse.ArgumentParser(description="Get differentially expressed genes.") ap.add_argument("input", type=str, help="input file") ap.add_argument("ctypes", type=str, help="cell types", nargs="*") ap.add_argument("-g", "--graph", default=True, type=str2bool, help="whether to graph (default: True)") args = vars(ap.parse_args()) b = Badge(args.get("input")) cg = b.candidate_genes(args.get("ctypes")) print(cg) if args.get("graph"): for ctype in args.get("ctypes"): b.graph(cg[ctype])
def __init__(self, ctx): super(Actor, self).__init__('actor', ctx) self.badge = Badge('actor')
def create_badge_prompt(self): badge_number = input('What is the number on the badge: ') door_access_codes = self.add_door_access_prompt() new_badge = Badge(badge_number, door_access_codes) self.badge_repo.add_badge(new_badge)