def test_reading_file(self): fb = FitbitCache('test_user') (dates, items) = populate_fb_object(fb) fb.write() test_object = FitbitCache('test_user') test_object.read() self.assertEqual(len(test_object), dates) i = 0 for day in test_object: for item in test_object[day]: i += 1 self.assertEqual(i, items)
if __name__ == '__main__': (options, args) = parser.parse_args() if len(args) != 1: parser.print_help() exit(1) else: user_name = args[0] cache = FitbitCache(user_name) if not cache.data_exists(): print("ERROR: Could not open data for user '{}'\n".format(user_name)) parser.print_help() exit(1) else: cache.read() if options.verbose: debug = True else: debug = False if options.filename: fp = open(options.filename, 'w') if debug: print('Writing data to file: {}'.format(options.filename)) else: fp = sys.stdout dump_data(fp, debug)
if args.distance: print('will check distance values') else: print('will NOT check distance values') user_name = args.user_name cache = FitbitCache(user_name) if not cache.data_exists(): print("ERROR: Could not open data for user '{}'\n".format(user_name)) parser.print_help() exit(1) cache.read() days = cache.daylist() current_date = days[0] end_date = days[-1] print('Start = {}'.format(days[0])) print('End = {}'.format(days[-1])) print('Num Days = {}'.format(cache.num_days())) i = 0 while current_date <= end_date: s = '' day_data = cache[current_date] if 'date' not in day_data: day_data['date'] = current_date.strftime(dt_format)
try: value = float(value) except: pass cache.add_item(day, name, value) item_count += 1 return item_count if __name__ == '__main__': if len(sys.argv) != 3: print('Usage: python add_csv_to_user.py user_name csv_file.csv') exit(1) user_name = sys.argv[1] fbcache = FitbitCache(user_name) if fbcache.data_exists(): fbcache.read() fn = sys.argv[2] if not os.path.exists(fn): print('Filename {} does not exist'.format(fn)) print('Usage: python add_csv_to_user.py user_name csv_file.csv') exit(1) count = add_csv_data(fbcache, fn) fbcache.write() print('Items added = {}'.format(count))