# -*- coding: utf-8 -*-
import cx_Oracle as cx
import requests
import json
import sys
import os
from redminelib import Redmine
from time import sleep
from retrying import retry
'''
https://pypi.org/project/cx-Oracle/5.3/#files
https://www.jianshu.com/p/f449b5199178
其中第二步自己一般都有client, 把文件复制粘贴下就可以
'''
@retry #如果出现异常,重试 ,网络异常是免不了的.很有用
def batchRun(): # 每3分钟查询一次列表
redmine = Redmine('http://xxxx/redmine', username='xxxng', password='1xxx')
project = redmine.project.get('msxxxxx0')
con = cx.connect('MxxxxxG','Dxxxx6','192xxxxre')
schema_cursor = con.cursor()
query_cursor = con.cursor()
update_cursor = con.cursor()
schema_cursor.execute('alter session set current_schema= xxx')
while 1==1 :# 每3分钟查询一次列表
print("loop begin")
sleep(30*1)# 每3分钟查询一次列表
result = query_cursor.execute(" select * from REDMINE_OPERATION_LOG_NEW where a2 is null")
for row in result:
redmine_no = row[7]
print('query redmine no :'+str(redmine_no))
issue = redmine.issue.get(redmine_no)
a1 = ''
a2 = issue.author.name
a3 = issue.custom_fields[4]['value'] #分类模块
a4 = issue.custom_fields[5]['value'] #所属部门
a5 = ''
a6 = issue.status.name.decode('utf-8')
a7 = ''.join(issue.custom_fields[6]['value'])
a8 = ''.join(issue.custom_fields[7]['value'])
a9 = ''.join(issue.custom_fields[8]['value'])
a10 = ''.join(issue.custom_fields[9]['value'])
print(a1)
print(a2)
print(a3)
print(a4)
print(a5)
print(a6)
print(a7)
print(a8)
print(a9)
print(a10)
update_cursor.execute("update REDMINE_OPERATION_LOG_NEW set a1 = :1,a2 = :2,a3 = :3,a4 = :4,a5 = :5,a6 = :6,a7 = :7,a8 = :8,a9 = :9,a10 = :10 where redmine_no = :2"
,[a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,redmine_no])
schema_cursor.close()
query_cursor.close()
update_cursor.close()
con.commit()
con.close()
#解决中文编码问题 python2.7 且 IDLE
stdi,stdo,stde=sys.stdin,sys.stdout,sys.stderr
reload(sys)
sys.setdefaultencoding('utf-8')
sys.stdin,sys.stdout,sys.stderr=stdi,stdo,stde
print sys.stdout
batchRun()
https://pypi.org/project/cx-Oracle/5.3/#files
https://www.jianshu.com/p/f449b5199178
其中第二步自己一般都有client, 把文件复制粘贴下就可以