fork download
  1. #!/usr/bin/python
  2.  
  3.  
  4. import os,sys
  5. from datetime import datetime,timedelta
  6. import cx_Oracle as orcl
  7. import mysql.connector as pymysql
  8. from pprint import pprint
  9.  
  10. alarms = {198087342:'2G'}
  11.  
  12. db=orcl.connect('sys','oracle','minos',mode=orcl.SYSDBA)
  13. cursor =db.cursor()
  14. cursor.execute("select position1,customattr5,to_char(alarmraisedtime_gmt,'YYYY-MM-DD HH24:MI:SS'),code from CAFFM4X.currentalarm where code in ('198087342')")
  15. p=cursor.fetchall()
  16.  
  17. print p
  18.  
  19.  
  20. conn = pymysql.connect(user='omcr',password='omcr',host='117.239.216.50',database='omcr')
  21. mycursor = conn.cursor()
  22.  
  23. for j in p:
  24. values =[j[1][0:17],j[1][0:15],j[0].split('@')[-2],'Zte',alarms[j[3]],datetime.strptime(j[2],'%Y-%m-%d %H:%M:%S')]
  25. #bts_name=j[1].split('_')[-2]
  26. print values
  27. sql=("insert ignore into omcr.currentbtsdown_sectors(sector_name,bts_name,bsc_name,make,tech,down_time) values(%s,%s,%s,%s,%s,%s)")
  28. mycursor.execute(sql,(values))
  29.  
  30.  
  31. cursor.execute("select position1,customattr5,to_char(alarmraisedtime_gmt,'YYYY-MM-DD HH24:MI:SS'),to_char(alarmclearedtime,'YYYY-MM-DD HH24:MI:SS'),code from CAFFM4X.historyalarm \
  32. where code in ('198087342') and alarmclearedtime>sysdate-3/24")
  33.  
  34. outage = cursor.fetchall()
  35.  
  36. for k in outage:
  37. values =[k[1][0:17],k[1][0:15],k[0].split('@')[-2],'Zte',alarms[k[4]],datetime.strptime(k[2],'%Y-%m-%d %H:%M:%S'),datetime.strptime(k[3],'%Y-%m-%d %H:%M:%S')]
  38. #print values
  39. sql = ("replace into omcr.currentbtsdown_sectors(sector_name,bts_name,bsc_name,make,tech,down_time,up_time) values(%s,%s,%s,%s,%s,%s,%s)")
  40. mycursor.execute(sql,(values))
  41.  
  42.  
  43. conn.commit()
  44. conn.close()
  45. # your code goes here
Success #stdin #stdout 0.02s 25676KB
stdin
Standard input is empty
stdout

import os,sys
from datetime import datetime,timedelta
import cx_Oracle as orcl
import mysql.connector as pymysql
from pprint import pprint

alarms = {198087342:'2G'}

db=orcl.connect('sys','oracle','minos',mode=orcl.SYSDBA)
cursor =db.cursor()
cursor.execute("select position1,customattr5,to_char(alarmraisedtime_gmt,'YYYY-MM-DD HH24:MI:SS'),code from CAFFM4X.currentalarm  where code in ('198087342')")
p=cursor.fetchall()

print p


conn = pymysql.connect(user='omcr',password='omcr',host='117.239.216.50',database='omcr')
mycursor = conn.cursor()

for j in p:
	values =[j[1][0:17],j[1][0:15],j[0].split('@')[-2],'Zte',alarms[j[3]],datetime.strptime(j[2],'%Y-%m-%d %H:%M:%S')]
	#bts_name=j[1].split('_')[-2]
	print values
	sql=("insert ignore into omcr.currentbtsdown_sectors(sector_name,bts_name,bsc_name,make,tech,down_time) values(%s,%s,%s,%s,%s,%s)")
        mycursor.execute(sql,(values))

	
cursor.execute("select position1,customattr5,to_char(alarmraisedtime_gmt,'YYYY-MM-DD HH24:MI:SS'),to_char(alarmclearedtime,'YYYY-MM-DD HH24:MI:SS'),code from CAFFM4X.historyalarm  \
where code in ('198087342') and alarmclearedtime>sysdate-3/24")

outage = cursor.fetchall()

for k in outage:
	values =[k[1][0:17],k[1][0:15],k[0].split('@')[-2],'Zte',alarms[k[4]],datetime.strptime(k[2],'%Y-%m-%d %H:%M:%S'),datetime.strptime(k[3],'%Y-%m-%d %H:%M:%S')]
	#print values
	sql = ("replace into omcr.currentbtsdown_sectors(sector_name,bts_name,bsc_name,make,tech,down_time,up_time) values(%s,%s,%s,%s,%s,%s,%s)")
	mycursor.execute(sql,(values))


conn.commit()
conn.close()
# your code goes here