diff --git a/script.py b/script.py index 239a655..da0bc70 100644 --- a/script.py +++ b/script.py @@ -49,7 +49,7 @@ def run_command(command, based = False): # Run all the commands for getting the logs, and assign to variables -print("start running the log commands"); +print("Commands: statics") # These vars cannot go back in time if not time_ago_arg: @@ -66,29 +66,24 @@ else: ip_address = False time_since_last_boot = False - +print("Commands: packages") dpkg_date = now.strftime("%Y-%m-%d") list_package_installs = subprocess.run(["grep","-E", dpkg_date + '.*install|install.*' + dpkg_date, "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8').splitlines() list_package_upgrade = subprocess.run(["grep","-E", dpkg_date + '.*upgrade|upgrade.*' + dpkg_date, "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8').splitlines() list_package_remove = subprocess.run(["grep","-E", dpkg_date + '.*remove|remove.*' + dpkg_date, "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8').splitlines() -print("start running the service commands, this sometimes takes longer"); - +print("Commands: journalctl, this sometimes takes longer"); -# journalctl --utc - -journal_today = run_command(["sudo", "journalctl","_COMM=useradd", "_COMM=usermod", "_COMM=userdel","_COMM=groupremove", "_COMM=groupadd","-r"] + get_journalctl_on()).splitlines() +journal_today = run_command(["sudo", "journalctl","_COMM=useradd", "_COMM=usermod", "_COMM=userdel","_COMM=groupremove", "_COMM=groupadd","-r", "--utc"] + get_journalctl_on()).splitlines() # TODO this is not working with the time ago. name should be grepped from user_created_today last_user_added = subprocess.run(["sudo", "journalctl","_COMM=useradd","-r","-n", "1" , "--output-fields=MESSAGE"], capture_output=True) last_user_added_name = run_command(['grep', '-Po', "(?<=name)\W*\K[^ ]*"], based=last_user_added.stdout) users_created_today = run_command(["sudo", "journalctl","_COMM=useradd","-r"] + get_journalctl_on()).splitlines() - journal_today = subprocess.run(["sudo", "journalctl","_COMM=systemd-logind","_COMM=useradd", "_COMM=usermod", "_COMM=userdel","_COMM=groupremove", "_COMM=groupadd","-r"] + get_journalctl_on(), check=True, capture_output=True) -kitchen_services = run_command(["sudo", "journalctl", "-u", "kitchen-stove.service", "-u", "kitchen-bin.service", "-u", "kitchen-fridge.service", "-r", "-n"] + get_journalctl_on()).splitlines() try: groups_created = subprocess.run(['grep','groupadd'], capture_output=True, input=journal_today.stdout).stdout.decode('UTF-8').strip().splitlines() @@ -101,15 +96,17 @@ try: except subprocess.CalledProcessError as e: raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output)) +print("Commands: services, this sometimes takes longer"); +kitchen_services = run_command(["sudo", "journalctl", "-u", "kitchen-stove.service", "-u", "kitchen-bin.service", "-u", "kitchen-fridge.service", "-r", "-n"] + get_journalctl_on()).splitlines() - +print("Got all commands data"); # loading the jinja template environment -print("Filling the template"); env = Environment(loader=FileSystemLoader("/home/xpub/www/html/tl-dr/templates")) # loading the template (use template.jinja when generating the html webview) template = env.get_template("book.jinja") +print("rendering the template") # rendering the template and storing the resultant text in variable output output = template.render( now = now.strftime("%B %dth %Y"), @@ -135,7 +132,7 @@ output = template.render( ) -print("Output the files"); +print("Storing the files"); # Export the html as book.html, which is used as an input for pandoc with open(f"/home/xpub/www/html/tl-dr/book_{time_ago_arg}.html", "w") as f: print(output, file=f) @@ -144,8 +141,4 @@ with open(f"/home/xpub/www/html/tl-dr/book_{time_ago_arg}.html", "w") as f: else: print("i did not create an epub since im an oldie") print("Finished"); - -# At the moment, we are not storing logs in the log folder anymore -# with open(log_file_name, "w") as f: -# print(output, file=f) \ No newline at end of file