Skip to content

Instantly share code, notes, and snippets.

@lawlesst
lawlesst / search_z3950.py
Created Jul 23, 2011
Sample Z39.50 search with Python.
View search_z3950.py
"""
Simple script to search a Z39.50 target using Python
and PyZ3950.
"""
from PyZ3950 import zoom
ISBNs = ['9781905017799', '9780596513986']
@lawlesst
lawlesst / cleaner.py
Created Nov 19, 2012
cleaning invalid characters from xml
View cleaner.py
def invalid_xml_remove(c):
#http://stackoverflow.com/questions/1707890/fast-way-to-filter-illegal-xml-unicode-chars-in-python
illegal_unichrs = [ (0x00, 0x08), (0x0B, 0x1F), (0x7F, 0x84), (0x86, 0x9F),
(0xD800, 0xDFFF), (0xFDD0, 0xFDDF), (0xFFFE, 0xFFFF),
(0x1FFFE, 0x1FFFF), (0x2FFFE, 0x2FFFF), (0x3FFFE, 0x3FFFF),
(0x4FFFE, 0x4FFFF), (0x5FFFE, 0x5FFFF), (0x6FFFE, 0x6FFFF),
(0x7FFFE, 0x7FFFF), (0x8FFFE, 0x8FFFF), (0x9FFFE, 0x9FFFF),
(0xAFFFE, 0xAFFFF), (0xBFFFE, 0xBFFFF), (0xCFFFE, 0xCFFFF),
(0xDFFFE, 0xDFFFF), (0xEFFFE, 0xEFFFF), (0xFFFFE, 0xFFFFF),
@lawlesst
lawlesst / .gitignore
Last active Jul 7, 2020
tdm-pilot.org gists
View .gitignore
datasets/
.ipynb*
@lawlesst
lawlesst / oaipmh_marc_harvest.py
Created Oct 28, 2011
OAI-PMH harvesting with Python
View oaipmh_marc_harvest.py
"""
Harvest MARC records via OAI-PMH.
"""
#Mostly from - http://code.google.com/p/oldmapsonline/source/browse/trunk/oai-pmh/oaipmh-client-pyoai-pymarc.py
# MarcXML reader - parsing done by pymarc
#Handle utf-8 strings
import codecs, sys
@lawlesst
lawlesst / clean_nbs.py
Last active May 21, 2020 — forked from cmoscardi/clean_nbs.py
Jupyter Notebook Output Cleaning Script
View clean_nbs.py
import io
import sys
from nbformat import read, write
# Handle either stdin or a filename
if __name__ == '__main__':
for filename in sys.argv[1:]:
print(filename, file=sys.stderr)
@lawlesst
lawlesst / fuseki-fulltext-config.ttl
Last active Apr 27, 2020
Minimal working Fuseki TDB with with full text search.
View fuseki-fulltext-config.ttl
@prefix : <http://localhost/jena_example/#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> .
@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix text: <http://jena.apache.org/text#> .
@prefix fuseki: <http://jena.apache.org/fuseki#> .
## Example of a TDB dataset and text index
## Initialize TDB
@lawlesst
lawlesst / rdflib_neptune.py
Created Mar 15, 2019
Connect RDFLib's SPARQL Store to Amazon Neptune
View rdflib_neptune.py
"""
RDFLib SPARQLStore wrapper for use with Neptune
"""
import sys
import os
import warnings
from rdflib import URIRef, Graph, ConjunctiveGraph
@lawlesst
lawlesst / rdflib_stardog.py
Last active Oct 15, 2018
Example code for working with Stardog from Python.
View rdflib_stardog.py
"""
Example code for connecting to Stardog (http://stardog.com/) with
Python's RDFLib (http://github.com/rdflib).
See longer description: http://lawlesst.github.io/notebook/rdflib-stardog.html
"""
@lawlesst
lawlesst / ldapBackEnd.py
Created Oct 19, 2010
For connecting Django auth to LDAP.
View ldapBackEnd.py
"""
Add below to settings.py
AUTHENTICATION_BACKENDS = (
'ldapBackend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
Requires python-ldap
@lawlesst
lawlesst / VIVO SPARQL Update API
Last active Aug 30, 2018
Example of using SPARQLWrapper to update data in VIVO .
View VIVO SPARQL Update API
Sample scripts for using the VIVO SPARQL Update API in PHP, Python.
https://wiki.duraspace.org/display/VIVO/The+SPARQL+Update+API