#!/usr/bin/env python # -*- coding: utf-8 -*- """ A simple demo program that grown beyond, see locateCoordv1.py for the simpler version This should really be scale back infavor of a better backend implementation """ import wikipedia import oursql, cgi import cgitb; cgitb.enable(logdir='tracebacks') # XXX copied from ghel.py globes = ( # Only object larger than XX are included. # Moons are indented, only important/well studied are listed "Sun", # Terrestrials "Mercury", "Venus", "Earth", "Moon", "Mars", "Phobos", "Deimos", # Asteroid belt "Ceres", # Jovian Planets (Gas Giants) "Jupiter", "Ganymede", "Callisto", "Io", "Europa", "Amalthea", "Thebe", "Adrastea", "Metis",# and 55 more "Saturn", "Mimas", "Enceladus", "Tethys", "Dione", "Rhea", "Titan", "Hyperion", "Iapetus", "Phoebe", "Janus", "Epimetheus", # and 50 more # TODO needs review "Pan", "Atlas", "Pandora", "Prometheus", "Janus", "Telesto", "Calypso", "Helene", "Uranus", "Miranda", "Ariel", "Umbriel", "Titania", "Oberon", "Puck", # and 21 more # TODO needs review "Cordelia", "Ophelia", "Bianca", "Cressida", "Desdemona", "Juliet", "Portia", "Rosalind", "Belinda", "Puck", "Neptune", "Triton", "Nereid", "Proteus", # and 10 more # TODO needs review "Naiad", "Thalassa", "Despina", "Galatea", "Larissa", # Kuiper belt "Pluto", "Charon", "Haumea", "Makemake", "Eris" ) connections = {} def getConn(dbname, host=None): if not dbname.endswith('_p'): dbname+='_p' if (host,dbname) not in connections: connections[host,dbname] = oursql.connect( db=dbname, host=host or dbname.replace('_', '-')+'.userdb.toolserver.org', read_default_file="/home/dispenser/.my.cnf", charset=None, use_unicode=False ) return connections[host,dbname] def main(): form = cgi.FieldStorage() site = wikipedia.getSite() # Support older URL where dbname was the table name if form.getfirst('dbname', '').startswith('coord_'): try:site = wikipedia.Site(form.getfirst('dbname')[6:], 'wikipedia') except:pass ghel_table= "u_dispenser_p.coord_%s" % site.dbName() globe = form.getfirst('globe', '') # try: def get_form_float(name, defaultValue): try:return float(form.getfirst(name, defaultValue)) except ValueError:return defaultValue lat1 = get_form_float('lat1', 0.0) lat2 = get_form_float('lat2', 0.0) lon1 = get_form_float('lon1', 0.0) lon2 = get_form_float('lon2', 0.0) limit = 500 offset = int(get_form_float('offset', 0)) if not any((lat1, lat2, lon1, lon2)): # based on http://toolserver.org/~kolossos/wp-world/umkreis-source.php # by http://de.wikipedia.org/wiki/Benutzer:Kolossos import math range_deg = (get_form_float('range_km', 0) or 0.0001)/111.3 # lat = get_form_float('lat', 0.0) lat1 = lat - range_deg/2.0 lat2 = lat + range_deg/2.0 # lon = (get_form_float('lon', 0.0)+180) % 360 - 180 lon1 = lon - range_deg/2.0/math.cos(lat/57.27) lon2 = lon + range_deg/2.0/math.cos(lat/57.27) # Swap if relations are reversed if lat1 > lat2: lat1, lat2 = lat2, lat1 if lon1 > lon2: lon1, lon2 = lon2, lon1 except (TypeError, ValueError) as errmsg: wikipedia.output("Input error: \03{lightred}%s\03{default}"%(errmsg,)) return wikipedia.logtime('Finished reading inputs') conn = getConn(site.dbName()) cursor = conn.cursor() cursor.execute("""/* locateCoord LIMIT:30 */ SELECT DATE_FORMAT(IFNULL(UPDATE_TIME, CREATE_TIME), '%d %M %Y at %H:%i UTC') FROM information_schema.tables WHERE TABLE_SCHEMA=? AND TABLE_NAME=? """, ghel_table.partition('.')[::2]) updated = cursor.fetchall() if updated: updated=updated[0][0] wikipedia.logtime('Lookup tables Last-Modified') print """