def __init__(self, companyId=0, logger=""): self.allSites= {} self.companyId = companyId self.logger = logger self.logger.info("SETUP USERS \n") api = jsonws.API() r = api.call("/group/get-groups", {'companyId': self.companyId, 'parentGroupId': '0', 'site':'true'}) #print(r.url) #print (r.text) groups = json.loads(r.text) for g in groups: if 'Guest' in g['groupKey']: self.groupID = g['groupId'] #print("GROUP ID = ", self.groupID ) r = api.call("/layout/get-layouts", {'groupId': self.groupID, 'privateLayout': 'false'}) self.logger.info("/layout/get-layouts") self.logger.info(r.text) #print (r.text) sites = json.loads(r.text) #print("SITES AVAILABLE") for si in sites: self.allSites[si['friendlyURL']] = si['layoutId'] if si['friendlyURL'] == "/home": self.welcometypeSettings = si['typeSettings'] self.welcomeplid = si['plid'] #print(self.allSites) self.journalService = journal.Journal(self.companyId, self.groupID, logger)
def __init__(self, user): try: while True: print("\n\t\t\t\t\tYou are Logged in as {}".format(user)) print( '''\t\t\t\t\t\t1.) Post Journal\n\t\t\t\t\t\t2.) Show Journal List''' ) register__val = int(input("\t\t\t\t\t: ")) self.Journal = journal.Journal() if register__val == 1: self.post_journal(user) elif register__val == 2: self.show_journal(user) else: print("\t\t\t\t\t\tWrong Value") except KeyboardInterrupt: start()
def setUp(self): # mock input self.input_values = [] self.save_input = journal.input def mock_input(s): return self.input_values.pop(0) journal.input = mock_input # save files os.rename("journal_tasks.txt", "sjt.txt") os.rename("journal_actions.txt", "sja.txt") with open("journal_tasks.txt", 'w') as f: pass with open("journal_actions.txt", 'w') as f: pass self.journal = journal.Journal()
def __init__(self): self.inventory = inventory.Inventory() self.journal = journal.Journal() super(Player, self).__init__()
def main(): import journal journal.Journal()
def __init__(self, args): """Initialise the command-line interface for Inpensa. Process the user's input according to the options provided. :param dict args: dictionary of arguments from docopt. """ print('==============================================') print('| |') print('| Inpensa v0.1 |') print('| |') print('==============================================') self.args = args # Load journal if self.args['init']: print('== Creating a new journal') name = input(' -- Enter a name for the journal (journal.json): ') # Check and edit the entered filename appropriately if name.strip() == '': name = 'journal.json' elif not name.endswith('.json'): name = name + '.json' # Check if journal exists. If so, backup original. if os.path.exists(name): os.replace(name, name + '.orig') # Create a new journal self.journal = journal.Journal(name, new=True) print('== New journal created') print(' -- Location: {0:s}'.format( os.path.abspath(self.journal.abs_filename))) return # If user ran 'init', only create the new journal and exit. # If no 'journal' provided, assume a default name. if self.args['--journal'] is None: self.filename = 'journal.json' else: self.filename = self.args['--journal'] try: self.journal = journal.Journal(self.filename) except FileNotFoundError: print('Cannot find the journal file requested.') print('File requested: {0:s}'.format(self.filename)) return except json.decoder.JSONDecodeError: print('Something wrong with the journal file requested.') print('File requested: {0:s}'.format(self.filename)) return print('== Loaded journal: {0:s}'.format(self.filename)) # Processing commands if self.args['add']: if self.args['expense']: if not self.journal.categories: print('No categories/sub-categories in journal.\n') print('Use \'inpensa add category <name> <sub-name>\' to ' 'add.') return print('== Adding expense') self.add_expense() elif self.args['category']: print('== Adding category') c = self.args['<category-name>'].strip() sc = self.args['<sub-category-name>'].strip() if c in self.journal.categories: if sc in self.journal.categories[c]: print('\'{0:s}\' already in \'{1:s}\''.format( sc, self.journal.filename)) return else: self.journal.categories[c].append(sc) self.journal.categories[c].sort(key=str.lower) else: # Add new category with current sub-category as first item self.journal.categories[c] = [sc] print(' -- \'{0:s}: {1:s}\' was added to \'{2:s}\''.format( c, sc, self.journal.filename)) # After doing some work write changes to file. self.journal.write(self.filename) if self.args['show']: if self.args['expenses']: self.show_expenses() elif self.args['categories']: self.show_categories() elif self.args['statistics']: self.show_statistics() return
with open('config.json', 'w') as f: json.dump(config, f) if __name__ == '__main__': #exit(cli()) d = os.path.dirname(os.path.realpath(__file__)) if os.path.exists(d + '/config.json'): with open('config.json', 'r') as f: config = json.load(f) main = Walker(url=config['master'], feed=config['feed_master'], api_key=config['api_key_master'], DEBUG=0) mirror = Walker(url=config['slave'], feed=config['feed_slave'], api_key=config['api_key_slave'], DEBUG=0) m1 = mirror.get_nuget_packages_list() m = main.get_nuget_packages_list() j_main = journal.Journal() j_m1 = journal.Journal() j_main.insert_packs(m) j_m1.insert_packs(m1) print(j_main.get_table()) print(j_m1.get_table()) print('--------------------') diff = j_main.diff_table(j_m1) mirror.download_nuget(diff)
def main(): program_name = os.path.basename(__file__) door_log = journal.Journal(GDOOR_ACTIVITY_LOGGER, GDOOR_ACTIVITY_LOG_FILE, program_name) startup_log = journal.Journal(GDOOR_STARTUP_LOGGER, GDOOR_STARTUP_LOG_FILE, program_name) startup_log.information("Garage door monitor started.") parser = argparse.ArgumentParser() parser.add_argument( "-c", "--checkstatus", type=float, default=1.0, help="delay in minutes between checking door status", ) parser.add_argument( "-i", "--individual", type=float, default=0.5, help="delay in seconds between taking individual measurements", ) parser.add_argument( "-m", "--measurements", type=int, default=3, help="number of measurements for averaging", ) parser.add_argument( "-o", "--open", type=int, default=50, help="number of cm above the door is considered open", ) parser.add_argument( "-w", "--warning", type=int, default=30, help= "display warnings when the door is open more than this many minutes", ) parser.add_argument( "-d", "--debug", action='store_true', help="print and log debugging messages", ) args = parser.parse_args() msg = "Each average will use {} measurements.".format(args.measurements) door_log.information(msg) msg = "There will be {} seconds delay between individual measurements.".format( args.individual) door_log.information(msg) msg = "There will be {} minutes ({} seconds) delay between checking the door's status.".format( args.checkstatus, args.checkstatus * 60) door_log.information(msg) msg = "Door is considered open if sensor reading is less than {}".format( args.open) door_log.information(msg) msg = "Warnings will be sent every {} minutes while the door is open".format( args.warning) door_log.information(msg) # Set whether debug messages are printed and logged based on # what was specified on the command. door_log.log_debug = args.debug # Convert the time between taking averaged measurements from # minutes to seconds. checkstatus = 60 * args.checkstatus monitor_door( GPIO_TRIGGER, GPIO_ECHO, GPIO_STATUS_LED, args.measurements, args.individual, checkstatus, args.open, args.warning, door_log, ) door_log.debug("Exiting...")