Skip to content

Instantly share code, notes, and snippets.

View racitup's full-sized avatar

Richard Case racitup

  • Warwickshire, UK
View GitHub Profile
@racitup
racitup / html_to_text.py
Last active July 29, 2021 09:43
Extract text from html in python using BeautifulSoup4
from bs4 import BeautifulSoup, NavigableString, Tag
def html_to_text(html):
"Creates a formatted text email message as a string from a rendered html template (page)"
soup = BeautifulSoup(html, 'html.parser')
# Ignore anything in head
body, text = soup.body, []
for element in body.descendants:
# We use type and not isinstance since comments, cdata, etc are subclasses that we don't want
if type(element) == NavigableString:
@racitup
racitup / setvmdate.sh
Created May 5, 2017 08:45
Set the date of a JLR SDD V145 Diagnostics Virtualbox VM to a known date using python3 script
#! /usr/bin/env python3
# Script to reset JLR SDD VM time back
# Note the limited install authentication access is only valid within a 24 hour period
# The VM date must be within this period, not before (system date tamper detected error)
# and not afterward (expired error)
import sys
from datetime import datetime, date
from subprocess import call
@racitup
racitup / _progress.py
Last active July 8, 2021 10:25
Django db integrity check management command
import sys
import time
class ProgressBase(object):
"""
An abstract class that helps to put text on the screen and erase it again.
"""
def __init__(self):