Skip to content

Instantly share code, notes, and snippets.

@davidallenfox
davidallenfox / dbpedia_redirects.py
Last active August 25, 2016 01:18
Accepts a term, queries DBpedia for page redirects, returns a set of synonyms.
import sys
from SPARQLWrapper import SPARQLWrapper, JSON, XML, N3, RDF
def dbpedia(term):
term = term.strip()
nterm = term.capitalize().replace(' ','_')
query = """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?label
@davidallenfox
davidallenfox / chunk-txt-sm.py
Created January 15, 2014 15:00
Converts a list of items to a chunked sitemap. Run on the command line; first argument is the text file; second argument is the amount with which to 'chunk'.
from itertools import islice
from lxml import etree, objectify
import sys
def main(filen,chunk):
increment = 0
with open(filen) as f:
while True:
increment = increment + 1
smf = "output_"+str(increment)+".xml"