Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am jamesoutterside on github.
* I am jamesoutterside (https://keybase.io/jamesoutterside) on keybase.
* I have a public key ASBoFVr9GglrK_KJFobXH_LcrZW40NO9FwhYkqArlL5bpQo
To claim this, I am signing this object:
@jamesoutterside
jamesoutterside / create_dlm_epub_mashup.py
Created January 22, 2013 08:40
Generates an epub of mashed up content from within Dynamic Learning Maps
def create_for_mashup(request, mashups, filename):
"""
request - django request object
mashup - dict of items to mash from dlms, containin django content_type, title and link
filename - output name
"""
book = django_epub.EpubBook()
book.setTitle('Dynamic Learning Maps - Resource Mashup')
book.addCreator('Dynamic Learning Maps - https://learning-maps.ncl.ac.uk/')
book.addMeta('date', datetime.datetime.now(), event = 'publication')
@jamesoutterside
jamesoutterside / epub_inspect.py
Created January 21, 2013 13:43
Experimental code to look at an epub file and return metadata and a list of chapters
import zipfile
def get_epub_info(fname):
zip = zipfile.ZipFile(fname)
# find the contents metafile
txt = zip.read('META-INF/container.xml')
tree = etree.fromstring(txt)
cfname = tree.xpath('n:rootfiles/n:rootfile/@full-path',namespaces=NS)[0]
@jamesoutterside
jamesoutterside / stamp_image.py
Created January 21, 2013 13:19
Uses pil to stamp and image with a license banner
# stanp a license bar at the bottom of an image
from PIL import Image, ImageFont, ImageDraw
import settings
def stamp_image(in_filepath, out_filepath,text):
im = Image.open(in_filepath)
# get size
original_size = im.size
@jamesoutterside
jamesoutterside / lr_store.py
Created October 19, 2012 15:09
Sample structure of saving resources from a Learning registry node
# Sample structure of saving resources from a Learning registry node.
# The original code was developed for the RIDLR project using django,
# the code below has had all references of django removed so it will run as
# a standalone python script.
# The removed code saved/updated the resource dictonary in a database, in this case DC_MAP was used
# to map db fields to dublin core fields
# requires http://pypi.python.org/pypi/BeautifulSoup
@jamesoutterside
jamesoutterside / upload_bookmarks.py
Created October 19, 2012 13:54
Sample script to uploaded resources via the oerbookmarking.ncl.ac.uk API
#!/usr/bin/env python
############################
#
# bare bones script to upload a dict of resources to oerbookmarking.ncl.ac.uk
#
# http://oerbookmarking.ncl.ac.uk/api/
#
# Developer = james.outterside@newcastle.ac.uk
@jamesoutterside
jamesoutterside / LRHarvest.py
Created October 19, 2012 13:53
Script to export DLMs oai resources to an LR node
# Script to export DLMs oai resources to an LR node.
import urllib2
import json
import settings
from oaipmh.client import Client
from oaipmh.metadata import MetadataRegistry, oai_dc_reader
DEBUG = True
@jamesoutterside
jamesoutterside / get_bookmarks.py
Created October 19, 2012 13:51
Sample script to query oer bookmarking, used in spliced search as part of RIDLR OER project
import urllib2
import json as simplejson
BOOKMARKING_BASE_CONFIG = {'base_url':'http://oerbookmarking.ncl.ac.uk',
'api_key':'{{OER_BOOKMARKING_API_KEY}}',
'api_username':'{{OER_BOOKMARKING_API_USERNAME}}',
'api_format':'json',
'bookmark_path':'/api/v1/bookmark/'
}
@jamesoutterside
jamesoutterside / django_epub.py
Last active September 7, 2022 22:42
django epub builder
# Copyright (c) 2012, Bin Tan
# This file is distributed under the BSD Licence. See python-epub-builder-license.txt for details.
# James Outterside - Modified code from http://code.google.com/p/python-epub-builder/source/browse/trunk/epub.py to use
# use django templates instead of genshi
import itertools
import mimetypes
import os
import shutil