Automate Posting Hugo Blog to Social Sites (with a db) Part 2
Background
Previous posts in this series
Expand a the mysql class
I create a repo at https://github.com/justin-napolitano/mysql-utility-class.git to enable importing as a submodule the class that i have been workign on.
Set up the db
In another part in this series, I detailed setting up the mysql db via the command line. I am going to furher that workflow by modifying the files in that repo and then running thm to generat tables within my instance of mysql.
Setup you dev environment...again
Copy the .env file
Copy over the .env files from the previous few steps.
Import the Config repo
Import the utility class repo
Setup the package as a module
From root drop an empty _init.py file
From the utility class directory drop another init.py
This one however will contain a relative import to enable access to the class
Touch
&&
Echo to file
Check the module hierarchy
We should be looking like this
Create the main file
Touch main.py
Modify main.py
My file currently looks like this to test the connect
# Load environment variables from .env file
=
Test the conection
Modify the class for more features.
I want to be able to
- create a db
- drop a db
- use a db
- execute a script fro file
Create db
=
return True
return False
return False
Drop db
=
return True
return False
return False
use db
Execute Script
=
=
Test the module
With the added logic my main.py file looks like
=
=
I execute with the following from the project root.
The current MySQLConnector Class
Below is as it stand.. The most up to date file can always be found at https://github.com/justin-napolitano/mysql-utility-class.git
=
=
=
=
= None
= None
=
=
=
return True
return False
return False
=
return True
return False
return False
=
=
# Usage example
# Load environment variables from .env file
=
=
# Replace 'new_database' with the desired database name
# Use the specified database from .env