Last active
December 25, 2015 09:59
-
-
Save imryan/6957801 to your computer and use it in GitHub Desktop.
Current weather brought to you in the CLI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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