Created
March 22, 2024 05:43
-
-
Save technusm1/1ca9d0e01489402a7b72f7691acd7e3c to your computer and use it in GitHub Desktop.
Tinymesh stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import readline | |
def main(log_file_path, markdown_file_path): | |
print("Enter a command (af <text>, as <text>, cc, cl) or press Ctrl + D to exit.") | |
while True: | |
try: | |
user_input = input("\n\033[94m> \033[0m") | |
except EOFError: | |
print("\033[91m\nExiting the application.\033[0m") | |
break | |
except KeyboardInterrupt: | |
continue | |
if user_input.startswith("af"): | |
heading_text = user_input[3:] | |
with open(markdown_file_path, 'a') as markdown_file: | |
markdown_file.write(f"\n# {heading_text} (Failure)") | |
elif user_input.startswith("as"): | |
heading_text = user_input[3:] | |
with open(markdown_file_path, 'a') as markdown_file: | |
markdown_file.write(f"\n# {heading_text} (Success)") | |
elif user_input == "cc": | |
with open(log_file_path, 'r') as log_file: | |
log_content = log_file.read() | |
with open(markdown_file_path, 'a') as markdown_file: | |
markdown_file.write(f"\n```\n{log_content}\n```\n") | |
with open(log_file_path, 'w') as log_file: | |
log_file.truncate(0) # Clear log file | |
elif user_input == "cl": | |
with open(log_file_path, 'w') as log_file: | |
log_file.truncate(0) # Clear log file | |
else: | |
print("Invalid command. Please try again.") | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("log_file_path", help="Path to the log file") | |
parser.add_argument("markdown_file_path", help="Path to the markdown file") | |
args = parser.parse_args() | |
if not (args.log_file_path and args.markdown_file_path): | |
parser.print_help() | |
print("\nCommands:") | |
print("af: append failure") | |
print("as: append success") | |
print("cc: copy contents from log and clear log") | |
print("cl: clear log") | |
else: | |
readline.parse_and_bind('set editing-mode vi') | |
print("Welcome to Log Composer - Developed by technusm1 ([email protected])") | |
main(args.log_file_path, args.markdown_file_path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import re | |
# Read the markdown file | |
with open('/mnt/c/Users/maheepkumar/Desktop/result.md', 'r') as file: | |
data = file.read() | |
# Parse the test name, result, and log traces | |
test_data = [] | |
for match in re.finditer(r'#\s*(.*?)\s*\((success|failure)\)\s*```(.*?)```', data, re.DOTALL | re.IGNORECASE): | |
test_name = match.group(1) | |
result = match.group(2) | |
log_traces = match.group(3) | |
test_data.append([test_name, result.capitalize(), log_traces.strip()]) | |
# Create a DataFrame | |
df = pd.DataFrame(test_data, columns=['Test Name', 'Result', 'Log Traces']) | |
# Write the DataFrame to an Excel file | |
df.to_excel('test_results.xlsx', index=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import socket | |
import logging | |
import sys | |
def send_message(ip_address, port=4059, message=""): | |
# Convert message to byte array | |
message_bytes = message.encode('utf-8') | |
# Create a UDP socket | |
s = socket.socket(socket.AF_UNSPEC, socket.SOCK_DGRAM) | |
try: | |
# Resolve the IP address | |
addr_info = socket.getaddrinfo(ip_address, port, socket.AF_UNSPEC, socket.SOCK_DGRAM) | |
for family, socktype, proto, canonname, sockaddr in addr_info: | |
if family in (socket.AF_INET, socket.AF_INET6): | |
# Send the message | |
s.sendto(message_bytes, sockaddr) | |
logging.info(f"Sent message to {ip_address}:{port} - {message}") | |
break | |
except socket.gaierror as e: | |
logging.error(f"Error resolving address: {e}") | |
except OSError as e: | |
logging.error(f"Error sending message: {e}") | |
finally: | |
# Close the socket | |
s.close() | |
def main(): | |
parser = argparse.ArgumentParser(description='Send UDP message to IPv4 or IPv6 address') | |
parser.add_argument('ip_address', help='IPv4 or IPv6 address to send the message to') | |
parser.add_argument('--port', type=int, default=4059, help='Port number (default: 4059)') | |
parser.add_argument('--message', default='', help='Message to send') | |
if len(sys.argv) == 1: | |
parser.print_usage() | |
sys.exit(1) | |
args = parser.parse_args() | |
# Configure logging | |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | |
# Send the message | |
send_message(args.ip_address, args.port, args.message) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment