Skip to content

Instantly share code, notes, and snippets.

Gabriele Alese gabalese

Block or report user

Report or block gabalese

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gabalese
gabalese / russian_roulette.py
Created Jul 23, 2016
A simple game of russian roulette played with the bbc:microbit. Reset the device when you "die"
View russian_roulette.py
from microbit import *
import random
choices = [1,2,3,4,5,6]
death_number = random.choice(choices)
click_counter = 0
while True:
display.show(Image.ASLEEP)
@gabalese
gabalese / sortncx.py
Created Mar 6, 2014
Python script to sort a NCX with no gaps in playOrder.
View sortncx.py
#! /usr/bin/env python
from lxml import etree as ET
import zipfile as ZIP
import sys
import os
namespaces = { "opf":"http://www.idpf.org/2007/opf",
"dc":"http://purl.org/dc/elements/1.1/",
"ncx":"http://www.daisy.org/z3986/2005/ncx/"
@gabalese
gabalese / checkisbn.py
Last active Aug 29, 2015
Script to check the formal validity of a given ISBN-10 or ISBN-13.
View checkisbn.py
#! /usr/bin/env python
import sys
import re
def is_valid(isbn):
sum = 0
isbn = re.sub(r"[-–—\s]", "", isbn)
# in case of isbn13
if len(isbn) == 13 and isbn[0:3] == "978" or "979": # is it a ISBN? Thanks @librarythingtim
@gabalese
gabalese / html_splitter.py
Last active Dec 26, 2015
Splits a HTML file into several smaller files, given a tag and a (optional) class name. Also fixes links in the same document.
View html_splitter.py
#! /usr/bin/env python
try:
import lxml.etree as ET
except ImportError:
from xml.etree import ElementTree as ET
from StringIO import StringIO
import sys
pub_id = "-//W3C//DTD XHTML 1.1//EN"
@gabalese
gabalese / simplewatermark.py
Created Sep 11, 2013
Basic example of how simple it is to add (slightly) less obvious watermarks to EPUB files with pyepub library and stepic
View simplewatermark.py
#! /usr/bin/env python
import os
from pyepub import EPUB # see https://github.com/gabalese/pyepub
from StringIO import StringIO
from PIL import Image
import stepic
epub = EPUB("startepub.epub","a")
@gabalese
gabalese / previewbuilder.py
Last active Dec 22, 2015
Raw script to build a quick and dirty preview from an existing full EPUB. Useful to send out previews of existing ebooks.
View previewbuilder.py
#! /usr/bin/env python
# by Gabriele Alese <gabriele@alese.it> / http://www.alese.it
# Released in Public Domain where applicable: http://creativecommons.org/publicdomain/zero/1.0/
# ***
# REQUIREMENTS:
# this script makes use of pyepub 2.0.9
# download here: https://github.com/gabalese/pyepub
# ***
# USAGE:
@gabalese
gabalese / attributealtfield.py
Last active Dec 21, 2015
Make a list of every img alt attribute in htmls and print it to stdout
View attributealtfield.py
#! /usr/bin/env python
# file: attributealtfield.py
# Make a list of every img alt attribute in htmls and print to stdout
# Usage: from the command line, python attributealtfield.py <epub.epub>
from __future__ import print_function
import os
import sys
import zipfile as ZIP
@gabalese
gabalese / tweet.py
Created Jun 3, 2013
Quick and dirty script to post a tweet from the CLI interface. Requires twitter library.
View tweet.py
#! /usr/bin/env python3
from twitter import *
import os, sys
CONSUMER_KEY = <your_consumer_key>
CONSUMER_SECRET <your_consumer_secret_key>
MY_TWITTER_CREDS = os.path.expanduser('~/.token_cache')
if not os.path.exists(MY_TWITTER_CREDS):
try:
@gabalese
gabalese / annot2html.py
Last active Dec 16, 2015
Brain-dead simple utility to dump a HTML list out of a Sony Reader annot. db. (Made on a Mac, so it look for a /Volumes/READER mount. I'm way too lazy to amend that to accept a path argv[n])
View annot2html.py
#! /usr/bin/env python
# Brain-dead simple utility to dump a list of annotations from a Sony Reader .db
# Usage: $ python annot2html.py [int number of annot to fetch]
import sys
import sqlite3 as sql
import xml.etree.ElementTree as ET
# Mac-path!
file_db = sql.connect('/Volumes/READER/Sony_Reader/database/books.db')
You can’t perform that action at this time.