Skip to content

Instantly share code, notes, and snippets.

View EdwardBetts's full-sized avatar

Edward Betts EdwardBetts

View GitHub Profile
@EdwardBetts
EdwardBetts / README.txt
Created February 28, 2020 14:44
Build overpass query from Wikidata SPARQL
This is an example of how to locate Wikidata items from a SPARQL query on OpenStreetMap.
The overpass_query.py Python code will run a SPARQL query and use the results to generate an OSM Overpass query.
The name of a file containing a SPARQL query should be passed to overpass_query.py as the first command line argument. For example:
python overpass_query.py query.sparql
The query will find matching objects using the OSM wikidata tag.
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
except KeyboardInterrupt:
raise
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
@EdwardBetts
EdwardBetts / pprint_color.py
Last active October 10, 2024 04:42
Python pprint with color syntax highlighting for the console
from pprint import pformat
from typing import Any
from pygments import highlight
from pygments.formatters import Terminal256Formatter
from pygments.lexers import PythonLexer
def pprint_color(obj: Any) -> None:
"""Pretty-print in color."""

Keybase proof

I hereby claim:

  • I am edwardbetts on github.
  • I am edwardbetts (https://keybase.io/edwardbetts) on keybase.
  • I have a public key whose fingerprint is FB8A CFA7 8C72 6089 C38A D026 9605 A109 8C63 B92A

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am edwardbetts on github.
  • I am edwardbetts (https://keybase.io/edwardbetts) on keybase.
  • I have a public key whose fingerprint is 26B3 E244 3423 7F38 C93A 73E6 99C8 9075 1BC4 E32B

To claim this, I am signing this object:

@EdwardBetts
EdwardBetts / untruncate.py
Created February 24, 2012 20:03
Untruncate using Google Suggest API
from urllib import quote_plus
from lxml import etree
def untruncate(s):
q = s.strip(u' .\u2026')
url = 'http://google.com/complete/search?output=toolbar&q=' + quote_plus(q.encode('latin-1'))
root = etree.parse(url).getroot()
return q + root[0][0].attrib['data'][len(q):] if len(root) else s
def demo():