Exemplo n.º 1
0
# Demonstrates the delete command.
from sqlalchemy import create_engine
import pleiades as ple

engine = create_engine('mysql+pymysql://root:@localhost/testDB')
con = engine.connect()

cz = ple.CZ(engine, alchemy=True)

print('before:')
print(cz.select_from('konosuba').ex())

# Demonstrates the basic delete datement.
# If where is not specified all rows in the table will be deleted.
command = '''
DELETE
FROM konosuba
WHERE id = 1;
'''
con.execute(command)

print('after')
print(cz.select_from('konosuba').ex())
print()
Exemplo n.º 2
0
# Official mdb connector.
mdb_con = mdb.connect(**cfg)
cursor = mdb_con.cursor()

# sqlalchemy connector.
try:
    password = cfg['password']
except KeyError:
    password = ''
engine_string = 'mysql+pymysql://' + cfg['user'] + ':' + password + '@' + cfg[
    'host'] + '/' + dbname
engine = create_engine(engine_string)
con = engine.connect()

cz = ple.CZ(engine)

# Select database to be used. Can also be set in server.cfg instead.
command = f'USE {dbname};'
print(cz.use_db(dbname, printable=True))
try:
    cursor.execute(command)
    print(f'database {dbname} selected.')
    print()
except mdb.ProgrammingError as err:
    print(err)
    print()

# Demonstrates creating a table.
command = '''
CREATE TABLE client(
dbname = 'testDB'
cfg_path = './server.cfg'

with open(cfg_path, 'r') as f:
    server_config = json.load(f)
db = mdb.connect(**server_config)
cursor = db.cursor()

command = f'USE {dbname};'
try:
    cursor.execute(command)
except mdb.ProgrammingError:
    print('database does not exist')

cz = ple.CZ(cursor)

# CHECK is a CONSTRAINT that allows for data validation of sql tables by
# checking if the data fulfils certain criteria.
# Like UNIQUE, it can be added during table creation while defining column
# datatypes or after. It can also be added to columns using ALTER TABLE.
# After CHECK has been set, an error will be returned if a value that does not
# meet the criteria is added or updated to the column. The CHECK criteria does
# not have to be the same column as the column whose datatype was just defined.
# However, it makes things confusing, and it still works as if you set CHECK
# on the column defined in the criteria anyway.
# If attempting to set CHECK on an existing table, and error will be returned
# if any existing value in the column does not meet the criteria.
command = '''
CREATE TABLE testtable(
Exemplo n.º 4
0
# Demonstrates generation of a wordcloud.
import_path = r'.\datasets\reddit.csv'
data = pd.read_csv(import_path)
df = data[['title', 'subreddit']]

X = df['title']
y = df['subreddit'].values

reddit_lingo = {
    'TIL': '',
    '[tT]oday [iI] [lL]earned': '',
    'ff+uu+': 'ffuuu'
}

cz = ple.CZ()
X = cz.text_list_cleaner(X, cz.contractions, reddit_lingo, r'[^a-zA-Z ]', cz.lemmatize_sentence)

# Join the text into a single body.
full_text = ' '.join(X)
stops = stopwords.words('english') + ['wa', 'ha']
print(stops)

import_path = r'.\images\Reddit.jpg'
# The way masks work is all values that are 255 in the matrix are treated as
# off limits to the wordcloud. It is possible to manipulate the mask using
# functions if you wish to reverse the image or something.
mask = np.array(Image.open(import_path))
print(mask[0])
# Generates color based on an image.
image_colors = ImageColorGenerator(mask)
Exemplo n.º 5
0
# Demonstrates how to download files from an Amazon S3 server. The key will of
# course differ for different users, and the bucket name is the server instance
# name.
import json
import boto3
import pleiades as ple

with open(r'./boto3/keys.json') as f:
    keys = json.load(f)

# To see a list of available resources, use:
# print(boto3.session.Session().get_available_resources())
s3 = boto3.resource(
    's3',
    aws_access_key_id=keys['access_key'],
    aws_secret_access_key=keys['secret_key'],
    region_name=keys['default_region'],
)

cz = ple.CZ(s3)

bucket = 'inp-dil-ap-southeast-1'
# keys in this case are the paths to the needed files inside the bucket.
keys = cz.get_keys(bucket, prefix='/data/eICU/')
# Folder to save files into.
savein = './boto3/eicu/'
print(cz.download_files(bucket, keys, savein=savein))