Posts filed in Python

Introducing python-docraptor

Filed in: Python, Releases

python-docraptor is a python interface to the Doc Raptor document generation API. It is designed to mirror (well almost) the behaviour of the doc-raptor-gem, including asynchronous support. Here’s an example of it in action: from docraptor import DocRaptor docraptor = DocRaptor() resp = docraptor.create({ ‘document_content’: ‘<p>python-docraptor Test</p>’, ‘test’: True }) # PDF data is now [...]

Read more...

Excel2CSV

Filed in: Python

Small itch scratched. import csv from xlrd import open_workbook def excel_to_csv(excel_file, include=None): “”" Convert the data in the excel_file to CSV. If include is specified, only those named columns will be included in the CSV. “”" # open the Excel file wb = open_workbook(excel_file) # read each sheet in the file for s in wb.sheets(): [...]

Read more...

Find a random unbound port

Filed in: Python

find_unbound_port returns a (pseudo-)random unbound port on localhost. import random import socket # range of ports where available ports can be found PORT_RANGE = [33000,60000] def find_unbound_port(): “”" Returns an unbound port number on 127.0.0.1. “”" port = random.randint(*PORT_RANGE) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.bind((“127.0.0.1″, port)) except socket.error: port = get_port() return port if __name__ [...]

Read more...