Created
March 22, 2022 05:46
-
-
Save an0ndev/42031e03fef6424550baba83009c70c0 to your computer and use it in GitHub Desktop.
Pro Nerdle Generator: unrestricted Pro Nerdle puzzle generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Pro Nerdle Generator: unrestricted Pro Nerdle puzzle generator | |
| # Eric Reed (github.com/an0ndev) 2021 | |
| import tkinter, tkinter.messagebox | |
| import requests | |
| class ProNerdleGenerator: | |
| def __init__ (self): | |
| self.name = "Pro Nerdle Generator" | |
| self.root = tkinter.Tk () | |
| self.root.title (self.name) | |
| self.soln_label = tkinter.Label (self.root, text = "Solution") | |
| self.soln_label.grid (row = 0, column = 0) | |
| self.soln_var = tkinter.StringVar () | |
| self.soln_input = tkinter.Entry (self.root, textvariable = self.soln_var) | |
| self.soln_input.grid (row = 0, column = 1) | |
| self.rows_label = tkinter.Label (self.root, text = "Number of rows") | |
| self.rows_label.grid (row = 1, column = 0) | |
| self.rows_var = tkinter.StringVar () | |
| self.rows_input = tkinter.Entry (self.root, textvariable = self.rows_var) | |
| self.rows_input.grid (row = 1, column = 1) | |
| self.submit_btn = tkinter.Button (self.root, text = "Generate", command = self.submit) | |
| self.submit_btn.grid (row = 2, columnspan = 2) | |
| self.url_var = tkinter.StringVar () | |
| self.url_label = tkinter.Label (self.root, text = "URL") | |
| self.url_label.grid (row = 3, column = 0) | |
| self.url_input = tkinter.Entry (self.root, textvariable = self.url_var) | |
| self.url_input.grid (row = 3, column = 1) | |
| self.initial_copy_button_text = "Copy to clipboard" | |
| self.copy_button = tkinter.Button (self.root, text = self.initial_copy_button_text, command = self.copy) | |
| self.copy_button.grid (row = 4, columnspan = 2) | |
| self.operators_table = {'+': "P", '-': "S", '*': "M", '/': "D", '^': "E", '(': "O", ')': "C", '!': "F", '.': "d"} | |
| self.url = None | |
| def submit (self): | |
| solution = self.soln_var.get () | |
| if solution == "": | |
| tkinter.messagebox.showerror (self.name, "Empty solution!") | |
| return | |
| rows_count_str = self.rows_var.get () | |
| try: | |
| rows_count = int (rows_count_str) | |
| except ValueError: | |
| tkinter.messagebox.showerror (self.name, "Invalid number of rows!") | |
| return | |
| resp = requests.get ("https://api.nerdlegame.com/encode/encodeSolution", params = {"solution": solution}) | |
| if resp.status_code != 200: | |
| tkinter.messagebox.showerror (self.name, f"Request failed: {resp.text}") | |
| return | |
| encoded_solution = resp.text | |
| self.url = f"https://pro.nerdlegame.com/{encoded_solution}/{rows_count}/{self._gen_excluded_operators_str (solution)}" | |
| self.url_var.set (self.url) | |
| def _gen_excluded_operators_str (self, _soln: str) -> str: return "".join (op_val if op_key not in _soln else "" for op_key, op_val in self.operators_table.items ()) | |
| def copy (self): | |
| if self.url is not None: | |
| self.root.clipboard_clear () | |
| self.root.clipboard_append (self.url) | |
| self.copy_button.configure (text = "Copied!") | |
| self.copy_button.after (5000, lambda: self.copy_button.configure (text = self.initial_copy_button_text)) | |
| def run (self): self.root.mainloop () | |
| if __name__ == "__main__": ProNerdleGenerator ().run () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment