<commit_before># -*- coding: utf-8 -*-
# @Date    : 2014-06-27 14:36:45
# @Author  : <EMAIL>
from config import SRTP_URL, TIME_OUT
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from BeautifulSoup import BeautifulSoup
import tornado.web
import tornado.gen
import urllib
import json


class SRTPHandler(tornado.web.RequestHandler):

    def get(self):
        self.write('Herald Web Service')

    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        cardnum = self.get_argument('cardnum', default=None)

        if not cardnum:
            self.write('params lack')
        else:
            params = urllib.urlencode({'Code': cardnum})
            client = AsyncHTTPClient()
            request = HTTPRequest(SRTP_URL, body=params, method='POST',
                                  request_timeout=TIME_OUT)
            response = yield tornado.gen.Task(client.fetch, request)
            if not response.headers:
                self.write('time out')
            else:
                self.write(self.parser(response.body))
        self.finish()

    def parser(self, html):
        soup = BeautifulSoup(html)
        trs = soup.findAll('tr')

        name = trs[6].text.split(u'&nbsp;')[3].split(u'：')[1]
        cardnum = trs[6].text.split(u'&nbsp;')[1].split(u'：')[1]<commit_msg>bug fix<commit_after># -*- coding: utf-8 -*-
# @Date    : 2014-06-27 14:36:45
# @Author  : <EMAIL>
from config import SRTP_URL, TIME_OUT
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from BeautifulSoup import BeautifulSoup
import tornado.web
import tornado.gen
import urllib
import json
import re


class SRTPHandler(tornado.web.RequestHandler):

    def get(self):
        self.write('Herald Web Service')

    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        number = self.get_argument('number', default=None)

        if not number:
            self.write('params lack')
        else:
            params = urllib.urlencode({'Code': number})
            client = AsyncHTTPClient()
            request = HTTPRequest(SRTP_URL, body=params, method='POST',
                                  request_timeout=TIME_OUT)
            response = yield tornado.gen.Task(client.fetch, request)
            if not response.headers:
                self.write('time out')
            else:
                pat = re.compile('不存在', re.U)
                match = pat.search(response.body)
                if match:
                    self.write('number not exist')
                else:
                    self.write(self.parser(response.body))
        self.finish()

    def parser(self, html):
        soup = BeautifulSoup(html)
        trs = soup.findAll('tr')

        name = trs[6].text.split(u'&nbsp;')[3].split(u'：')[1]
        cardnum = trs[6].text.split(u'&nbsp;')[1].split(u'：')[1]
{'fraction_non_alphanumeric': 0.12592332043615898, 'fraction_numerical': 0.014773126978543792, 'mean_word_length': 2.2244897959183674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6310524', 'n_tokens_mistral': 904, 'n_tokens_neox': 860, 'n_words': 179}