mirror of
https://github.com/chubin/wttr.in
synced 2024-11-15 08:37:12 +00:00
Merge pull request #137 from sehaas/dns_loc_record
Support DNS LOC record for @<domain> queries
This commit is contained in:
commit
4bd7928c02
2 changed files with 9 additions and 1 deletions
|
@ -14,6 +14,9 @@ from gevent.monkey import patch_all
|
||||||
from gevent.subprocess import Popen, PIPE
|
from gevent.subprocess import Popen, PIPE
|
||||||
patch_all()
|
patch_all()
|
||||||
|
|
||||||
|
import dns.resolver
|
||||||
|
from dns.exception import DNSException
|
||||||
|
|
||||||
from flask import Flask, request, render_template, send_from_directory
|
from flask import Flask, request, render_template, send_from_directory
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@ -257,7 +260,11 @@ def wttr(location = None):
|
||||||
if is_ip( location ):
|
if is_ip( location ):
|
||||||
location = get_location( location )
|
location = get_location( location )
|
||||||
if location.startswith('@'):
|
if location.startswith('@'):
|
||||||
location = get_location( socket.gethostbyname( location[1:] ) )
|
try:
|
||||||
|
loc = dns.resolver.query( location[1:], 'LOC' )
|
||||||
|
location = str("%.7f,%.7f" % (loc[0].float_latitude, loc[0].float_longitude))
|
||||||
|
except DNSException, e:
|
||||||
|
location = get_location( socket.gethostbyname( location[1:] ) )
|
||||||
|
|
||||||
location = location_canonical_name( location )
|
location = location_canonical_name( location )
|
||||||
log("%s %s %s %s" % (ip, user_agent, orig_location, location))
|
log("%s %s %s %s" % (ip, user_agent, orig_location, location))
|
||||||
|
|
|
@ -3,3 +3,4 @@ geoip2
|
||||||
geopy
|
geopy
|
||||||
requests
|
requests
|
||||||
gevent
|
gevent
|
||||||
|
dnspython
|
||||||
|
|
Loading…
Reference in a new issue