Shorten emoji gopher path. - annna - Annna the nice friendly bot. HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/ DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit 47e49b546f35cce6036c4af217053ac90c95c504 DIR parent dc0e577401b734bc1513078f7af1d0f1b741dc46 HTML Author: Annna Robert-Houdin <annna@bitreich.org> Date: Fri, 1 Jul 2022 20:08:13 +0200 Shorten emoji gopher path. Diffstat: M dalle-gen-emoji | 74 ++++++++++++++++---------------- 1 file changed, 37 insertions(+), 37 deletions(-) --- DIR diff --git a/dalle-gen-emoji b/dalle-gen-emoji @@ -13,54 +13,54 @@ import requests import base64 def usage(app): - app = os.path.basename(app) - print("usage: %s [-h] [::]some-emoji[:key=value...][::]" % (app), - file=sys.stderr) - sys.exit(1) + app = os.path.basename(app) + print("usage: %s [-h] [::]some-emoji[:key=value...][::]" % (app), + file=sys.stderr) + sys.exit(1) def main(args): - try: - opts, largs = getopt.getopt(args[1:], "h") - except getopt.GetoptError as err: - print(str(err)) - usage(args[0]) + try: + opts, largs = getopt.getopt(args[1:], "h") + except getopt.GetoptError as err: + print(str(err)) + usage(args[0]) - for o, a in opts: - if o == "-h": - usage(args[0]) - else: - assert False, "unhandled option" + for o, a in opts: + if o == "-h": + usage(args[0]) + else: + assert False, "unhandled option" - if len(largs) < 1: - usage(args[0]) + if len(largs) < 1: + usage(args[0]) - emoji = " ".join(largs) - emoji = emoji.strip("::") - emoji = emoji.replace(":", " ").replace(",", " ").replace("=", " ").\ - replace(".", " ").replace("/", " ") + emoji = " ".join(largs) + emoji = emoji.strip("::") + emoji = emoji.replace(":", " ").replace(",", " ").replace("=", " ").\ + replace(".", " ").replace("/", " ") - emojifile = "%s.jpg" % (emoji.replace(" ", "-")) + emojifile = "%s.jpg" % (emoji.replace(" ", "-")) - filebase = "/br/ai/dalle/dalle-results/" - emojiuribase = "gopher://bitreich.org/9/memecache/dalle/" - imguri = "http://127.0.0.1:32553/dalle" - jsonreq = {"text": emoji, "num_images": 1} + filebase = "/br/ai/dalle/dalle-results/" + emojiuribase = "gopher://bitreich.org/9/emoji/" + imguri = "http://127.0.0.1:32553/dalle" + jsonreq = {"text": emoji, "num_images": 1} - filepath = "%s%s" % (filebase, emojifile) - if not os.path.exists(filepath): - try: - answer = requests.post(imguri, json=jsonreq) - except: - return 1 + filepath = "%s%s" % (filebase, emojifile) + if not os.path.exists(filepath): + try: + answer = requests.post(imguri, json=jsonreq) + except: + return 1 - fd = open(filepath, "wb") - fd.write(base64.b64decode(answer.json()[0])) - fd.close() + fd = open(filepath, "wb") + fd.write(base64.b64decode(answer.json()[0])) + fd.close() - print("%s%s" % (emojiuribase, emojifile)) + print("%s%s" % (emojiuribase, emojifile)) - return 0 + return 0 if __name__ == "__main__": - sys.exit(main(sys.argv)) + sys.exit(main(sys.argv))