def main(args): folder = args.folder with_unseen = args.include_unseen with_solved = not args.exclude_solved save_config = not args.without_config domain_data = conf.default_domain_data if not folder: folder = domain_data.get('solutions') if not folder: print('Select folder') return print('Requesting...') data = get_user_missions() os.makedirs(folder, exist_ok=True) for item in data['objects']: if not item['isStarted'] and not with_unseen: continue if item['isSolved'] and not with_solved: continue mission = item['slug'] code = item['code'] description = item['description'] filename = os.path.join( folder, mission.replace('-', '_') + '.' + domain_data['extension']) output = code_for_file(mission, code, None if args.without_info else description) init_code_file(filename, output) print(filename + ' - Done') if save_config: conf.default_domain_section['solutions'] = os.path.abspath(folder) conf.save()
def main(args): print('Requesting...') data = get_user_missions() station_groups = {} for item in data['objects']: station_groups.setdefault(item['stationName'], []).append(item) for station, data in sorted(station_groups.items(), key=lambda a: a[0]): print(station) for mission in data: line = ' ' if mission['isSolved']: line += '+ ' elif mission['isStarted']: line += '- ' else: line += ' ' line += mission['slug'] print(line)
def main(args): folder = args.folder with_unseen = not args.exclude_unseen with_solved = not args.exclude_solved save_config = not args.without_config domain_data = conf.default_domain_data if not folder: folder = domain_data.get('solutions') if not folder: print('Select folder') return print('Using folder "{}"'.format(folder)) if args.configure_only: conf.default_domain_section['solutions'] = os.path.abspath(folder) conf.save() return paths = solutions_paths(folder) print('Requesting...') data = get_user_missions() for item in data['objects']: if not item['isStarted'] and not with_unseen: continue if item['isSolved'] and not with_solved: continue mission = item['slug'] code = item['code'] description = item['description'] output = code_for_file(mission, code, None if args.without_info else description) # file exist if mission not in paths: filename = gen_filename(mission, item['stationName'], folder) init_code_file(filename, output) print(filename + ' - Created') continue filename = paths[mission] f_stats = os.stat(filename) # file changed with open(filename, 'r', encoding='utf-8') as fh: local_code = fh.read() if code_for_send(local_code) == code_for_send(output): continue t_changed = time.time() - f_stats.st_mtime # local file have been changed if not item['secondsPast'] or t_changed < item['secondsPast']: print(filename + ' - Sending... ', end='') save_code(code_for_send(local_code), item['id']) print('Done') # file was changed through the web interface else: init_code_file(filename, output) print(filename + ' - Overwritten') if save_config: conf.default_domain_section['solutions'] = os.path.abspath(folder) conf.save()