Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pywapi
- import cgi, cgitb
- form = cgi.FieldStorage()
- print("Welcome to Python Weather Forecast script and Currency Converter script \n")
- print("To Lauch Weather Forecast press 1. For currency converter press 2. 3 to Exit \n")
- countSearch = 0
- CityList =[]
- z = input ("Chooese : ")
- while z!='3' :
- if z == '1':
- city = input ("Enter City name: " )
- if countSearch > 3:
- CityList[0] = city
- else:
- CityList.append(city)
- countSearch = countSearch + 1
- lookup = pywapi.get_location_ids(city)
- for i in lookup:
- location_id = i
- weather_com_result = pywapi.get_weather_from_weather_com(location_id)
- temp = weather_com_result['current_conditions']['temperature']
- update = weather_com_result['current_conditions']['last_updated']
- station = weather_com_result['current_conditions']['station']
- visi = weather_com_result['current_conditions']['visibility']
- wind = weather_com_result['current_conditions']['wind']['speed']
- windD = weather_com_result['current_conditions']['wind']['direction']
- windText = weather_com_result['current_conditions']['wind']['text']
- baroText = weather_com_result['current_conditions']['barometer']['direction']
- baroRead = weather_com_result['current_conditions']['barometer']['reading']
- humi = weather_com_result['current_conditions']['humidity']
- cloud = weather_com_result['current_conditions']['text']
- fore1 = weather_com_result['forecasts'][0]
- fore2 = weather_com_result['forecasts'][1]
- fore3 = weather_com_result['forecasts'][2]
- fore4 = weather_com_result['forecasts'][3]
- feel = weather_com_result['current_conditions']['feels_like']
- print ('Welcome into Python Weather Forecast script. This script is using pywAPI and weather.com for weather information \n')
- print ('The city you enter is : ' + city + '\n')
- print ('Forecast for day : ' + fore1["date"] + " " + fore1["day_of_week"])
- print ('Current Temperature in ' + city + ' is ' + temp + ' C. Last update on ' + update + ' wind ' + wind + ' km/h' + ' date from station ' + station)
- print ('Sunrise : ' + fore1["sunrise"] + ' Sunset : ' + fore1["sunset"])
- print ('For More option press following keys \n')
- print ('1 - Temperature' )
- print ('2 - Wind')
- print ('3 - Barometer')
- print ('4 - Visibility')
- print ('5 - humidity')
- print ('6 - Clouds and Rain chances')
- print ('7 - Forecast for 3 next days')
- print ('8 - Last 3 searches')
- print ('9 - exit')
- f = input ("Menu ")
- while f != '9' :
- if f == '1' :
- print('Current Temperature in ' + city + ' is ' + temp + ' C. Feels like ' + feel + ' C. ' + " highest temperature : " + fore1["high"] + " lowest : " + fore1["low"] )
- elif f == '2':
- print("Current Wind speed is " + wind + ' KM/h. From ' + windD + " " + windText )
- elif f == '3':
- print("Current Barometer date are " + baroRead + " " + baroText)
- elif f == '4':
- visiInt = float(visi)
- if visiInt > 10 :
- print("Current Visibility is perfect " + visi + " meteres" )
- elif visiInt < 10 and visi > 5:
- print("Current Visibility is okay " + visi + " meteres" )
- elif visiInt < 5 :
- print("Current Visibility is poor " + visi + " meteres" )
- elif f == '5':
- print("Current Humidity is " + humi + " % " )
- elif f == '6':
- print("Current sky condition is : " + cloud + " Chance for rain at day " + fore1["day"]["chance_precip"] + "% at night " + fore1["night"]["chance_precip"] + "%" )
- elif f == '7':
- print("Forecast for " + fore2["date"] + " " + fore2["day_of_week"] + " highest temperature will be " + fore2["high"] + " C. Lowest will be " + fore2["low"] + " C " )
- print("Sunrise at " + fore2["sunrise"] + " Sunset at " + fore2["sunset"])
- print("At Day :" + fore2["day"]["text"] + " Chance for rain: " + fore2["day"]["chance_precip"] + "%. Humidity : " + fore2["day"]["humidity"] + "%. Wind speed: " + fore2["day"]["wind"]["speed"] + "km/h")
- print("At Day :" + fore2["night"]["text"] + " Chance for rain: " + fore2["night"]["chance_precip"] + "%. Humidity : " + fore2["night"]["humidity"] + "%. Wind speed: " + fore2["night"]["wind"]["speed"] + "km/h" + "\n")
- print("Forecast for " + fore3["date"] + " " + fore3["day_of_week"] + " highest temperature will be " + fore3["high"] + " C. Lowest will be " + fore3["low"] + " C " )
- print("Sunrise at " + fore3["sunrise"] + " Sunset at " + fore3["sunset"])
- print("At Day :" + fore3["day"]["text"] + " Chance for rain: " + fore3["day"]["chance_precip"] + "%. Humidity : " + fore3["day"]["humidity"] + "%. Wind speed: " + fore3["day"]["wind"]["speed"] + "km/h")
- print("At Day :" + fore3["night"]["text"] + " Chance for rain: " + fore3["night"]["chance_precip"] + "%. Humidity : " + fore3["night"]["humidity"] + "%. Wind speed: " + fore3["night"]["wind"]["speed"] + "km/h" + "\n")
- print("Forecast for " + fore4["date"] + " " + fore4["day_of_week"] + " highest temperature will be " + fore4["high"] + " C. Lowest will be " + fore4["low"] + " C " )
- print("Sunrise at " + fore4["sunrise"] + " Sunset at " + fore4["sunset"])
- print("At Day :" + fore4["day"]["text"] + " Chance for rain: " + fore4["day"]["chance_precip"] + "%. Humidity : " + fore4["day"]["humidity"] + "%. Wind speed: " + fore4["day"]["wind"]["speed"] + "km/h")
- print("At Day :" + fore4["night"]["text"] + " Chance for rain: " + fore4["night"]["chance_precip"] + "%. Humidity : " + fore4["night"]["humidity"] + "%. Wind speed: " + fore4["night"]["wind"]["speed"] + "km/h" + "\n")
- elif f == '8':
- cities = str(CityList)
- print ("You searched for this Cities : " + cities)
- elif f == '9':
- print("Goodbay, thank you for using this app")
- f = 9
- else :
- print ('Wrong key, try again')
- print("City you entered : " + city)
- print ('1 - Temperature' )
- print ('2 - Wind')
- print ('3 - Barometer')
- print ('4 - Visibility')
- print ('5 - humidity')
- print ('6 - Clouds and Rain chances')
- print ('7 - Forecast for 3 next days')
- print ('8 - Last 3 searches')
- print ('9 - exit')
- f = input ("Menu ")
- elif z == '2':
- import requests
- a = input('Enter currency to convert from? ')
- a = a.upper()
- b = input('Enter currency to convert to? ')
- b = b.upper()
- c = float(input('Enter value to convert? '))
- url = ('https://currency-api.appspot.com/api/%s/%s.json') % (a, b)
- print(url)
- r = requests.get(url)
- rate = (r.json()['rate'])
- print("Current rate of exchange is:" + str(rate))
- result = c*float(r.json()['rate'])
- print(str(c) + " " + a + " is " + str(result) + " " + b )
- elif z == '3':
- exit()
- else:
- print('Wrong key')
- z = input ("To Lauch Weather Forecast press 1. For currency converter press 2. 3 to Exit \n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement