def new_setting(key, value): settings_path, settings_filename = find_settings_file() settings = load_settings(process_markers=False) # check whether the key is already in there if key in settings.keys(): logging.info("the key is already stored.") # pre-process the value if isinstance(value, str): value.replace('\n', '\\n') settings[key] = value # store the settings with open(settings_path, 'w') as file: dumpjson(settings, file) logging.info("new settings written.")
def main(): from docopt import docopt from json import dumps as dumpjson args = docopt(__doc__) patterns = args['PATTERNS'] limit = args['--limit'] sort_limit = args['--sort-limit'] options = {} if limit is not False and limit is not None: options['limit'] = int(limit) if sort_limit is not False and sort_limit is not None: options['sort_limit'] = int(sort_limit) if args['--ignore-bad-patterns']: options['ignore_bad_patterns'] = True if args['--reverse']: options['reverse'] = True strip = str.strip entries = (strip(line) for line in iter(sys.stdin.readline, '')) terms = (Term(i, c) for i, c in enumerate(entries, start=1) if c) results = filter_entries(terms, *patterns, **options) for result in results: if args['--output-json']: line = dumpjson(result.asdict()) else: line = build_line(result, highlight=not args['--no-color']) print(line) return 0
location = place.location point_geometry = {'type': 'Point', 'coordinates': (location.lon, location.lat)} point_features.append({'type': 'Feature', 'geometry': point_geometry, 'properties': properties }) label_geometry = bbox_polygon(place.label_bbox(), osm, zoom).__geo_interface__ label_features.append({'type': 'Feature', 'geometry': label_geometry, 'properties': properties }) dumpjson({'type': 'FeatureCollection', 'features': point_features}, open(pointsfile, 'w')) dumpjson({'type': 'FeatureCollection', 'features': label_features}, open(labelsfile, 'w')) print 'Wrote %d points to %s and %s.' % (len(point_features), pointsfile, labelsfile) print '-' * 80 map = mapByCenterZoom(osm, Location(0, 0), zoom, Point(2 ** (zoom + 8), 2 ** (zoom + 8))) if zoom > 5: map = mapByCenterZoom(osm, Location(40.078, -96.987), zoom, Point(1400, 800)) map = mapByCenterZoom(osm, Location(38.889, -77.050), zoom, Point(1200, 900)) img = map.draw(False) # newimg('RGB', (map.dimensions.x, map.dimensions.y), (0xFF, 0xFF, 0xFF)) draw = drawimg(img)