diff --git a/app/app.py b/app/app.py index 4bfad44..ec4d8fd 100644 --- a/app/app.py +++ b/app/app.py @@ -1,4 +1,12 @@ from flask import Flask, render_template, send_from_directory +import rfc2229 +import configparser + +# Load configuration +config = configparser.ConfigParser() +config.read('config.ini') +server = config['server']['host'] +port = config['server']['port'] app = Flask(__name__) @@ -6,9 +14,19 @@ app = Flask(__name__) def home(): return render_template('index.j2', server="everypizza.im dictd 1.13.3/rf on Linux 6.13.7-arch1-1") +@app.route('/define/') +def define(word): + client = rfc2229.RFC2229Client() + client.connect(server, port) + definition = client.define(word) + client.quit() + return render_template('define.j2', word=word, definition=definition) + @app.route('/style.css') def style(): return send_from_directory('static', 'output.css') +print(rfc2229._read_response) + if __name__ == '__main__': app.run(host="0.0.0.0", port=8080) \ No newline at end of file diff --git a/app/config.ini b/app/config.ini new file mode 100644 index 0000000..b2a9eeb --- /dev/null +++ b/app/config.ini @@ -0,0 +1,3 @@ +[server] +host = everypizza.im +port = 2628 \ No newline at end of file diff --git a/app/rfc2229.py b/app/rfc2229.py new file mode 100644 index 0000000..0b3f17f --- /dev/null +++ b/app/rfc2229.py @@ -0,0 +1,57 @@ +import socket + + +class RFC2229Client: + def __init__(self): + self.sock = None + + def connect(self, host='dict.org', port=2628): + """Establish a connection to the dictionary server.""" + self.sock = socket.create_connection((host, port)) + + """Read the response from the server.""" + response = self.sock.recv(4096).decode('utf-8') + print(response) + return response + + def define(self, word, database='!'): + """Request a definition for a word and parse the multi-line response.""" + self._send_command(f"DEFINE {database} {word}") + # Use a file-like interface for line-by-line reading. + file = self.sock.makefile('r', encoding='utf-8') + # Read the initial response header. + header = file.readline() + response_lines = [header.rstrip('\r\n')] + # Read subsequent lines until a single dot indicates the end. + for line in file: + line = line.rstrip('\r\n') + if line == '.': + break + response_lines.append(line) + return "\n".join(response_lines) + + def match(self, word, strategy='.', database='!'): + """Request matches for a word.""" + self._send_command(f"MATCH {database} {strategy} {word}") + return self._read_response() + + def quit(self): + """Close the connection to the server.""" + self._send_command("QUIT") + self.sock.close() + self.sock = None + + def _send_command(self, command): + """Send a command to the server.""" + if not self.sock: + raise ConnectionError("Not connected to the server.") + self.sock.sendall(f"{command}\r\n".encode('utf-8')) + +if __name__ == "__main__": + client = RFC2229Client() + try: + client.connect() + word = input("Enter a word to define: ") + print(client.define(word)) + finally: + client.quit() \ No newline at end of file diff --git a/app/static/output.css b/app/static/output.css index 132206c..002bebe 100644 --- a/app/static/output.css +++ b/app/static/output.css @@ -34,6 +34,8 @@ --text-sm--line-height: calc(1.25 / 0.875); --text-base: 1rem; --text-base--line-height: calc(1.5 / 1); + --text-2xl: 1.5rem; + --text-2xl--line-height: calc(2 / 1.5); --text-3xl: 1.875rem; --text-3xl--line-height: calc(2.25 / 1.875); --text-4xl: 2.25rem; @@ -452,6 +454,10 @@ .text-center { text-align: center; } + .text-2xl { + font-size: var(--text-2xl); + line-height: var(--tw-leading, var(--text-2xl--line-height)); + } .text-3xl { font-size: var(--text-3xl); line-height: var(--tw-leading, var(--text-3xl--line-height)); diff --git a/app/templates/define.j2 b/app/templates/define.j2 new file mode 100644 index 0000000..7b37ebb --- /dev/null +++ b/app/templates/define.j2 @@ -0,0 +1,30 @@ + + + + + + WebDICT + + + + + +
+ + WebDICT +
+
+ + Word: {{ word }} + Definition: {{ definition }} + +
+ + + +
+ + + \ No newline at end of file