Skip to content

Commit 73a23fb

Browse files
committed
Fixed module import method.
1 parent bb7b7df commit 73a23fb

File tree

3 files changed

+54
-55
lines changed

3 files changed

+54
-55
lines changed

loaf/__init__.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,53 @@
1-
from general import bake
1+
import pymysql, datetime, socket
2+
3+
host_ = socket.gethostbyname(socket.gethostname())
4+
port_ = 80 # Default XAMPP Apache server port.
5+
user_ = "root"
6+
pasw_ = ""
7+
db_ = None
8+
creds_ = ""
9+
10+
# Make this differently, for the love of god!
11+
def bake(host=host_, port=port_, user=user_, pasw=pasw_, db=db_, creds=creds_):
12+
global host_, port_, user_, pasw_, db_, creds_
13+
if host != "": host_=host
14+
if port != "": port_=port
15+
if user != "": user_=user
16+
if pasw != "": pasw_=pasw
17+
if db != "": db_=db
18+
if creds != "": creds_=creds
19+
20+
# A query.
21+
def query(query):
22+
conn = pymysql.connect(host=host_, port=port_, user=user_, passwd=pasw_, db=db_)
23+
conn_object = conn.cursor()
24+
conn_object.execute(query)
25+
str = conn_object.fetchall()
26+
conn.commit()
27+
conn.close()
28+
return str
29+
30+
# Call a stored procedure.
31+
def call(func, *args):
32+
call = "CALL " + func + "("
33+
if len(args) > 0:
34+
for i in range(len(args)):
35+
call += (str(args[i]) if type(args[i])==type(1) else parseNull(args[i])) + (", " if i<len(args)-1 else ");")
36+
else: call += ");"
37+
q = query(call)
38+
return q[0][0] if len(q)==1 else q
39+
40+
# Quick query.
41+
def all(table):
42+
return query(f"SELECT * from {table};")
43+
44+
def getToday():
45+
dat = datetime.date.today() + datetime.timedelta(days=1)
46+
return dat.strftime("%Y-%m-%d")
47+
48+
def getTomorrow():
49+
dat = datetime.date.today() + datetime.timedelta(days=1)
50+
return dat.strftime("%Y-%m-%d")
51+
52+
def parseNull(val):
53+
return "NULL" if val in ["", "NULL"] else "'"+val+"'"

loaf/general.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '0.1.8'
3+
VERSION = '0.1.10'
44
DESCRIPTION = 'Effortlessly access your MySQL server and procedures, plus some other utilities!'
55
with open('README.md', encoding="utf8") as f:
66
LONG_DESCRIPTION = f.read()

0 commit comments

Comments
 (0)