Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3.5
- import mysql.connector #import library mysql.connector
- from mysql.connector import errorcode #import library errorcod from mysql.conn
- import csv #import standart library csv
- try:
- cnx = mysql.connector.connect(user='root', password='t00r0DGn1', host='localhost', database='odgn') #open connection to the MySQL server and store the conn object in the variable cnx
- except mysql.connector.Error as err:
- if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
- print("Something is wrong with your user name or password")
- elif err.errno == errorcode.ER_BAD_DB_ERROR:
- print("Database does not exist")
- else:
- print(err)
- else:
- cursor = cnx.cursor() #create a new cursor
- for i in range(23, 35):
- query = ("SELECT date_format(date, '%d.%m.%Y %H:%i') as date, sensor, id, h FROM data_hydrolevel WHERE sensor = '%s';")
- cursor.execute(query, (i,))
- csvFile = open('file_sensor_%s.scv' % i, 'w', newline='')
- writer = csv.writer(csvFile, delimiter=';')
- writer.writerows(cursor)
- #for row in cursor:
- #print(row[0], row[1], row[2], row[3], sep = ';')
- #writer.writerow(row)
- csvFile.close()
- cursor.close()
- cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement