Added initial code.

This commit is contained in:
eplots 2024-07-03 21:06:41 +02:00
parent b20c62c46e
commit aa8e08afca
27 changed files with 565 additions and 8 deletions

124
python/md_to_pdf.py Normal file
View file

@ -0,0 +1,124 @@
import markdown
from weasyprint import HTML, CSS
import sys
import re
from datetime import datetime
def extract_date(markdown_text):
# Försök att hitta ett datum i formatet "Datum: YYYY-MM-DD"
match = re.search(r'\*\*Datum\*\*:\s*(\d{4}-\d{2}-\d{2})', markdown_text)
return match.group(1) if match else datetime.now().strftime('%Y-%m-%d')
def markdown_to_pdf(input_file, output_file):
# Läs markdown från fil
with open(input_file, 'r', encoding='utf-8') as file:
markdown_text = file.read()
# Extrahera datumet
date = extract_date(markdown_text)
# Konvertera markdown till HTML
html_text = markdown.markdown(markdown_text, extensions=['tables'])
# HTML-mall med anpassad teckenstorlek
html_template = f"""
<html>
<head>
<style>
@page {{
size: A4;
margin: 30mm 20mm 30mm 20mm; /* Top, Right, Bottom, Left margins */
}}
body {{
font-family: 'Arial';
padding: 13.2px;
font-size: 11px; /* Standardstorlek för brödtext */
}}
h1 {{
font-size: 24px; /* Storlek för H1 rubriker */
color: #e47203;
}}
h2 {{
font-size: 20px; /* Storlek för H2 rubriker */
color: #2b979f;
}}
h3 {{
font-size: 16px; /* Storlek för H3 rubriker */
color: #000000;
}}
#header {{
position: fixed;
left: -10mm;
top: -20mm;
text-align: left;
}}
#header img {{
width: 52.5mm;
height: auto;
opacity: 0.5;
}}
#date {{
position: fixed;
right: -10mm;
top: -20mm;
font-size: 7px;
opacity: 0.5;
}}
#date .label {{
color: orange;
}}
#date .value {{
color: black;
}}
ul, ol {{
padding-left: 20px; /* Justera detta värde för att kontrollera indraget för hela listan */
}}
ul ul, ol ol {{
padding-left: 10px; /* Justera detta värde för att kontrollera indraget för nestlade listor */
}}
li {{
margin-bottom: 3px; /* Ger ett litet mellanrum mellan listpunkter */
}}
}}
table {{
border-collapse: collapse;
width: 100%;
margin-bottom: 20px; /* Lägg till utrymme under tabellerna */
}}
th, td {{
border: 1px solid #ddd; /* Lätt grå kantlinje */
padding: 8px; /* Tillräckligt med utrymme för cellinnehållet */
text-align: left; /* Vänsterjustera all text i cellerna */
}}
th {{
background-color: #f2f2f2; /* Ljusgrå bakgrundsfärg för rubriker */
font-weight: bold;
}}
</style>
</head>
<body>
<div id='header'>
<img src='https://www.kfast.se/wp-content/themes/kfast-theme%201.0.1.3.6/images/KFast_Logotype_webb@2x.png'>
</div>
<div id='date'>
{f'<span class="label">DATUM:</span> <span class="value">{date}</span>' if date else ""} <br>
Eskilstuna Kommunfastigheter AB
</div>
{html_text}
</body>
</html>
"""
# Generera PDF
html = HTML(string=html_template)
html.write_pdf(output_file)
print(f"PDF-filen {output_file} har skapats.")
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Användning: python script.py input.md output.pdf")
else:
input_filepath = sys.argv[1]
output_filepath = sys.argv[2]
markdown_to_pdf(input_filepath, output_filepath)

33
python/ssh_honeypot.py Normal file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env python3
import socket
import paramiko
import threading
class SSHServer(paramiko.ServerInterface):
def check_auth_password(self, username: str, password: str) -> int:
print(f'{username}:{password}')
return paramiko.AUTH_FAILED
def handle_connection(client_sock):
transport = paramiko.Transport(client_sock)
server_key = paramiko.RSAKey.from_private_key_file('key')
transport.add_server_key(server_key)
ssh = SSHServer()
transport.start_server(server=ssh)
def main():
server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_sock.bind(('', 2222))
server_sock.listen(100)
while True:
client_sock, client_addr = server_sock.accept()
print(f'Connection from {client_addr[0]}:{client_addr[1]}')
t = threading.Thread(target=handle_connection, args=(client_sock,))
t.start()
if __name__ == "__main__":
main()

View file

@ -0,0 +1,51 @@
#!/usr/bin/env python3
from tasklib import TaskWarrior
import sys
tw = TaskWarrior('~/.local/share/task/')
# Parse appointments
apts = tw.tasks.filter('(status:pending or status:waiting or status:completed)', type='cal')
for apt in apts:
start = apt['scheduled']
if start is None:
sys.stderr.write(f"Apt '{apt}' has no sched date!\n")
continue
summary = str(apt)
if start.hour == 0 and start.minute == 0:
start_fmt = start.strftime("%m/%d/%Y")
print(f"{start_fmt} [1] {summary}")
else:
start_fmt = start.strftime("%m/%d/%Y @ %H:%M")
if apt['due']:
end_fmt = apt['due'].strftime("%m/%d/%Y @ %H:%M")
else:
end_fmt = strt_fmt
print(f"{start_fmt} -> {end_fmt}|{summary}")
# Parse due dates for next actions and projects
tasks = tw.tasks.filter('(status:pending or status:waiting) and (type:next or type:objective or type:standby)')
for task in tasks:
for date_type, label in [('due', "Slutdatum: "),
('scheduled', "Startdatum: ")]:
if not task[date_type]: # Skip tasks with no date
continue
start = task[date_type]
proj = "Project: " if task['type'] == "objective" else ""
summary = label + proj + str(task)
if start.hour == 0 and start.minute == 0:
start_fmt = start.strftime("%m/%d/%Y")
print(f"{start_fmt} [1] {summary}")
else:
start_fmt = start.strftime("%m/%d/%Y @ %H:%M")
end_fmt = start_fmt
print(f"{start_fmt} -> {end_fmt}|{summary}")