Skip to content

Instantly share code, notes, and snippets.

@imryan
Last active December 25, 2015 09:59
Show Gist options
  • Select an option

  • Save imryan/6957801 to your computer and use it in GitHub Desktop.

Select an option

Save imryan/6957801 to your computer and use it in GitHub Desktop.
Current weather brought to you in the CLI.
# shellcast
# Main application file
import sources
import pywapi
import string
def main():
print("Welcome to shellcast.\n\nNote: If your zipcode begins with a 0, type the zipcode without the zero.\n")
zipcode = input("zipcode> ")
zipcode = str(zipcode)
if (len(zipcode) < 5):
new_zip = []
new_zip.append('0')
new_zip.append(zipcode)
zipcode = ''.join(new_zip)
fetch(zipcode)
else:
fetch(zipcode)
def fetch(zipcode):
if (len(zipcode) > 5):
print("[error] zipcode is invalid.\n")
exit(1)
else:
print(sources.weather_com(zipcode))
main()
# shellcast
# Fetch weather from requested sources
from pyzipcode import ZipCodeDatabase
import pywapi
import string
def weather_com(zipcode):
result = pywapi.get_weather_from_weather_com(zipcode, 'imperial')
condition = string.lower(result['current_conditions']['text'])
temperature = string.lower(result['current_conditions']['temperature'])
zcdb = ZipCodeDatabase()
zipcode = zcdb[zipcode]
msg = "\n" + zipcode.city + ", " + zipcode.state + "\n" + temperature + " F\n" + condition.capitalize() + "\n"
return msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment