from i3pystatus import IntervalModule
import pywapi
from i3pystatus.core.util import internet, require


class Weather(IntervalModule):
    """
    This module gets the weather from weather.com using pywapi module
    First, you need to get the code for the location from the www.weather.com

    .. rubric:: Available formatters

    * {current_temp}
    * {current_wind}
    * {humidity}

    Requires pywapi from PyPI.
    """

    interval = 20

    settings = (
        "location_code",
        ("colorize", "Enable color with temperature and UTF-8 icons."),
        ("units", "Celsius (metric) or Fahrenheit (imperial)"),
        "format",
    )
    required = ("location_code",)

    units = "metric"
    format = "{current_temp}"
    colorize = False
    color_icons = {
        "Fair": (u"\u2600", "#FFCC00"),
        "Cloudy": (u"\u2601", "#F8F8FF"),
        "Partly Cloudy": (u"\u2601", "#F8F8FF"),  # \u26c5 is not in many fonts
        "Rainy": (u"\u2614", "#CBD2C0"),
        "Sunny": (u"\u263C", "#FFFF00"),
        "Snow": (u"\u2603", "#FFFFFF"),
        "default": ("", None),
    }

    @require(internet)
    def run(self):
        result = pywapi.get_weather_from_weather_com(self.location_code, self.units)
        conditions = result["current_conditions"]
        temperature = conditions["temperature"]
        humidity = conditions["humidity"]
        wind = conditions["wind"]
        units = result["units"]
        color = None
        current_temp = "{t}°{d}".format(t=temperature, d=units["temperature"])
        current_wind = "{t} {s}{d}".format(t=wind["text"], s=wind["speed"], d=units["speed"])

        if self.colorize:
            icon, color = self.color_icons.get(conditions["text"],
                                               self.color_icons["default"])
            current_temp = "{t}°{d} {i}".format(t=temperature,
                                                d=units["temperature"],
                                                i=icon)
            color = color

        self.output = {
            "full_text": self.format.format(current_temp=current_temp, current_wind=current_wind, humidity=humidity),
            "color": color
        }

@@ -35,22 +35,8 @@
 ule%0A
-import pywapi%0A
 from
@@ -83,16 +83,189 @@
 equire%0A%0A
+from urllib.request import urlopen%0Aimport re%0Aimport xml.etree.ElementTree as ElementTree%0A%0AWEATHER_COM_URL = 'http://wxdata.weather.com/wxdata/weather/local/%25s?unit=%25s&cc=*'%0A
 %0Aclass W
@@ -349,28 +349,9 @@
 .com
- using pywapi module
+.
 %0A   
@@ -528,39 +528,8 @@
 y%7D%0A%0A
-    Requires pywapi from PyPI.%0A
     
@@ -789,16 +789,41 @@
 ode%22,)%0A%0A
+    location_code = None%0A
     unit
@@ -1236,129 +1236,1149 @@
     
-@require(internet)%0A    def run(self):%0A        result = pywapi.get_weather_from_weather_com(self.location_code, self.units
+def fetch_weather(self):%0A        '''Fetches the current weather from wxdata.weather.com service.'''%0A        unit = '' if self.units == 'imperial' or self.units == '' else 'm'%0A        url = WEATHER_COM_URL %25 (self.location_code, unit)%0A        with urlopen(url) as handler:%0A            try:%0A                content_type = dict(handler.getheaders())%5B'Content-Type'%5D%0A                charset = re.search(r'charset=(.*)', content_type).group(1)%0A            except AttributeError:%0A                charset = 'utf-8'%0A            xml = handler.read().decode(charset)%0A        doc = ElementTree.XML(xml)%0A        return dict(%0A            current_conditions=dict(%0A                text=doc.findtext('cc/t'),%0A                temperature=doc.findtext('cc/tmp'),%0A                humidity=doc.findtext('cc/hmid'),%0A                wind=dict(text=doc.findtext('cc/wind/t'), speed=doc.findtext('cc/wind/s'))%0A                ),%0A            units=dict(%0A                temperature=doc.findtext('head/ut'),%0A                speed=doc.findtext('head/us'),%0A                ),%0A            )%0A%0A    @require(internet)%0A    def run(self):%0A        result = self.fetch_weather(
 )%0A  
@@ -3231,16 +3231,33 @@
 .format(
+%0A                
 current_
@@ -3274,16 +3274,32 @@
 nt_temp,
+%0A               
  current
@@ -3317,16 +3317,32 @@
 nt_wind,
+%0A               
  humidit
@@ -3351,16 +3351,34 @@
 humidity
+,%0A                
 ),%0A     

Remove `pywapi` dependency from weather module