aboutsummaryrefslogtreecommitdiff
path: root/tests/dbTestFiller.py
blob: 5d2b2949c97ceaa665d3087e81fc77cc513a8d6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import mysql.connector as con
from mysql.connector.errors import InterfaceError

GitHubWorkflow = True

try:
    print(os.environ['GITHUB_ACTIONS'])
except:
    GitHubWorkflow = False

def returnValue(key):
    return os.environ[key]

if GitHubWorkflow:
    host = returnValue("CURIE_HOST")
    db = returnValue("CURIE_DB")
    user = returnValue("CURIE_USER")
    port = returnValue("CURIE_PORT")
    password = returnValue("CURIE_PASSWORD")
    fromaddr = returnValue("CURIE_EMAIL")
    emailServer = returnValue("CURIE_EMAIL_SERVER")
    emailPort = returnValye("CURIE_EMAIL_PORT")
    emailPassword = returnValye("CURIE_EMAIL_PASSWORD")
else:
    import configparser
    config = configparser.ConfigParser()
    config.read('config.ini')
    try:
        config['DATABASE']
    except KeyError:
        config.read("../config.ini")
    v = config['DATABASE']

    host = v['HOST']
    db = v['NAME']
    user = v['USER']
    password = v['PASSWORD']
    port = v['PORT']
    fromaddr = config['SMTP']['EMAIL']
    emailServer = config['SMTP']['SERVER']
    emailPort = config['SMTP']['PORT'] 
    emailPassword = config['SMTP']['PASSWORD'] 


try:
    mycon = con.connect(host=host,user=user,password=password,port=port,database=db)
except InterfaceError:
    print("Could not connect to the database")
    sys.exit(1)

mycursor = mycon.cursor()
done = 1

try:
    mycursor.execute("create table curieweb (    id varchar(16) primary key, email nvarchar(255) NOT NULL,   protein LONGBLOB NOT NULL, protein_name VARCHAR(255),  ligand_pdbqt LONGBLOB,   ligand_smile VARCHAR(255),   ligand_name VARCHAR(255),   config LONGBLOB NOT NULL, date DATE, description VARCHAR(255),   done TINYINT DEFAULT 0, pdb VARCHAR(4),csv longblob)")
except con.ProgrammingError:
    print("Table Already Exists!")

def convertToBinaryData(filename):
    with open(filename, 'rb') as file:
        binaryData = file.read()
    return binaryData

ligand = convertToBinaryData("./files/Eucalyptol.pdbqt")
receptor = convertToBinaryData("./files/6LU7.pdbqt")
config = convertToBinaryData("./files/6LU7.txt")
ligandName = "Eucalyptol"
receptorName = "6LU7"
sqlQuery = "insert into curieweb (id, email, protein, protein_name, ligand_pdbqt, ligand_name,date, config,done) values (%s,%s,%s,%s,%s,%s,CURDATE(),%s,%s) "
jobID = "l9xo2isr98oepcia"

insert_tuple = (jobID,"b5bmf.{curie-gh-ci}@inbox.testmail.app",receptor,receptorName,ligand,ligandName,config,done)
mycursor.execute(sqlQuery,insert_tuple)
print("Succesfuly submitted Job ID:",jobID)


mycon.commit()