def create(image_src_dir, badge_dst_dir, kind, username, email): """Create JSON and PNG for a new badge.""" # Paths image_src_path, image_dst_path, json_dst_path = \ make_paths(image_src_dir, badge_dst_dir, kind, username) # When is the badge being created? when = datetime.date.today().isoformat() # Hide the email address hashedemail = hash_email_address(email, badge.SALT) # Consistent slug combining kind and username. slug = "{0}/{1}".format(kind, username) # Cache a few values. name = kind description = badge.BADGE_DESCRIPTIONS[kind][1] criteria = "/badges/index.html#{0}.html".format(kind) assertion_url = "/badges/{0}.json".format(slug) image_url = "/badges/{0}.png".format(slug) new_badge = { "uid": hashedemail, "issuedOn": when, "image": badge.set_image_url(name), "recipient": { "identity": hashedemail, "type": "email", "hashed": True, "salt": badge.SALT }, "badge": badge.set_badge_url(name), "verify": { "type": "hosted", "url": badge.set_verify_url(name, username) } } # Create and save the JSON assertion. with open(json_dst_path, "w") as writer: json.dump(new_badge, writer, indent=True, sort_keys=True) badgebakery.bake_badge("img/badges/{0}.png".format(kind), "{0}.png".format(username), slug)
def create(image_src_dir, badge_dst_dir, kind, username, email): """Create JSON and PNG for a new badge.""" # Paths image_src_path, image_dst_path, json_dst_path = \ make_paths(image_src_dir, badge_dst_dir, kind, username) # When is the badge being created? when = datetime.date.today().isoformat() # Hide the email address hashedemail = hash_email_address(email, badge.SALT) # Consistent slug combining kind and username. slug = "{0}/{1}".format(kind, username) # Cache a few values. name = kind description = badge.BADGE_DESCRIPTIONS[kind][1] criteria = "/badges/index.html#{0}.html".format(kind) assertion_url = "/badges/{0}.json".format(slug) image_url = "/badges/{0}.png".format(slug) new_badge = { "uid":hashedemail, "issuedOn":when, "image":badge.set_image_url(name), "recipient":{ "identity":hashedemail, "type":"email", "hashed":True, "salt":badge.SALT}, "badge":badge.set_badge_url(name), "verify":{ "type":"hosted", "url":badge.set_verify_url(name, username)}} # Create and save the JSON assertion. with open(json_dst_path, "w") as writer: json.dump(new_badge, writer, indent=True, sort_keys=True) badgebakery.bake_badge("img/badges/{0}.png".format(kind), "{0}.png".format(username), slug)
def main(badge_filename, save_result, baking, backups): """Main program driver.""" with open(badge_filename, "r") as f: badge = json.load(f) # Check if badge is from the older API if type(badge["badge"]) is dict: badge_name = badge["badge"]["name"] badge = update_badge_assertion(badge, badge_filename) output = json.dumps(badge, indent=True, sort_keys=True) if not save_result and not baking: print(output) else: if backups: shutil.copyfile(badge_filename, "{}.bak".format(badge_filename)) with open(badge_filename, "w") as f: f.write(output) if baking: badgebakery.bake_badge('img/badges/{0}.png'.format(badge_name.lower()), badge_filename.replace('.json', '.png'), badge_filename) else: print("Badge already on version 1.0.0")
def main(badge_filename, save_result, baking, backups): """Main program driver.""" with open(badge_filename, "r") as f: badge = json.load(f) # Check if badge is from the older API if type(badge["badge"]) is dict: badge_name = badge["badge"]["name"] badge = update_badge_assertion(badge, badge_filename) output = json.dumps(badge, indent=True, sort_keys=True) if not save_result and not baking: print(output) else: if backups: shutil.copyfile(badge_filename, "{}.bak".format(badge_filename)) with open(badge_filename, "w") as f: f.write(output) if baking: badgebakery.bake_badge( 'img/badges/{0}.png'.format(badge_name.lower()), badge_filename.replace('.json', '.png'), badge_filename) else: print("Badge already on version 1.0.0")