Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- import platform
- class Test:
- def system_data(self):
- global get_data
- var = 0
- variable = 'variable'
- for value in zip(['system ','node ','release_version ','version ','machine ','processor'],platform.uname()):
- var = var + 1
- data = value[1]
- get_data = variable+str(var)+' = '+str(data)
- print(get_data)
- obj = Test()
- data= obj.system_data()
- '''
- '''
- class Test:
- def test(self):
- pass
- print(get_data)
- obj = Test()
- obj.test()
- '''
- # Connect to the database
- '''
- class Crud:
- connection = pymysql.connect(host='127.0.0.1',
- user='root',
- password='',
- db='system',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- try:
- with connection.cursor() as cursor:
- # Create a new record
- sql = "INSERT INTO `system_info` \
- (`system`,`node`, `release_version`,\
- `version`, `machine`,`processor`)\
- VALUES (%s, %s, %s, %s, %s, %s)"
- cursor.execute(sql, ('variable1', 'variable2',
- 'variable3', 8, 'variable5', 'variable6'))
- # Commit for save data
- connection.commit()
- finally:
- connection.close()
- obj = Crud()
- '''
- '''
- import pymysql
- # open database connection
- db = pymysql.connect("localhost", "root", "", "TESTDB")
- # prepare a cursor object
- cursor = db.cursor()
- # Drop table if it already exists
- cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
- # create table as per requirement
- sql = """CREATE TABLE SYSTEMINFO (
- SYSTEM CHAR(20) NOT NULL,
- NODE CHAR(20) NOT NULL,
- RELEASE_VR INT NOT NULL,
- VERSION FLOAT NOT NULL,
- MACHINE CHAR(20) NOT NULL,
- PROCESSOR CHAR(20) NOT NULL)"""
- cursor.execute(sql)
- # disconnect from server
- db.close()
- '''
- import platform
- import pymysql
- import pymysql.cursors
- # open database connection
- db = pymysql.connect("localhost", "root", "", "TESTDB")
- # prepare a cursor object using cursor() method
- cursor = db.cursor()
- # Drop table if it already exists
- cursor.execute("DROP TABLE IF EXISTS SYSTEMINFO")
- # create table as per requirement
- sql = """CREATE TABLE SYSTEMINFO (
- SYSTEM CHAR,
- NODE CHAR,
- RELEASED_VR CHAR,
- VERSION CHAR,
- MACHINE CHAR,
- PROCESSOR CHAR)"""
- cursor.execute(sql)
- # prepare SQL Query to INSERT a record into the database
- sql = "INSERT INTO SYSTEMINFO(SYSTEM, NODE, RELEASED_VR, VERSION, MACHINE, PROCESSOR)"
- for i in zip(['system ','node ','release ','version ','machine ','processor'],platform.uname()):
- # print(i[0],':',i[1])
- a = i[1]
- print(a)
- sql = sql + "VALUES ('"+str(a)+"')" # problem
- try:
- # execute the SQL command
- cursor.execute(sql)
- # commit changes in the database
- db.commit()
- except:
- # rollback in case there is any error
- db.rollback()
- # disconnect from server
- db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement