Imports Discord messages archive to PostgreSQL database
Project description
Discord to PostgreSQL
Imports Discord messages archive to PostgreSQL database.
Tested in a Linux installation of Python 3.9. May also work for Python 3.6, 3.7, 3.8 but not 3.10.
Installation
pip3 install discord-to-postgresql
Usage
Run with postgresql credentials as arguments
python3 discord_to_postgresql data/package.zip replace myusername mypassword 0.0.0.0 5432 postgres
Run with textfile containing PostgreSQL connection URL specified as argument
python3 discord_to_postgresql path/to/package.zip replace -t path/to/conn_url.txt
Sample contents of textfile
postgresql://myusername:mypassword@0.0.0.0:5432/postgres
PostgreSQL output tables
discord_user
Column | Type |
---|---|
id | bigint |
username | character varying |
discriminator | character varying |
discord_server
Column | Type |
---|---|
id | bigint |
name | character varying |
discord_channel
type
is the "type" of the discord channel. Known possible values of type
are:
- 0 = normal server channel
- 1 = direct message (between 2 people only)
- 3 = group chat (may be more than 2 people)
- 5 = announcement channel
- 11 = thread
Column | Type |
---|---|
id | bigint |
type | integer |
name | character varying |
server_id | bigint |
discord_recipient
A private chat will have 2 "recipients" (members), or 1-8 for group chats.
Column | Type |
---|---|
channel_id | bigint |
user_id | bigint |
discord_message
Column | Type |
---|---|
id | bigint |
timestamp | timestamp without time zone |
contents | text |
attachments | character varying |
channel_id | bigint |
user_id | bigint |
Command-line arguments
--package
: package.zip file path.--if_exists
: How to behave if the tables already exist. This argument will be directly passed to the DataFrame.to_sql() function. Possible values:fail
: Raise a ValueError.replace
: Drop the table before inserting new values.append
: Insert new values to the existing table.
--username
: PostgreSQL server username. Optional if text_file_with_url already specified.--password
: PostgreSQL server password. Optional if text_file_with_url already specified.--host
: PostgreSQL server host URL (e.g. localhost or xxx.xxx.xxx.xxx). Optional if text_file_with_url already specified.--port
: PostgreSQL server port. Optional if text_file_with_url already specified.--db_name
: PostgreSQL server database name. Optional if text_file_with_url already specified.--text_file_with_url
: Text file containing PostgreSQL DB connection URL. Optional if username, password, host, port, db_name are all specified. URL is of the format:postgresql://<USERNAME>:<PASSWORD>@<HOST>:<PORT>/<DB_NAME>
Addendum: Easiest way to start up a test PostgreSQL server
Install Docker: https://docs.docker.com/engine/install/
Then type this command to install a Docker PostgreSQL image and run as a container:
docker run -p 5432:5432 --name test-postgres -e POSTGRES_USER=myusername -e POSTGRES_PASSWORD=mypassword -e POSTGRES_DB=postgres -d postgres
This will run a postgresql server accessible on localhost:5432
with username myusername
and password mypassword
, and create a databased named postgres
.
To stop the container:
docker stop test-postgres
To restart the container:
docker start test-postgres
To delete the container (and erase all db data):
docker rm test-postgres
after which it is completely fine to run the above-mentioned docker run
command again.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for discord_to_postgresql-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fadad2c09d71653851b3e35a956151e5d19e62acf1ad5010834195968772aa5 |
|
MD5 | 1fd69c661ad134dd4f92573112345eac |
|
BLAKE2b-256 | 9cbdac2c4989e21be5dc202cd0ab0896b7fe632a0f092d4440091d8d85422741 |