Skip to main content

Posts

Python regex

 import re # Regular expression to extract the master ticket number pattern = re.compile(r'<master_ticket_number>(\d+)</master_ticket_number>') # File path file_path = 'file.xml' # Open the file and read each line with open(file_path, 'r') as file:     for line in file:         # Search for the pattern in the line         match = pattern.search(line)         if match:             # Extract and print the ticket number             ticket_number = match.group(1)             print("Master Ticket Number:", ticket_number)
Recent posts

Python Jinja2

 import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.base import MIMEBase from email import encoders from jinja2 import Environment, FileSystemLoader import os # Email configuration sender_email = "your_email@example.com" receiver_email = "recipient_email@example.com" password = "your_password" subject = "Subject of the email" # Jinja2 template configuration template_dir = "templates" template_file = "email_template.html" attachment_path = "path/to/attachment.pdf" # Load Jinja2 template env = Environment(loader=FileSystemLoader(template_dir)) template = env.get_template(template_file) template_vars = {"var1": "value1", "var2": "value2"}  # Add any variables needed in your template # Render Jinja2 template html_content = template.render(template_vars) # Create email message msg = MIMEMultipart() msg['From'] =...

Python K Medoids

def kmedoids(X, k,            starting_medoids=None,            max_steps=50):     if starting_medoids is None:         medoids = init_medoids(X, k)         print(medoids)     else:         medoids = starting_medoids             converged = False     labels = np.zeros(len(X))     i = 1         # Delete a file if it exists     if os.path.exists("KMedoids_Results.txt"):         os.remove("KMedoids_Results.txt")            f = open("KMedoids_Results.txt", "a")     start_time = time.time()     f.write('The program starting time '...