aboutsummaryrefslogtreecommitdiffstats
path: root/database.py
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2021-03-03 22:26:16 +0000
committerjwansek <eddie.atten.ea29@gmail.com>2021-03-03 22:26:16 +0000
commit5d330852b8b390af41717e0fdb47a689cc18bd77 (patch)
tree7da24066420ccbd418fe60ca308635dca94bfc47 /database.py
parenta36992b08c7e165b271ac76166058db2c50609fe (diff)
downloadboymoder.blog-5d330852b8b390af41717e0fdb47a689cc18bd77.tar.gz
boymoder.blog-5d330852b8b390af41717e0fdb47a689cc18bd77.zip
updated loads of shit
Diffstat (limited to 'database.py')
-rw-r--r--database.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/database.py b/database.py
index 142d942..6bf3c1f 100644
--- a/database.py
+++ b/database.py
@@ -1,7 +1,7 @@
from dataclasses import dataclass
+import configparser
import pymysql
import random
-import app
@dataclass
class Database:
@@ -10,17 +10,20 @@ class Database:
passwd:str = None
def __enter__(self):
+ config = configparser.ConfigParser()
+ config.read("edaweb.conf")
+
if self.safeLogin:
self.__connection = pymysql.connect(
- **app.CONFIG["mysql"],
+ **config["mysql"],
charset = "utf8mb4"
)
else:
self.__connection = pymysql.connect(
user = self.user,
passwd = self.passwd,
- host = app.CONFIG["mysql"]["host"],
- db = app.CONFIG["mysql"]["db"],
+ host = config["mysql"]["host"],
+ db = config["mysql"]["db"],
charset = "utf8mb4"
)
return self
@@ -38,10 +41,10 @@ class Database:
cursor.execute("SELECT alt, url FROM images WHERE imageName = %s;", (imageName, ))
return cursor.fetchone()
- def get_pfp_image(self):
+ def get_pfp_images(self):
with self.__connection.cursor() as cursor:
cursor.execute("SELECT alt, url FROM images WHERE pfp_img = 1;")
- return random.choice(cursor.fetchall())
+ return cursor.fetchall()
def get_header_articles(self):
with self.__connection.cursor() as cursor:
@@ -94,8 +97,6 @@ class Database:
""")
return cursor.fetchall()
-
-
if __name__ == "__main__":
with Database() as db:
- print(db.get_all_thoughts()) \ No newline at end of file
+ print(db.get_header_articles()) \ No newline at end of file