Python调用服务接口
2016-08-18 21:52
676 查看
#! /usr/bin/env python # coding=utf-8 ###################################################################### # Author: yini.xie # Create Time: 2016-07-05 16:28:42 # Descriptioin: ###################################################################### import os import sys import time import json import urllib import urllib2 from urllib import quote from datetime import datetime pathATM = "http://192.168.217.217:4080/invoke.json" def fmtLen(value, length=7): fmt = '{0:>%d}' % (length) return fmt.format(value) def changeWithdrawRule(customerId, productCode, ruleTemplateId, ruleId, operator): service_url_s = "http://service.xxx.com/tsService/TSRuleService_1.0.0" method_s = "bindCustomerWithdrawRuleTemplate" params_s = "parameters[]=%d¶meters[]=%d¶meters[]=%d¶meters[]=%d¶meters[]=%s" % (customerId, productCode, ruleTemplateId, ruleId, operator) params_s += "&url=%s&method=%s¶meterTypes[]=int¶meterTypes[]=int¶meterTypes[]=int¶meterTypes[]=int¶meterTypes[]=java.lang.String" % (service_url_s, method_s) url_s = pathATM + "?" + quote(params_s, safe='&=') data_s = urllib2.urlopen(url_s).read() print url_s return json.loads(data_s) if __name__ == '__main__': start = datetime.now() for line in open(sys.argv[1]).xreadlines(): fields = line.strip().split() customerId = int(fields[0]) productCode = int(fields[1]) ruleTemplateId = int(fields[2]) ruleId = int(fields[3]) print "start to deal customerId = " + str(customerId) changeWithdrawRule(customerId, productCode, ruleTemplateId, ruleId, "Case") end = datetime.now()
运行Python脚本,即可调用相应的接口修改数据库数据。
python ChangeCustomerRule.py text.txt
text.txt中即为参数,以空格分隔
相关文章推荐
- Python调用服务接口
- 外部系统调用AWS ML服务的接口 - Python
- eoLinker-API_Shop_短信服务接口-调用示例代码,支持PHP、Python、Java等语言
- android 通过KSOAP调用.NET webservice中的服务接口
- [转载]戏说WSGI(Python Web服务网关接口)
- 完全使用接口方式调用WCF 服务
- Python调用C/C++的接口(Boost)
- python下调用淘宝top接口例子
- JQuery调用Rest服务接口
- osgi学习笔记4之 web客户端调用已发布的接口服务
- js调用web服务的接口和调用后台方法
- c++调用python函数接口
- 如何避免不同的用户调用接口时出现多个服务程序实例
- python实用程序-HTTP服务调用系统命令(带白名单)
- JQuery跨域调用Rest服务接口
- python调用百度短网址服务 - BitSky - 博客园
- python下调用淘宝top接口例子
- Linux系统调用接口、系统调用例程和内核服务例程之间的关系
- 戏说WSGI(Python Web服务网关接口)
- c++调用python函数接口