Skip to content

Instantly share code, notes, and snippets.

@justengel
justengel / pdf_to_jpg.py
Last active June 4, 2020 19:30
Convert pdf file to jpeg.
"""
Convert PDF images to jpg files
Requirements:
* Install imagemagick http://www.imagemagick.org/download/binaries/
* Install ghostscript https://www.ghostscript.com/download.html
* pip install wand
"""
import os
from wand.image import Image
import os
import win32com.client # Requires "pip install pywin32"
__all__ = ['get_xl_properties', 'get_file_details']
# https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.tools.excel.workbook.builtindocumentproperties?view=vsto-2017
BUILTIN_XLS_ATTRS = ['Title', 'Subject', 'Author', 'Keywords', 'Comments', 'Template', 'Last Author', 'Revision Number',
'Application Name', 'Last Print Date', 'Creation Date', 'Last Save Time', 'Total Editing Time',
@justengel
justengel / qimage_label.py
Created December 11, 2019 16:10
Qt re-sizable image label.
from qtpy import QtCore, QtWidgets, QtGui
class QImageLabel(QtWidgets.QLabel):
doubleClicked = QtCore.Signal()
def loadFile(self, filename):
"""Load the image with the given filename."""
pm = QtGui.QPixmap()
with open(filename, 'rb') as f:
@justengel
justengel / emailer.py
Created December 6, 2019 15:09
Simple send_mail function to using environment variables.
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# Check older version compatibility
if not hasattr(smtplib, "SMTPNotSupportedError"):
smtplib.SMTPNotSupportedError = smtplib.SMTPDataError
import base64
from Crypto.Cipher import AES # pip install pycrypto or pycryptodome
from Crypto.Hash import SHA256
from Crypto import Random
__all__ = ['encrypt', 'decrypt']
def encrypt(key, text, **kwargs):