SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import json
  2. from urllib.request import urlopen
  3.  
  4. #API_KEY = '406d9df2cc8f83cb6102eae5b850eeb4'
  5. API_KEY = 'b6907d289e10d714a6e88b30761fae22'
  6.  
  7. def wetter_in_stadt(stadt):
  8.     URL = 'https://openweathermap.org/data/2.5/weather?q=' + stadt + ',de&appid=' + API_KEY
  9.     response = urlopen(URL).read()
  10.     response = json.loads(response)
  11.     return {
  12.         'description':
  13.             response['weather'][0]['description']}
  14.  
  15. question = 'Ja' or 'ja'
  16.  
  17. while 'j' in question.lower():
  18.  
  19.  
  20.     stadt=input('Von welcher deutschen Stadt möchten Sie das Wetter wissen?')
  21.  
  22.     if stadt == 'München':
  23.          stadt = 'munich'
  24.     elif stadt == 'Köln':
  25.           stadt = 'cologne'
  26.     elif stadt == 'Hannover':
  27.          stadt = 'hanover'
  28.     wetter=wetter_in_stadt(stadt)
  29.     print('Das Wetter in', stadt, 'ist:', wetter['description'])
  30.     question = input('Wollen Sie noch eine Wetterabfrage starten?')
  31.  
  32. print('Danke, dass Sie die Wetterabfrage benutzt haben.')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top