回文句式初探【永利集团304com】

 任何个体都有自己的品牌;存在即有价值。 —— 传承者戚

因公司专门的学问须要,引入了自动化运维,所用到的监督检查平台为zbbix3.2,前段时间正值读书python,布置接纳python调用zabbix
api接口去做些工作,如生成报表,笔者想最基本的是要得到zabbix中的数据,那是首先步,今天先体验了一把,已经打响博得获得一些数据,所以记录下来。

本实例利用python完结类似于“法国首都自来水来自海上”的中文句子造句。达成效果与利益如下:

操作系统:win10

长短计算尺算计短长除根落水狗水落根除黄金润滑油滑润金黄马上话搭头搭话上马馋嘴说瞎话瞎说嘴馋风扇打拍子拍打扇风顺耳话搭头搭话耳顺面对计算机算计对面集市落花生花落市集难为继承人承继为难世故知情人情知故世……

zabbix版本:3.2

python3.5 代码如下:

python版本:2.7.14

 import 汉语词林 import jieba import jieba.posseg # 结巴词性标注模块 # 程序编者:传习者戚 # 造句:类似于“上海自来水来自海上”的句子 # 统计运行时间计时开始 import datetime begin = datetime.datetime.now() def 单字词性: return [i.flag for i in jieba.posseg.cut][0] def 词组词性排列: s = list return list(map # 搜索双字词语AB:倒叙过来也是常用词语BA。 double_char = 汉语词林.双字列表 double_char = [doub for doub in double_char if "v" not in 词组词性排列] # 没有动词 double_char = [doub for doub in double_char if doub[0] != doub[1]] # 双字不重复 double_char = [doub for doub in double_char if doub[::-1] in 汉语词林.双字列表] # AB倒序BA也是词组 print(len(double_char), double_char) # 搜索三字词语XYZ:前两个字倒序也是词语YX。 tri_char = 汉语词林.三字列表 tri_char = [tri for tri in tri_char if "v" in 词组词性排列] # 前两个词倒序 YX 中有动词 tri_char = [tri for tri in tri_char if tri[0] != tri[1]] # 前两字不重复 tri_char = [tri for tri in tri_char if tri[1] != tri[2]] # 后两字不重复 tri_char = [tri for tri in tri_char if tri[::-1][1:] in 汉语词林.双字列表] # 前俩字倒序YX也是词组 print(len, tri_char) # 组合成句子:A B X Y Z Y X B A for d in double_char: for t in tri_char: s = d + t # A B X Y Z t = s[::-1][1:] # Y Z B A print # A B X Y Z + Y X B A # 统计运行时间计时结束 end = datetime.datetime.now() print("n运行时间:%s" % (end-begin,(end-begin).seconds))

IDE:PyCharm 2017.2.3

上述顺序还索要改正:双字词组AB和三字词组XYZ的语义关联。

         Build #PY-172.3968.37, built on September 1, 2017
         Licensed to smile

永利集团304com 1

         JRE: 1.8.0_152-release-915-b11 amd64
         JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

 

1. user.login办法赢得zabbix
server的表明密钥。官方地址:

python实现情势:

#!/usr/bin/env python2.7
#coding=utf-8
import json
import urllib2
# based url and required header
url = "http://192.168.0.217/zabbix/api_jsonrpc.php"
header = {"Content-Type":"application/json"}
# auth user and password
data = json.dumps(
{
   "jsonrpc": "2.0",
   "method": "user.login",
   "params": {
   "user": "Admin",
   "password": "zabbix"
},
"id": 0
})
# create request object
request = urllib2.Request(url,data)
for key in header:
   request.add_header(key,header[key])
# auth and get authid
try:
   result = urllib2.urlopen(request)
except urllib2.URLError as e:
   print "Auth Failed, Please Check Your Name AndPassword:",e.reason
else:
   response = json.loads(result.read())
   result.close()
   print"Auth Successful. The Auth ID Is:",response['result']

 输出结果:

永利集团304com 2

 

2.hostgroup.get方法赢得具有主机组ID。把第一步获得的表达密钥填写到“auth”中,每一趟获取数据时都亟需验证。此处是猎取zabbix
server上的具有主机组名称与ID号。

合法地址:

python完成情势:

#!/usr/bin/env python2.7
#coding=utf-8
import json
import urllib2
# based url and required header
url = "http://192.168.0.217/zabbix/api_jsonrpc.php"
header = {"Content-Type":"application/json"}
# request json
data = json.dumps(
{
   "jsonrpc":"2.0",
   "method":"hostgroup.get",
   "params":{
       "output":["groupid","name"],
   },
   "auth":"4c38be0e3cda326c63e4f4be8f73a056", # theauth id is what auth script returns, remeber it is string
   "id":1,
})
# create request object
request = urllib2.Request(url,data)
for key in header:
   request.add_header(key,header[key])
# get host list
try:
   result = urllib2.urlopen(request)
except urllib2.URLError as e:
   if hasattr(e, 'reason'):
       print 'We failed to reach a server.'
       print 'Reason: ', e.reason
   elif hasattr(e, 'code'):
       print 'The server could not fulfill the request.'
       print 'Error code: ', e.code
else:
   response = json.loads(result.read())
   result.close()
   print "Number Of Hosts: ", len(response['result'])
   #print response
   for group in response['result']:
       print "Group ID:",group['groupid'],"tGroupName:",group['name']

 输出结果:

永利集团304com 3

发表评论

电子邮件地址不会被公开。 必填项已用*标注