数据清洗,处理日期以及特征以及调post形式你的api脚本

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_26566137/article/details/82593823
# def defendant_judgedoc_cnt(x):
#     if isinstance(x,unicode):
#         x =x.encode("utf8")
#     try:
#         if str(x)  == '被告':
#             return '被告裁判文书次数'
#         else:
#             return None
#     except:
#         return None
#
# def litigant_defendant_dispute_cnt(x):
#     if isinstance(x, unicode):
#         x = x.encode("utf8")
#     try:
#         if '合同' in str(x):
#             return '被告裁判文书合同纠纷次数'
#         elif '破产' in str(x):
#             return '被告裁判文书破产纠纷次数'
#         elif '著作权' in str(x) or '侵权' in str(x):
#             return '被告裁判文书著作权权属、侵权纠纷有关纠纷次数'
#         else:
#             return None
#     except:
#         return None
# print(defendant_judgedoc_cnt((u'被告')))
# print(litigant_defendant_dispute_cnt(u'被告裁判文书破产'))


# import datetime
#
# detester = u'2017-01-01'
# date = datetime.datetime.strptime(detester,'%Y-%m-%d')
# detester1 = u'2017-01-03'
# date1 = datetime.datetime.strptime(detester1,'%Y-%m-%d')
# print((date1-date).days/30.0)

'''
import datetime
# def get_survival_time_months(date1,date2):
#     try:
#         if datetime.time.strptime(date1, "%Y-%m-%d"):
#             date1 = datetime.datetime.strptime(date1,'%Y-%m-%d')
#             date2 = datetime.datetime.strptime(date2,'%Y-%m-%d')
#             return ((date2-date1).days/30.0)
#         elif datetime.time.strptime(date1, "%Y-%m"):
#             date1 = datetime.datetime.strptime(date1, '%Y-%m')
#             date2 = datetime.datetime.strptime(date2, '%Y-%m')
#             return ((date2 - date1).days / 30.0)
#         else:
#             return None
#     except:
#         return None
# print(get_survival_time_months(u'2017-08-02',u'2019-01-03'))



def get_survival_time_months(date1,date2):
    try:
        date1 = datetime.datetime.strptime(date1,'%Y-%m-%d')
        date2 = datetime.datetime.strptime(date2,'%Y-%m-%d')
        return ((date2-date1).days/30.0)
    except:
        return None
print(get_survival_time_months(u'2017-08-02',u'2019-01-03'))


def litigant_defendant_dispute_cnt(x):
    if isinstance(x, unicode):
        x = x.encode("utf8")
    if '合同' in str(x):
        return u'被告裁判文书合同纠纷次数'
    elif '破产' in str(x):
        return u'被告裁判文书破产纠纷次数'
    elif '著作权' in str(x) or '侵权' in str(x):
        return u'被告裁判文书著作权权属、侵权纠纷有关纠纷次数'
    else:
        return None

def string_toDatetime(string):
    return datetime.strptime(string, "%Y-%m-%d-%H")


# print(litigant_defendant_dispute_cnt(u'侵权'))
'''
# from test.test_black_box.api_validate.api.api_helper import ApiHelper
# from api.api_utils.api_helper import ApiHelper
import requests
from requests import Timeout

# from common.exceptions.api_exception import ApiException
# from common.exceptions.data_exception import DataException
from scpy.logger import get_logger
import json

logging = get_logger(__file__)
def post_url_dict(url, data):
    """
    get 请求返回字典表
    :param data:
    :type url str
    """
    try:
        headers = {'Content-Type': 'application/json',
                   'Connection': 'keep-alive'}

        logging.info('request:' + url)
        response = requests.post(url, data=json.dumps(data), timeout=120, headers=headers)
        logging.info('response:' + url)
        return response.json() if response.ok else {}
    except Timeout as e:
        logging.error('error url: %s', url)
        logging.error('error message: %s', e.message)
        # raise ApiException(message=u"api请求超时", code=ApiException.CODE_TIMEOUT, inner_exception=e)
    except Exception as e:
        logging.error('error url: %s', url)
        logging.error('error message: %s', e.message)
        # raise ApiException(message=u"api请求未知错误", inner_exception=e)



def network_whole_features_by_time(company_name, time_list):
    """
    网络图风险特征(有时间版本)
    see wiki http://192.168.31.157:8200/doku.php?id=huangyu:%E7%BD%91%E7%BB%9C%E5%9B%BE:%E9%A3%8E%E9%99%A9%E7%BD%91%E7%BB%9C#网络图风险特征_有时间版本
    :param time_list:
    :param company_name:
    :return:
    """
    url = 'http://192.168.31.116:11000/network/riskModel/company' + '/allLinkFeatures/byTime'
    data = {
        'companyName': company_name,
        'timeList': time_list
    }

    return post_url_dict(url, data)
a = network_whole_features_by_time('三亚昌达房地产开发有限公司',['2018-06-12'])
print(a)

猜你喜欢

转载自blog.csdn.net/sinat_26566137/article/details/82593823