mō
X&Gc           @   s   d  k  Z  d  k Z d  k Z d  k Z d k l Z d g Z d  d  d  Z d   Z	 d   Z
 d   Z e d j o e   n d  S(   N(   s   parset   weatherc         C   sy   t  i d  } t  i d |  } t i | | |   } |  d j o t
 |  } n | i d  } t i | | |  d  S(   Nt   commonR    s   latin-1(   t   impt   find_modulet   module_locationt   load_modulet   moduleR   t   NormalizeMessaget   msgt   irct   keywordt   WeatherLookupt   resultt   encodet   DeliverMessaget   channel(   R
   R   R	   R   R   R   R   (    (    tA   /home/avleen/devel/python/googlebot2/modules/googlebot_weather.pyt   Gather   s    c         C   s  |  i d d  }  t i d  } t i d  } t i d  } t i d  } | i |   o d |  } nī | i |   o9 d |  }	 t |	  } | d j o d	 Sn d
 | } nĻ | i |   o d
 |  } n | i |   oo | i |   i d  } | i |   i d  } d | | f }	 t |	  } | d j o d Sn d
 | } n	 d |  St |  } y | i d i }
 Wn t j
 o d Sn X|
 Sd S(   sg  Lookup the weather from rssweather.com

  The location input can be in a variety of formats. We determine what kind of
  input we're looking and then craft the correct feed URL from that.

  Args:
    location: str (5 dting US zip code, 'country, city' or 3 letter IATA code.

  Returns:
    string: Either the weather report, or an error message to print.
  s   weather t    s
   ^[\d+]{5}$s	   ^[\w]{3}$s	   ^[\w]{4}$s   ^([\w]+),\s+([\w]+)$s,   http://www.rssweather.com/rss.php?zipcode=%ss=   SELECT icao FROM googlebot_airports
        WHERE iata = '%s's   Unknown airports)   http://www.rssweather.com/icao/%s/rss.phpi   i   s`   SELECT icao FROM googlebot_airports
        WHERE city = '%s'
        AND country = '%s' LIMIT 1s$   Unknown city and country combinations2   No matching regular expressions for your input: %si    s3   No weather available for this location at this timeN(   t   locationt   replacet   ret   compilet   zip_pt	   airport_pt   icao_pt   city_pt   matcht   feedt	   selectsqlt   MysqlLookupt   icaot   Nonet   groupt   cityt   countryt   parseR    t   entriest   titleR   t
   IndexError(   R   R   R"   R   R   R#   R   R    R   R   R   R   (    (    R   R      s>     
	c         C   s[   t  i   } | i |   t | i  } | d j o | i   } | d } | Sn d Sd S(   s   Connect to the database and lookup the ICAO code for the location.

  Args:
    selectsql: str (SQL SELECT string)

  Returns:
    string: ICAO code or None
  i   i    N(   R   t   SetupDBt   cursort   executeR   t   intt   rowcountt   numrowst   fetchonet   rowR   R    (   R   R-   R   R)   R/   (    (    R   R   F   s     
c          C   s   y t  i d }  Wn  t j
 o t  i d  n Xy t  i d } Wn  t j
 o t  i d  n X|  t j o t |  |  n d  S(   Ni   i   (   t   syst   argvR
   R'   t   exitt   argumentt   module_triggersR   (   R
   R3   (    (    R   t   mainZ   s    t   __main__(   R   R   R   R0   t
   feedparserR$   R4   R    R   R   R   R5   t   __name__(
   R$   R5   R   R   R0   R   R   R   R   R4   (    (    R   t   ?   s   					
	1		
