def download_data( IDs="today", timestamps=None, data_type="fullscan", timestamp_interval=None, comment=None, connect={}, verbose=True, ): """ Copied 19G25 from commit 17G28 better combining and plotting b70b43b on Jul 28, 2017 ... but it seems to be broken :( Not wasting time on this now. Returns data columns matching a certain set of ID's. """ import sys try: import MySQLdb # known to pip as mysqlclient # CONNECT_EXCEPTION = MySQLdb.OperationalError # LOG.info('Using MySQLdb as the database module') print("imported MySQLdb no problem!") except ImportError: try: # .. if that fails, try with pymysql import pymysql as MySQLdb MySQLdb.install_as_MySQLdb() # CONNECT_EXCEPTION = MySQLdb.err.OperationalError # LOG.info('Using pymysql as the database module') if sys.version_info.major > 2: # LOG.info('pymysql is known to be broken with Python 3. Consider ' # 'installing mysqlclient!') pass except: print("Error, can't connect to database!") connect_0 = dict( host="servcinf-sql", # your host, usually localhost, servcinf would also work, but is slower (IPv6) # port=9995, # your forwording port user="******", # your username passwd="cinf_reader", # your password db="cinfdata", ) # name of the data base for key, val in connect_0.items(): if key not in connect: connect[key] = val if data_type == "fullscan": data_string_template = ( "SELECT x,y FROM xy_values_sniffer where measurement = {0} order by id" ) # try: print("Connecting to CINF database...") cnxn = MySQLdb.connect(**connect) cursor = cnxn.cursor() print("Connection successful!") # except: # print('Connection failed!') if type(IDs) is int: IDs = [IDs] datasets = {} for ID in IDs: data_string = data_string_template.format(str(ID)) cursor.execute(data_string) raw_data = cursor.fetchall() list_data = np.array(raw_data) xy_data = np.swapaxes(list_data, 0, 1) datasets[ID] = xy_data return datasets
import numpy as np # Set up logging logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO) LOG = logging.getLogger('CINFDATA') # First try and import MySQLdb .. try: import MySQLdb CONNECT_EXCEPTION = MySQLdb.OperationalError LOG.info('Using MySQLdb as the database module') except ImportError: try: # .. if that fails, try with pymysql import pymysql as MySQLdb MySQLdb.install_as_MySQLdb() CONNECT_EXCEPTION = MySQLdb.err.OperationalError LOG.info('Using pymysql as the database module') if sys.version_info.major > 2: LOG.info('pymysql is known to be broken with Python 3. Consider ' 'installing mysqlclient!') except ImportError: # if that fails, just set it to None to indicate that we have no db module MySQLdb = None # pylint: disable=invalid-name LOG.info('Using cinfdata without database') class CinfdataError(Exception): """Generic Cinfdata exception"""
print("ERROR: missing the MySQLdb python module:") print("On Ubuntu: apt-get install python-mysqldb") print("On RHEL/CentOS: yum install MySQL-python") print("On FreeBSD: cd /usr/ports/*/py-MySQLdb && make install clean") sys.exit(2) else: try: import queue as Queue except: print("ERROR: missing the queue python module.") sys.exit(2) # MySQLdb not avialable for python3 # http://stackoverflow.com/questions/4960048/python-3-and-mysql try: import pymysql as MySQLdb MySQLdb.install_as_MySQLdb() except: print("ERROR: missing the pymysql python module:") print(" On Ubuntu: sudo apt-get install python3-setuptools") print(" sudo easy_install3 pip") print(" sudo pip3 install PyMySQL") # FIXME. I not know how install on RHEL and FreeBSD print(" On other OSes install pip for python3 and than run from root user:"******" pip3 install PyMySQL") #print(" On RHEL/CentOS: yum install MySQL-python") #print(" On FreeBSD: cd /usr/ports/*/py-MySQLdb && make install clean") sys.exit(2) """ Parse Arguments