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
  46.  
  47.  
  48. # Instant Message Service using Python + MySQL
  49. # Corrected Version
  50.  
  51. import os
  52. import platform
  53. import mysql.connector
  54.  
  55. mydb = mysql.connector.connect(
  56. host="localhost",
  57. user="root",
  58. passwd="tiger",
  59. database="service"
  60. )
  61.  
  62. # ----------- CREATE TABLE ONLY IF NOT EXISTS -----------------
  63.  
  64. def create_table():
  65. try:
  66. cur = mydb.cursor()
  67. cur.execute("""
  68. CREATE TABLE IF NOT EXISTS ims(
  69. msg_id VARCHAR(10) PRIMARY KEY,
  70. rname VARCHAR(30),
  71. sname VARCHAR(30),
  72. rmail VARCHAR(50),
  73. smail VARCHAR(50),
  74. msg VARCHAR(250)
  75. )
  76. """)
  77. print("Table Checked/Created Successfully.")
  78. except Exception as e:
  79. print("Error Creating Table:", e)
  80.  
  81. # ---------------- ADD MESSAGE -----------------
  82.  
  83. def add_msg():
  84. cur = mydb.cursor()
  85. msg_id = input("Enter Message ID: ")
  86. rname = input("Enter Receiver Name: ")
  87. sname = input("Enter Sender Name: ")
  88. rmail = input("Enter Receiver Email: ")
  89. smail = input("Enter Sender Email: ")
  90. msg = input("Enter Message: ")
  91.  
  92. sql = "INSERT INTO ims(msg_id,rname,sname,rmail,smail,msg) VALUES(%s,%s,%s,%s,%s,%s)"
  93. values = (msg_id, rname, sname, rmail, smail, msg)
  94.  
  95. try:
  96. cur.execute(sql, values)
  97. mydb.commit()
  98. print("Message inserted successfully!")
  99. except Exception as e:
  100. print("Error:", e)
  101.  
  102. # --------------- SEARCH MESSAGE ----------------
  103.  
  104. def search_msg():
  105. cur = mydb.cursor()
  106. print("\nSEARCH BY:")
  107. print("1. Message ID")
  108. print("2. Sender Name")
  109. print("3. Receiver Name")
  110. print("4. Show ALL")
  111. choice = int(input("Enter choice: "))
  112.  
  113. if choice == 1:
  114. s = input("Enter Message ID: ")
  115. cur.execute("SELECT * FROM ims WHERE msg_id=%s", (s,))
  116.  
  117. elif choice == 2:
  118. s = input("Enter Sender Name: ")
  119. cur.execute("SELECT * FROM ims WHERE sname=%s", (s,))
  120.  
  121. elif choice == 3:
  122. s = input("Enter Receiver Name: ")
  123. cur.execute("SELECT * FROM ims WHERE rname=%s", (s,))
  124.  
  125. elif choice == 4:
  126. cur.execute("SELECT * FROM ims")
  127.  
  128. else:
  129. print("Invalid Choice!")
  130. return
  131.  
  132. rows = cur.fetchall()
  133.  
  134. if rows:
  135. for r in rows:
  136. print(r)
  137. else:
  138. print("No records found.")
  139.  
  140. # --------------- DELETE MESSAGE ----------------
  141.  
  142. def delete_msg():
  143. cur = mydb.cursor()
  144. ms = input("Enter Message ID to delete: ")
  145. cur.execute("DELETE FROM ims WHERE msg_id=%s", (ms,))
  146. mydb.commit()
  147.  
  148. if cur.rowcount > 0:
  149. print("Message deleted successfully.")
  150. else:
  151. print("Message ID not found.")
  152.  
  153. # ---------------- MAIN MENU ---------------------
  154.  
  155. def Main_Menu():
  156. while True:
  157. print("\n===== INSTANT MESSAGE SERVICE =====")
  158. print("1. Add New Message")
  159. print("2. Search Message")
  160. print("3. Delete Message")
  161. print("4. Exit")
  162.  
  163. try:
  164. choice = int(input("Enter your choice: "))
  165.  
  166. if choice == 1:
  167. add_msg()
  168. elif choice == 2:
  169. search_msg()
  170. elif choice == 3:
  171. delete_msg()
  172. elif choice == 4:
  173. print("Exiting Program... Thanks!")
  174. break
  175. else:
  176. print("Invalid choice! Try again.")
  177. except ValueError:
  178. print("Enter numbers only!")
  179.  
  180. # ---------------- RUN -------------------
  181.  
  182. create_table()
  183. Main_Menu()
  184.  
Success #stdin #stdout 0.03s 25604KB
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


# Instant Message Service using Python + MySQL
# Corrected Version

import os
import platform
import mysql.connector

mydb = mysql.connector.connect(
    host="localhost",
    user="root",
    passwd="tiger",
    database="service"
)

# ----------- CREATE TABLE ONLY IF NOT EXISTS -----------------

def create_table():
    try:
        cur = mydb.cursor()
        cur.execute("""
            CREATE TABLE IF NOT EXISTS ims(
                msg_id VARCHAR(10) PRIMARY KEY,
                rname VARCHAR(30),
                sname VARCHAR(30),
                rmail VARCHAR(50),
                smail VARCHAR(50),
                msg   VARCHAR(250)
            )
        """)
        print("Table Checked/Created Successfully.")
    except Exception as e:
        print("Error Creating Table:", e)

# ---------------- ADD MESSAGE -----------------

def add_msg():
    cur = mydb.cursor()
    msg_id = input("Enter Message ID: ")
    rname  = input("Enter Receiver Name: ")
    sname  = input("Enter Sender Name: ")
    rmail  = input("Enter Receiver Email: ")
    smail  = input("Enter Sender Email: ")
    msg    = input("Enter Message: ")

    sql = "INSERT INTO ims(msg_id,rname,sname,rmail,smail,msg) VALUES(%s,%s,%s,%s,%s,%s)"
    values = (msg_id, rname, sname, rmail, smail, msg)

    try:
        cur.execute(sql, values)
        mydb.commit()
        print("Message inserted successfully!")
    except Exception as e:
        print("Error:", e)

# --------------- SEARCH MESSAGE ----------------

def search_msg():
    cur = mydb.cursor()
    print("\nSEARCH BY:")
    print("1. Message ID")
    print("2. Sender Name")
    print("3. Receiver Name")
    print("4. Show ALL")
    choice = int(input("Enter choice: "))

    if choice == 1:
        s = input("Enter Message ID: ")
        cur.execute("SELECT * FROM ims WHERE msg_id=%s", (s,))

    elif choice == 2:
        s = input("Enter Sender Name: ")
        cur.execute("SELECT * FROM ims WHERE sname=%s", (s,))

    elif choice == 3:
        s = input("Enter Receiver Name: ")
        cur.execute("SELECT * FROM ims WHERE rname=%s", (s,))

    elif choice == 4:
        cur.execute("SELECT * FROM ims")

    else:
        print("Invalid Choice!")
        return

    rows = cur.fetchall()

    if rows:
        for r in rows:
            print(r)
    else:
        print("No records found.")

# --------------- DELETE MESSAGE ----------------

def delete_msg():
    cur = mydb.cursor()
    ms = input("Enter Message ID to delete: ")
    cur.execute("DELETE FROM ims WHERE msg_id=%s", (ms,))
    mydb.commit()

    if cur.rowcount > 0:
        print("Message deleted successfully.")
    else:
        print("Message ID not found.")

# ---------------- MAIN MENU ---------------------

def Main_Menu():
    while True:
        print("\n===== INSTANT MESSAGE SERVICE =====")
        print("1. Add New Message")
        print("2. Search Message")
        print("3. Delete Message")
        print("4. Exit")

        try:
            choice = int(input("Enter your choice: "))

            if choice == 1:
                add_msg()
            elif choice == 2:
                search_msg()
            elif choice == 3:
                delete_msg()
            elif choice == 4:
                print("Exiting Program... Thanks!")
                break
            else:
                print("Invalid choice! Try again.")
        except ValueError:
            print("Enter numbers only!")

# ---------------- RUN -------------------

create_table()
Main_Menu()