Example #1
0
from utils.geocoding import geocode

B_X = "\033[1m"
B_Z = "\033[0m"

the_command = input("What do you want to do? ")
if the_command == "hello":
    usertext = input("What is your name? ")
    print("Hello", B_X + usertext + B_Z)

elif the_command == 'geocode':
    userlocation = input("What is your location? ")
    print("OK...geocoding:", userlocation)
    georesult = geocode(userlocation)
    print(georesult) 
elif the_command == 'help':
    print(geocode.__name__)
    print(geocode.__doc__)

else:
    print("Sorry, I don't know how to respond to", the_command)
def publish(location):
    """
    What it expects:
    ----------------
    `location` is a string, representing some kind of human-readable
      geographical location

    `published_path` is a string representing a URL or filepath that
      the webbrowser can open.

    What it does:
    -------------
    Geocodes the location string.
    Then uses filtrate() to get the most relevant earthquakes
    Then produces HTML data that displays that data
    What it returns:
    ----------------
    A giant HTML string that can be written to file and opened as a webpage.
    """
    user_location = geocode(location)
    quakes = filtrate(user_location['longitude'], user_location['latitude'])

    #### let's make a big string of HTML
    giant_html_string = ""

    ##### Make the top of the page

    ##### Let's make a map, starting with the user
    gmarkers = []
    user_latlngstr = str(user_location['latitude']) + ',' + str(user_location['longitude'])
    user_marker = google_map_marker(user_latlngstr, color="0x00FF44", label='U')
    gmarkers.append(user_marker)

    for xid, quake in enumerate(quakes):
        latlngstr = str(quake['latitude']) + ',' + str(quake['longitude'])
        marker = google_map_marker(latlngstr, color="red", label=str(xid + 1))
        gmarkers.append(marker)

    bigmap_url = google_static_map_url(markers=gmarkers,
                                        center=user_latlngstr,
                                        size="800x400")



    giant_html_string += html_head(quake_count=len(quakes),
                                   location=user_location['label'],
                                   map_url=bigmap_url)



    ###################################
    ##### Now add each quake as a "row"
    for q in quakes:
        latlngstr = "%s,%s" % (q['latitude'], q['longitude'])

        # each row has a bit of narrative text
        qdistance = haversine((q['longitude'], q['latitude']),
                              (user_location['longitude'], user_location['latitude']))
        qdistance = round(qdistance, 1) # make it prettier
        narrative_html = html_narrative(time=friendly_timestamp(q['time']),
                                        place=q['place'],
                                        magnitude=q['mag'],
                                        distance=qdistance)

        # give each quake its own little map
        gmarkers = [user_marker, latlngstr]
        gmap_url = google_static_map_url(markers=gmarkers, size="500x300" )


        # For each quake/row, just throw it onto the giant_html_string
        giant_html_string += html_row(
                        map_url=gmap_url,
                        narrative=narrative_html,
                        quake_id=q['id'])
    ##### Now slap on the tail of the HTML
    giant_html_string += html_tail()

    ##### ...and we're done
    return giant_html_string
Example #3
0
from utils.geocoding import geocode

B_X = "\033[1m"
B_Z = "\033[0m"

intro = input("What do you want to do? ")
if intro == "hello":
	usertext = input("What is your name? ")
	print("Hello", B_X + usertext + B_Z)
elif intro == 'geocode':
	location = input("What is your location? ")
	print("Ok...geocoding:", location)
	georesult = geocode(location)
	print(georesult)
elif intro == 'help':
	print(geocode.__name__)   
	print(geocode.__doc__)
else:
	print("Sorry, I don't know how to respond to", intro)
Example #4
0
from utils.geocoding import geocode

B_X = "\033[1m"
B_Z = "\033[0m"

intro = input("What do you want to do? ")
if intro == "hello":
    usertext = input("What is your name? ")
    print("Hello", B_X + usertext + B_Z)
elif intro == 'geocode':
    location = input("What is your location? ")
    print("Ok...geocoding:", location)
    georesult = geocode(location)
    print(georesult)
elif intro == 'help':
    print(geocode.__name__)
    print(geocode.__doc__)
else:
    print("Sorry, I don't know how to respond to", intro)
Example #5
0
from utils.geocoding import geocode

B_X = "\033[1m"
B_Z = "\033[0m"

the_command = input("What do you want to do? ")
if the_command == "hello":
    usertext = input("What is your name? ")
    print("Hello", B_X + usertext + B_Z)

elif the_command == 'geocode':
    userlocation = input("What is your location? ")
    print("OK...geocoding:", userlocation)
    georesult = geocode(userlocation)
    print(georesult)
elif the_command == 'help':
    print(geocode.__name__)
    print(geocode.__doc__)

else:
    print("Sorry, I don't know how to respond to", the_command)
        print(report.__doc__)
        bprint("publish")
        print(publish.__doc__)


    elif command == 'bootstrap':
        bprint("Let's bootstrap the data!")
        bootstrap()

    elif command == 'wrangle':
        bprint("Let's wrangle the data!")
        wrangle()

    elif command == 'geocode':
        user_location = input(bolden("Type in a location/address to geocode: "))
        georesult = geocode(user_location)
        # normally we pass the georesult dict into
        # another function that might use it
        # but since the user is using our simple text interface
        # we can just serialize it as text and
        # print it to screen
        serialized_results = json.dumps(georesult, indent=4)
        print(serialized_results)

    elif command == 'filtrate':
        # because input() ALWAYS takes what it is given and turns it
        # into text, we have to typecast it to float before sending it
        # to filtrate()
        print("Enter longitude: ")
        lng = float(input())
        print("Enter latitude: ")
Example #7
0
from utils import geocoding

user_input = input("What do you want to do? ")
user_input = user_input.lower()

if user_input == "hello":
    user_name = input("What is your name? ")
    print("Hello", user_name)

elif user_input == "geocode":
    user_location = input("What is your location? ")
    print("Ok...geocoding:", user_location)
    result = geocoding.geocode(user_location)
    print(result)

elif user_input == "help":
    print(geocode.__name__)
    print(geocode.__doc__)

else:
    print("Sorry, I don't know how to respond to", user_input)
Example #8
0



    elif the_command == 'bootstrap':
        print("LET US BOOTSTRAP!")
        bootstrap()

    elif the_command == 'wrangle':
        print("WRANGLE THAT DATA!")
        wrangle()

    elif the_command == 'geocode':
        print("Type in a location to geocode:")
        user_location = input()
        res = geocode(user_location)
        print(json.dumps(res, indent=4))

    elif the_command == 'feedme':
        print("Enter longitude:")
        lng = input()
        print("Enter latitude:")
        lat = input()
        feedme(lng, lat)


    elif the_command == 'tellme':
        print("What is your current location?")
        user_location = input()
        tellme(user_location)
Example #9
0
from utils import geocoding

user_input = input("What do you want to do? ")
user_input = user_input.lower()

if user_input == "hello":
	user_name = input("What is your name? ")
	print("Hello", user_name)

elif user_input == "geocode":
	user_location = input("What is your location? ")
	print("Ok...geocoding:", user_location)
	result = geocoding.geocode(user_location)
	print(result)

elif user_input == "help":
	print(geocode.__name__)
	print(geocode.__doc__)

else:
	print("Sorry, I don't know how to respond to", user_input)
Example #10
0
boldx = "\033[1m"
boldy = "\033[0m"
from utils.geocoding import geocode, fetch_mapzen_response, parse_mapzen_response
command_txt= input("What do you want to do? ")

if command_txt == "hello":
	usr_txt = input("What is your name? ")
	print("Hello", boldx + usr_txt + boldy)
elif command_txt == "geocode":
	usr_coordinates = input("What is your location? ")
	print("OK...geocoding", usr_coordinates)
	georesult = geocode(usr_coordinates)
	print(georesult)
elif command_txt == 'help':
	print(geocode.__name__)
	print(geocode.__doc__)
else:
	print("Sorry, I don't know how to respond to", command_txt)