コード例 #1
0
def get_weather():
    city = id = ""
    lat, lon = wa.get_current_lat_lon()
    # Call api from www.openweathermap.org
    w, f = wa.get_weather_dicts(lat, lon, city, id)
    w = wa.get_current_weather(w)
    f = wa.get_forecast(f)
    fmt = "{}\n{}\nWeather information provided by openweathermap.org"
    return fmt.format(w, f)
コード例 #2
0
def check_icons(icons, path):
    # Loop list of needed icons
    for icon in icons:
        # Check if we have them
        if os.path.exists(icon):
            continue
        # If any are missing then download what icons are needed
        print('=' * 20)
        wa.download_weather_icons(path)
コード例 #3
0
def check_icons(icons, path):
  # Loop list of needed icons
  for icon in icons:
  # Check if we have them
    if os.path.exists(icon):
      continue
    # If any are missing then download what icons are needed
    print('=' * 20)
    wa.download_weather_icons(path)
コード例 #4
0
def get_weather():
    print('=' * 20)
    try:
        w, f = wa.pick_your_weather()
    except requests.ConnectionError or ValueError:
        print('=' * 20)
        sys.exit('Weather servers are busy. Try again in a few minutes...')

    # Call functions in WeatherAnywhere.py to retrieve weather data
    weather = wa.get_current_weather(w, f)
    forecast = wa.get_forecast(w, f)
    fmt = '{}\n\nWeather information provided by api.wunderground.com'
    forecast = fmt.format(forecast)
    return w, f, weather, forecast
コード例 #5
0
def get_weather():
  print('=' * 20)
  try:
    w, f = wa.pick_your_weather()
  except requests.ConnectionError or ValueError:
    print('=' * 20)
    sys.exit('Weather servers are busy. Try again in a few minutes...')

  # Call functions in WeatherAnywhere.py to retrieve weather data
  weather = wa.get_current_weather(w)
  forecast = wa.get_forecast(w,f)
  fmt = '{}\n\nWeather information provided by api.wunderground.com'
  forecast = fmt.format(forecast)
  return w, f, weather, forecast
コード例 #6
0
    def alerts(self, sender):
        # Retrieve alerts
        alerts = wa.get_alerts(json_w, json_f)
        '''
    Kill sceneview to cut memory overhead, textview
    then loads much faster.  Note too that when
    textview is loaded via .present() without
    killing the sceneview, the sceneview will lock
    up after closing the textview window.
    '''
        self.remove_subview(self.scene_view)
        tv = ui.TextView()
        #w, h = ui.get_screen_size()
        #tv.frame = (0, 20, w, h / 1.2)
        tv.frame = self.bounds
        tv.border_color = 'grey'
        tv.border_width = 3
        tv.background_color = ('white')
        tv.text = alerts
        tv.editable = False
        tv.selectable = False
        tv.font = ('<system>', 9)

        self.closebutton(tv)
        self.add_subview(tv)
コード例 #7
0
 def __init__(self, in_scene):
   # Set up title bar with web view button
   b1 = ui.ButtonItem('Web View', action = self.web_weather, tint_color = 'black')
   self.right_button_items = [b1]
   # If any severe weather then set up a button to view the alerts
   if len(wa.get_alerts(json_w, json_f)) != 0:
     b2 = ui.ButtonItem('Severe Weather Alert', action = self.alerts, tint_color = 'red')
     self.left_button_items = [b2]
   self.present('full_screen')
   self.scene_view = scene.SceneView(frame = self.bounds)
   self.scene_view.scene = in_scene
   self.add_subview(self.scene_view)
コード例 #8
0
    def web_weather(self, sender):
        '''
    Kill sceneview to cut memory overhead...webview
    then loads much faster. Note too that when
    webview is loaded via .present() without
    killing the sceneview, the sceneview will lock
    up after closing the webview window.
    '''
        self.remove_subview(self.scene_view)
        wv = ui.WebView()
        #w, h = ui.get_screen_size()
        #wv.frame = (0, 20, w, h / 1.2)
        wv.frame = self.bounds
        wv.border_color = 'grey'
        wv.border_width = 3
        wv.scales_page_to_fit = True
        url = wa.get_web_weather(json_w)
        wv.load_url(url)

        self.closebutton(wv)
        self.add_subview(wv)
コード例 #9
0
        self.add_subview(wv)


if __name__ == '__main__':
    '''
  Query api for json outputs of current & extended
  weather & their respective reformatted outputs
  for use in scene.
  '''
    json_w, json_f, w, f = get_weather()

    # Format extended forecast & plot scene coordinates to display it
    txt_wrapped_f, icon_y, y1_y2 = format_plot_weather(f)

    # Current weather info for scene header
    city_name, temp_now, conditions = wa.get_scene_header(json_w)

    # Get icons & 24 hr weather data for scene
    the_icons, the_hours, the_temps, the_pops = wa.get_icons_24h_data(
        json_w, json_f, icon_path)

    # Check for any missing icons before scene runs
    check_icons(the_icons, icon_path)

    # Debug
    #for ys in y1_y2:
    #print ys
    #for ys in icon_y:
    #print ys
    #sys.exit()
コード例 #10
0
 def web_weather(self, sender):
   wa.get_web_weather(json_w)
   self.close()
コード例 #11
0
    # If any are missing then download what icons are needed
    print('=' * 20)
    wa.download_weather_icons(path)

'''
Query api for json outputs of current & extended
weather & their respective reformatted outputs for
use in scene
'''
json_w, json_f, w, f = get_weather()

# Format extended forecast & plot scene coordinates to display it
txt_wrapped_f, icon_y, y1_y2 = format_plot_weather(f)

# Current weather info for scene header
city_name, temp_now, conditions = wa.get_scene_header(json_w)

# Get icons & 24 hr weather data for scene
the_icons, the_hours, the_temps, the_pops = wa.get_icons_24h_data(json_w, json_f, icon_path)

# Check for any missing icons before scene runs
check_icons(the_icons, icon_path)

# Debug
#for ys in y1_y2:
  #print ys
#for ys in icon_y:
  #print ys
#sys.exit()

class MyScene(scene.Scene):
コード例 #12
0
def get_icons(w,f,icon_path):
  return wa.get_weather_icons(w,f,icon_path)
コード例 #13
0
def get_forecast(f):
  f = wa.get_forecast(f)
  fmt = '{}\n\nWeather information provided by openweathermap.org'
  return fmt.format(f)
コード例 #14
0
def get_weather_now(w):
  return wa.get_current_weather(w)
コード例 #15
0
def get_background_color(day):
  color = {1: [.5,.5,.5],  # Medium grey
           2: [.5,0,.5],   # Purple
           3: [.75,0,0],   # Light red
           4: [.5,0,0],    # Medium red
           5: [0,.5,.5],   # Medium green
           6: [1,.5,0],    # Orange
           7: [.25,.25,1]} # Light blue

  # Monday is 1, Sunday is 7
  r,g,b = color[day]
  return r,g,b

print('=' * 20)
try:
  w,f = wa.pick_your_weather()
except requests.ConnectionError or ValueError:
  print('=' * 20)
  sys.exit('Weather servers are busy. Try again in a few minutes...')

weather_now = get_weather_now(w)
forecast = get_forecast(f)
icon_path = './icons/'
weather_icons = get_icons(w,f, icon_path)

# Loop list of needed icons
for icon in weather_icons:
  # Check if we have them
  if os.path.exists(icon):
    continue
  # If missing then download what
コード例 #16
0
 def web_weather(self, sender):
     wa.get_web_weather(json_w)
     self.close()