ó
µIWc           @   sá   d  d l  m Z d  d l  m Z d  d l  m Z d  d l Td  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 e e
 ƒ Z e j d ƒ d „  ƒ Z e j d d d	 g ƒd
 „  ƒ Z e
 d k rÝ e j d d e ƒn  d S(   iÿÿÿÿ(   t   Flask(   t   request(   t   render_template(   t   *Nt   /c           C   s   t  d d t ƒS(   Ns
   input.htmlt   error(   R   t   False(    (    (    s-   /var/www/html/vec2topic/vec2topic/__init__.pyt   my_form   s    t   methodst   POSTc          C   sã  t  }  d } t j d | d t j ƒ t j ƒ  } | j t j ƒ t j d d ƒ } | j d j | ƒ t	 j
 d } | j d d	 ƒ | j d
 | d	  ƒ | j d d	 ƒ t j ƒ  } y$t j t j d d | ƒ ƒ rJt j d d | ƒ } | } t | ƒ } t | j ƒ  ƒ } | d k rAt t | | ƒ | ƒ \ } }	 }
 qÚd } n t | | ƒ } t | ƒ d k rwd g } n  | } t j d d d j | ƒ ƒ } t j d d | ƒ } t | j ƒ  ƒ } t | | ƒ \ } }	 }
 Wn t k
 r÷} d } | SX| d k rd } n d } t j j ƒ  j d ƒ } y: t j t	 j d | | | | d j t j ƒ  | ƒ ƒ Wn | j d ƒ n X| d k r˜t d d t  ƒSt d d | d t! d t j ƒ  | ƒ d d d |	 d d  j |
 ƒ ƒSd  S(!   Ns   log_vec2topic.logt   filenamet   levels   %(asctime)s %(message)ss   %b-%d-%Y %H:%M:%Si    t   textR   i2   s   Running Vec2Topic on %st    t    t   problems	   <nothing>s   [']s   ["]s   Not OKt   OKs   %Y-%m-%d %H:%M:%St   REMOTE_ADDRs   {:.2f}s	   sql errors
   input.htmlR   s   results.htmlt   resultt   timeid   g      ð?t   metrict	   num_wordss   {:,}("   R   t   loggingt   basicConfigt   INFOt	   getLoggert   setLevelt	   Formattert   handlerst   setFormatterR   t   formt   infoR   t
   validatorst   urlt   ret   subt   read_urlt   lent   splitt	   vec2topict   cleanupContentt   joint	   Exceptiont   datetimet   nowt   strftimet   sqlt   insert_databaset   environt   formatR   t   Truet   int(   R   t   LOG_FILENAMEt   loggert	   formatterR   t   time1t
   text_storet   lengthR   R   R   t   et   statusR,   (    (    s-   /var/www/html/vec2topic/vec2topic/__init__.pyt   my_form_post   sV    $		:t   __main__s   0.0.0.0t   debug(   t   flaskR    R   R   t   vec2topic_appR   R   R+   R    R.   t   __name__t   appt   routeR   R<   t   runR2   (    (    (    s-   /var/www/html/vec2topic/vec2topic/__init__.pyt   <module>   s   
!>