def do_GET(self): self._set_headers() if self.path.startswith('/?'): path = parse.urlparse(self.path[2:]).path path = parse.unquote_plus(path) entries = {} package = False for entry in path.split('&'): a = entry.split('=') if a[0] == 'extras[]': if 'package' in a[1]: package = True continue entries[a[0]] = a[1] if not a[1].isdecimal() else int(a[1]) conditions = Condition.create_conditions(entries) timestamp = datetime.now().strftime('%y%m%d_%H%M%S') log = open(timestamp + '.txt', 'w') log.write(pprint.pformat(conditions) + '\n') log.close() documents = Finder.find( Finder.get_collection('localhost', 27017, 'shoulie', 'resumes'), conditions) if package: Finder.package(documents, WebSvr.base_folder, timestamp + '.zip') message = Reporter.to_html(documents, '') """ html = open(timestamp + '.html', 'w') html.write(message) html.close() """ self.wfile.write(bytes(message, 'utf8')) elif self.path == '/' or self.path.endswith('.html'): path = parse.unquote(self.path.lstrip('/')) if not path: path = 'form.html' else: path = os.path.join(WebSvr.base_folder, path.split('_')[0], path) try: f = open(path) except FileNotFoundError: self.send_error(404, 'File Not Found: ' + path) return self.wfile.write(bytes(f.read(), 'utf8')) elif self.path.endswith('.docx'): path = parse.unquote(self.path.lstrip('/')) basic = os.path.splitext(path)[0] conditions = Condition.create_conditions({'file': basic + '.html'}) documents = Finder.find( Finder.get_collection('localhost', 27017, 'shoulie', 'resumes'), conditions) """ txt = open(basic + '.txt', 'w') txt.write(pprint.pformat(documents[0]) + '\n') txt.close() """ Saver.to_doc(documents[0], path) message = '''<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style type="text/css">td, th {{ border: 1px solid black; }}</style> </head> <body> File "{}" generated </body> </html> ''' self.wfile.write(bytes(message.format(path), "utf8"))