diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2021-02-02 12:24:06 +0000 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2021-02-02 12:24:06 +0000 |
commit | 1dac1ee189bdcf70a5dd933d5f6a69a15d5a8d7e (patch) | |
tree | 0bff6312d7e3bcc364d7632da708f74d15cbd0f3 /database.py | |
parent | 6eb416ac7784ce08b6959e3db06ccd404736516f (diff) | |
download | eda.gay-1dac1ee189bdcf70a5dd933d5f6a69a15d5a8d7e.tar.gz eda.gay-1dac1ee189bdcf70a5dd933d5f6a69a15d5a8d7e.zip |
added the program files for the first time
Diffstat (limited to 'database.py')
-rw-r--r-- | database.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/database.py b/database.py new file mode 100644 index 0000000..05e8a7e --- /dev/null +++ b/database.py @@ -0,0 +1,33 @@ +import pymysql +import app + +class Database: + def __enter__(self): + self.__connection = pymysql.connect( + **app.CONFIG["mysql"], + charset = "utf8mb4" + ) + return self + + def __exit__(self, type, value, traceback): + self.__connection.close() + + def get_header_links(self): + with self.__connection.cursor() as cursor: + cursor.execute("SELECT name, link FROM headerLinks ORDER BY name;") + return cursor.fetchall() + + def get_image(self, imageName): + with self.__connection.cursor() as cursor: + cursor.execute("SELECT alt, url FROM images WHERE imageName = %s;", (imageName, )) + return cursor.fetchone() + + def get_header_articles(self): + with self.__connection.cursor() as cursor: + cursor.execute("SELECT articleName, link FROM headerArticles;") + return cursor.fetchall() + + +if __name__ == "__main__": + with Database() as db: + print(db.get_header_articles())
\ No newline at end of file |