Advertisement
Guest User

test

a guest
Apr 12th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.34 KB | None | 0 0
  1. '''
  2. import platform
  3.  
  4.  
  5. class Test:
  6.    def system_data(self):
  7.        global get_data
  8.        var =  0
  9.        variable = 'variable'
  10.        for value in zip(['system   ','node     ','release_version  ','version  ','machine  ','processor'],platform.uname()):
  11.            var = var + 1
  12.            data = value[1]
  13.            get_data = variable+str(var)+' = '+str(data)
  14.            print(get_data)          
  15. obj = Test()
  16. data=  obj.system_data()
  17. '''
  18.  
  19. '''
  20. class Test:
  21.    def test(self):
  22.        pass
  23.        print(get_data)
  24.    
  25.    
  26.        
  27. obj = Test()
  28. obj.test()
  29. '''
  30. # Connect to the database
  31. '''
  32. class Crud:
  33.    connection = pymysql.connect(host='127.0.0.1',
  34.                             user='root',
  35.                             password='',
  36.                             db='system',
  37.                             charset='utf8mb4',
  38.                             cursorclass=pymysql.cursors.DictCursor)
  39.  
  40.    try:
  41.        with connection.cursor() as cursor:
  42.        # Create a new record
  43.            sql = "INSERT INTO `system_info` \
  44.            (`system`,`node`, `release_version`,\
  45.             `version`, `machine`,`processor`)\
  46.             VALUES (%s, %s, %s, %s, %s, %s)"
  47.            
  48.            cursor.execute(sql, ('variable1', 'variable2',
  49.                                 'variable3', 8, 'variable5', 'variable6'))
  50.  
  51.    # Commit for save data
  52.        connection.commit()
  53.    finally:
  54.        connection.close()
  55.          
  56. obj = Crud()
  57.  
  58. '''
  59.  
  60. '''
  61. import pymysql
  62.  
  63. # open database connection
  64. db = pymysql.connect("localhost", "root", "", "TESTDB")
  65.  
  66. # prepare a cursor object
  67. cursor = db.cursor()
  68.  
  69. # Drop table if it already exists
  70. cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
  71.  
  72. # create table as per requirement
  73. sql = """CREATE TABLE SYSTEMINFO (
  74.         SYSTEM CHAR(20) NOT NULL,
  75.         NODE CHAR(20) NOT NULL,
  76.         RELEASE_VR INT NOT NULL,
  77.         VERSION FLOAT NOT NULL,
  78.         MACHINE CHAR(20) NOT NULL,
  79.         PROCESSOR CHAR(20) NOT NULL)"""
  80.        
  81. cursor.execute(sql)
  82.  
  83. # disconnect from server
  84. db.close()
  85.  
  86. '''
  87. import platform
  88. import pymysql
  89. import pymysql.cursors
  90.  
  91. # open database connection
  92. db = pymysql.connect("localhost", "root", "", "TESTDB")
  93.  
  94. # prepare a cursor object using  cursor() method
  95. cursor = db.cursor()
  96.  
  97. # Drop table if it already exists
  98. cursor.execute("DROP TABLE IF EXISTS SYSTEMINFO")
  99.  
  100. # create table as per requirement
  101. sql = """CREATE TABLE SYSTEMINFO (
  102.         SYSTEM CHAR,
  103.         NODE CHAR,
  104.         RELEASED_VR CHAR,
  105.         VERSION CHAR,
  106.         MACHINE CHAR,
  107.         PROCESSOR CHAR)"""
  108.          
  109. cursor.execute(sql)
  110.  
  111. # prepare SQL Query to INSERT a record into the database
  112. sql = "INSERT INTO SYSTEMINFO(SYSTEM, NODE, RELEASED_VR, VERSION, MACHINE, PROCESSOR)"
  113.  
  114. for i in zip(['system   ','node     ','release  ','version  ','machine  ','processor'],platform.uname()):
  115.     # print(i[0],':',i[1])
  116.     a = i[1]
  117.     print(a)
  118.     sql = sql + "VALUES ('"+str(a)+"')"    # problem
  119.    
  120.     try:
  121.         # execute the SQL command
  122.         cursor.execute(sql)
  123.        
  124.         # commit changes in the database
  125.         db.commit()
  126.        
  127.     except:
  128.         # rollback in case there is any error
  129.         db.rollback()
  130.        
  131.  
  132. # disconnect from server
  133. db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement