User:Geekthras

From Geohashing
Revision as of 02:06, 22 May 2008 by imported>Geekthras (shit reformatting as soon as I can figure this out :()

Woo woo! I is here! Yeah, no car = fail. I'll get there whenever possible, but that's not very often - if it's within maybe 10-15 miles of my house I'll bike. I made a script which tells me approximate distance in miles and opens up a google maps map googles. Erm.


import datetime import md5 def hexdec(s) :

   fract = 1/16.0
   z = "0123456789abcdef"
   return sum(z.index(s[i])/(16.0**(i+1))for i in xrange(len(s)))

def run(dow, date="", d = ""):

   now = datetime.datetime.now()
   if d != "" :
       now = d
   year = str(now.year)
   month = str(now.month)
   day = str(now.day)
   if len(day) == 1 :
       day = "0" +day
   if len(month) == 1 :
       month = "0" + month
   if date != "" :
       year = date.split("-")[0]
       month = date.split("-")[1]
       day = date.split("-")[2]
   string = "-".join([year, month, day,str(dow).replace(',',' ')])
   m = md5.md5(string).hexdigest()
   offset =(hexdec(m[:16]), hexdec(m[16:]))
   wkday = now.weekday()
   if wkday == 4 :
       r = run(dow, d=now+datetime.timedelta(1))
       print dist(r, (42.CENSORTED,-71.CENSORTED)), r
       
   webbrowser.open_new_tab(geturl((42.CENSORTED,-71.CENSORTED),(42+offset[0], 0-(71+offset[1]))))
   
   return (42+offset[0], 0-(71+offset[1]))

def geturl(s,e) :

   return "http://maps.google.com/maps?f=d&hl=en&geocode=" + str(s[0]) + ","+ str(s[1]) + "&saddr=" + str(s[0]) + " ,+-" + str(abs(s[1])) + "&daddr=" + str(e[0]) + ",+-" + str(abs(e[1])) + "&mra=mr&mrcr=0&dirflg=h&sll=" + str((s[0]+e[0])/2) + "," + str((s[1]+e[1])/2) + "&ie=UTF8&z=10"


import socket

import urllib s = urllib.urlopen("http://money.cnn.com/data/markets/dow/") q = s.read() s.close() import re import math import webbrowser a = run(re.findall(".*?Open.*?([0-9\.,]+).*", q)[0].replace(',',)) b = (42.CENSORTED,-71.CENSORTED) def dist(z, me) :

   dy = 26000*(z[0] - me[0])/360
   r = 26000*math.cos(math.radians(me[0]))
   dx = r*(z[1]-me[1])/360
   return ((dx**2)+(dy**2))**0.5

print dist(a, b), a print geturl(b, a)