def get_date_search_string(request_dict): date_search_string = '' if len(request_dict['from'][0]) > 0: date_search_string += '&beginDate=' + util.get_date_string(request_dict['from'][0]) if len(request_dict['to'][0]) > 0: date_search_string += '&endDate=' + util.get_date_string(request_dict['to'][0]) if len(date_search_string) > 0: date_search_string += '&dateSearchMode=isWithin' return escape.url_escape(date_search_string)
def bindSocket(s, BindPort, local_ip): try: s.bind(('', BindPort)) get_date_string() if local_ip != '': print("server: + $local_ip + $BindPort") else: print("server:" + str(gethostbyname(gethostname())) + str(BindPort)) except Exception as e: print(e) get_date_string() print("ERROR: nie mozna zabindowac portu %s, wybierz inny BindPort") s.close() sys.exit()
def get_actual_config(schedule_thing): return ( '%s | %s' % ( schedule_thing.enter_days, util.get_date_string(schedule_thing.entry_boundary_date) ) )
def get_expected_config(enterdays): return ( '%s | %s' % ( enterdays, util.get_date_string( date.today() + relativedelta(days=enterdays) ) ) )
def test_one_entry_count(self): testdate = util.get_date_string(date.today()) schedule_lines = [ '{date} lightning energy'.format(date=testdate), ' ;; schedule ; monthly', ' blah blah blah', ] schedule_thing = ScheduleThing(schedule_lines) expected = 1 actual = len(schedule_thing.get_scheduled_entries()) self.assertEqual(expected, actual)
def test_one_entry_next_date(self): testdate = util.get_date_string(date.today()) schedule_lines = [ '{date} lightning energy'.format(date=testdate), ' ;; schedule ; monthly', ' blah blah blah', ] schedule_thing = ScheduleThing(schedule_lines) schedule_thing.get_scheduled_entries() expected = date.today() + relativedelta(months=1) actual = schedule_thing.thing_date self.assertEqual(expected, actual)
def run_it(self, before_date, after_date, schedule, enter_days=7): schedulefiledata = self.get_schedule_file( util.get_date_string(before_date), schedule, enter_days ) tempschedulefile = FileTester.write_to_temp_file( FileTester.testdir + 'run_it_schedule_file', schedulefiledata ) schedulefile = ScheduleFile(tempschedulefile) templedgerfile = FileTester.write_to_temp_file( FileTester.testdir + 'run_it_ledger_file', '' ) ledgerfile = LedgerFile(templedgerfile) scheduler = Scheduler(ledgerfile, schedulefile) scheduler.run() ledgerfile.write_file() schedulefile.write_file() schedulefile_actual = FileTester.read_file(tempschedulefile) schedulefile_expected = self.get_schedule_file( util.get_date_string(after_date), schedule, enter_days ) os.remove(templedgerfile) os.remove(tempschedulefile) self.assertEqual(schedulefile_expected, schedulefile_actual)
def save_statement_info_to_cache(self): key, cache = self.get_key_and_cache() if self.ending_balance is None: cache.pop(key, None) else: entry = { 'ending_date': util.get_date_string(self.ending_date), 'ending_balance': self.ending_balance, } cache[key] = entry try: with open(Reconciler.CACHE_FILE, 'w') as the_file: the_file.write(json.dumps(cache)) except (IOError, ValueError) as e: print('Error writing reconciler cache: {}'.format(e))
def set_statement_info(self): if self.ending_balance is not None: print( "(Enter 'cancel' to remove ending balance and set " "ending date to today.)" ) old_ending_date = self.ending_date while True: date_str = util.get_date_string(self.ending_date) new_date = self.get_response( prompt='Ending Date (YYYY/MM/DD)', old_value=date_str ) if self.cancel_statement(new_date): return try: self.ending_date = util.get_date(new_date) break except ValueError: print('*** Invalid date') new_ending_balance = None if self.ending_balance is None: old_ending_balance = None else: old_ending_balance = util.get_amount_str( self.ending_balance ) while True: new_ending_balance = self.get_response( prompt='Ending Balance', old_value=old_ending_balance ) if new_ending_balance is None: break if self.cancel_statement(new_ending_balance): return try: self.ending_balance = float( new_ending_balance.replace('$', '') ) break except ValueError: print('*** Invalid number') if new_ending_balance is not None: new_ending_balance = util.get_amount_str( self.ending_balance ) # only list and save to cache if values have changed... if old_ending_date != self.ending_date \ or old_ending_balance != new_ending_balance: self.save_statement_info_to_cache() self.list_transactions()
def list_transactions(self, args=None): args = util.parse_args(args) if args and args[0].lower() == 'all': show_all = True else: show_all = False self.current_listing = {} count = 0 for thing in self.open_transactions: if thing.thing_date > self.ending_date \ and not show_all \ and not thing.is_pending(): continue if not self.current_listing: print() # only print one buffer line at top if items count += 1 self.current_listing[str(count)] = thing count_str = '{:-4}.'.format(count) print( '{number} {date} {amount} {status:1} {payee} ' '{code:>7}'.format( number=util.get_cyan_text(count_str), date=thing.get_date_string(), code=thing.transaction_code, payee=util.get_cyan_text( thing.payee, column_width=40 ), amount=util.get_colored_amount( thing.rec_amount, 10 ), status=thing.rec_status ) ) end_date = util.get_cyan_text( util.get_date_string(self.ending_date) ) if self.ending_balance is None: end_balance = util.get_cyan_text('(not set)') else: end_balance = util.get_colored_amount(self.ending_balance) print( '\nending date: {end_date} ending balance: {end_balance} ' 'cleared: {cleared}'.format( end_date=end_date, end_balance=end_balance, cleared=util.get_colored_amount(self.total_cleared) ) ) if self.ending_balance is not None: print('to zero: {}'.format( util.get_colored_amount(self.get_zero_candidate()) )) print()
2016/10/27 two pt five e: meep 2 ! a: cash $-2.12 2016/10/27 two point zwib i: jsdklfjsdlkjflksdjfklsd a: checking $550 {next_week} three e: fweep ! a: cash $-30 {next_week} four e: snurp a: cash $-40 '''.format(next_week=util.get_date_string(next_week)) Reconciler.CACHE_FILE = FileTester.CACHE_FILE_TEST FileTester.delete_test_cache_file() class SimpleOutputTests(Redirector): def test_syntax_error(self): with FileTester.temp_input(testdata) as tempfilename: interpreter = Reconciler(LedgerFile(tempfilename, 'cash')) self.reset_redirect() bad_command = 'cthulu' interpreter.onecmd(bad_command) self.assertEqual(
def test_dates(self): self.assertEqual("1999/12/03", util.get_date_string(date(1999, 12, 3))) self.assertEqual(date(1999, 12, 3), util.get_date("1999/12/03")) self.assertTrue(util.is_valid_date("2016/10/26")) self.assertTrue(util.is_valid_date("2016/1/5")) self.assertFalse(util.is_valid_date("2016/5/5 10:23"))
def get_date_string(self): return util.get_date_string(self.thing_date)