-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from babetoduarte/PyPI
v.1.0.0-RC1: PyPI compatible version!
- Loading branch information
Showing
5 changed files
with
68 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,5 @@ htmlcov | |
|
||
# Project files | ||
build | ||
dist | ||
tootnotify.egg-info | ||
tootnotify/credentials.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,31 +27,32 @@ The simplest way to do this, is through the Mastodon web interface: go to Prefer | |
|
||
![Mastodon Preferences - Development Settings](./media/0-mastodon_app_credentials.png "Mastodon Preferences - Development Settings") | ||
|
||
Once there, click on the `New Application` button. There, give your application a Name, and click the `Submit` button on the bottom of the page. Having created an App on your account, you should be presented with a `Client key`, a `Client secret`, and `Your Access Token`. You'll need to put these strings into a python file called `credentials.py` as instructed below. | ||
Once there, click on the `New Application` button. There, give your application a Name, and click the `Submit` button on the bottom of the page. Having created an App on your account, you should be presented with a `Client key`, a `Client secret`, and `Your Access Token`. You'll need to put these strings into a text configuration file called `.tootnotifyrc` located in your `$HOME` directory, as instructed below. | ||
## Installation | ||
|
||
This section presents the steps needed to install TootNotify, once the API credentials have been obtained. | ||
|
||
### Create `credentials.py` file | ||
### Create `~/.tootnotifyrc` file | ||
|
||
TootNotify looks for API credentials stored as variables in the `credentials.py` file within the `TootNotify/tootnotify/` folder. By default, **the 'credentials.py' file is not shipped with the project, which means you need to create it**: | ||
TootNotify looks for API credentials stored as variables in the `~/.tootnotifyrc` file within the users `$HOME` folder. By default, **the `.tootnotifyrc` file is not shipped with the project, which means you need to create it**: | ||
|
||
`foo@bar:TootNotify$> touch tootnotify/credentials.py` | ||
`foo@bar:~$> touch ~/.tootnotifyrc` | ||
|
||
Make sure that the content of `TootNotify/tootnotify/credentials.py` has this structure: | ||
Make sure that the content of `~/.tootnotify` correspond to the following (and be sure to assign values to these variables **without any quotes**!): | ||
|
||
``` python | ||
"""FILE: TootNotify/tootnotify/credentials.py""" | ||
``` shell | ||
## FILE: ~/.tootnotifyrc | ||
[tootnotify] | ||
# Instance url (e.g. https://mastodon.social) | ||
api_base_url = "" | ||
api_base_url = YOUR_INSTANCE_URL | ||
# API Client Key | ||
client_id = "" | ||
client_id = YOUR CLIENT_ID | ||
# API Client Secret | ||
client_secret = "" | ||
client_secret = YOUR_CLIENT_SECRET | ||
# API Access Token | ||
access_token = "" | ||
access_token = YOU_ACCESS_TOKEN | ||
# Default recipient for the private toots (e.g. @[email protected]) | ||
DEFAULT_RECIPIENT="" | ||
DEFAULT_RECIPIENT = YOUR_DEFAULT_RECIPIENT | ||
``` | ||
|
||
Among the variables, a DEFAULT_RECIPIENT can be configured, so that when using TootNotify systematically to notify the same user, the recipient address doesn't have to be provided every time: | ||
|
@@ -60,7 +61,7 @@ Among the variables, a DEFAULT_RECIPIENT can be configured, so that when using T | |
|
||
### Install via PIP | ||
|
||
Once the `credentials.py` file is in place, we can use PIP to install TootNotify (make sure you navigate to the root of the `TootNotify` project folder): | ||
Once the `~/.tootnotifyrc` control file is in place, we can use PIP to install TootNotify (make sure you navigate to the root of the `TootNotify` project folder): | ||
|
||
``` bash | ||
foo@bar:TootNotify$> pip install . | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ packages = ["tootnotify"] | |
|
||
[project] | ||
name = "tootnotify" | ||
version = "1.0.0b" | ||
version = "1.0.0-RC1" | ||
authors = [ | ||
{name="Jorge A. Duarte", email="[email protected]"}, | ||
] | ||
|
@@ -19,7 +19,6 @@ dependencies = [ | |
"mastodon.py>=1.8.0" | ||
] | ||
classifiers = [ | ||
"Private :: Do Not Upload", | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,44 +17,78 @@ | |
=== | ||
TootNotify - Version 1.0.0b | ||
TootNotify - Version 1.0.0-RC1 | ||
by: Jorge A. Duarte - [email protected] | ||
July 11, 2023 | ||
This is a python command line utility, which is able to send direct messages to | ||
a provided user on Mastodon. To use this tool you will need to have a Mastodon | ||
API application created, with its corresponding API credentials. | ||
API application created, with its corresponding API credentials. You will also | ||
need to store these credentials in configuration file called '.tootnotifyrc' in | ||
your $HOME directory, as TootNotify expects to find this file using the path: | ||
By default, the 'credentials.py' file is not shipped with the project, and must | ||
be created by the user, populating the required variables for API access: | ||
$HOME/.tootnotifyrc | ||
By default, the '.tootnotifyrc' file is not shipped with the project, and must | ||
be created by the user, populating the required variables for API access in the | ||
following format: | ||
[tootnotify] | ||
# Instance url (e.g. https://mastodon.social) | ||
api_base_url = "" | ||
api_base_url = YOUR_INSTANCE_URL | ||
# API Client Key | ||
client_id = "" | ||
client_id = YOUR CLIENT_ID | ||
# API Client Secret | ||
client_secret = "" | ||
client_secret = YOUR_CLIENT_SECRET | ||
# API Access Token | ||
access_token = "" | ||
access_token = YOU_ACCESS_TOKEN | ||
# Default recipient for the private toots (e.g. @[email protected]) | ||
DEFAULT_RECIPIENT="" | ||
DEFAULT_RECIPIENT = YOUR_DEFAULT_RECIPIENT | ||
Among the variables, a DEFAULT_RECIPIENT can be configured, so that when using | ||
TootNotify systematically to notify the same user, the recipient address doesn't | ||
have to be provided every time. | ||
Make sure that the first line and all variable names are copied verbatim into | ||
your configuration file. Among the variables, a DEFAULT_RECIPIENT can be | ||
configured, so that when using TootNotify systematically to notify the same | ||
user, the recipient address doesn't have to be provided every time. | ||
""" | ||
import argparse | ||
from configparser import ConfigParser | ||
from pathlib import Path | ||
from sys import argv, exit, stdout | ||
from time import sleep | ||
|
||
from mastodon import Mastodon | ||
|
||
from tootnotify.credentials import (DEFAULT_RECIPIENT, access_token, api_base_url, | ||
client_id, client_secret) | ||
# Read the user's configuration file stored in (~/.tootnotifyrc) | ||
# Instantiate a configutation parser | ||
config = ConfigParser() | ||
# Try to read the configuration file | ||
try: | ||
# Make sure to safely open the configuration file | ||
with open(f"{Path.home()}/.tootnotifyrc") as f: | ||
# Read the configuration properties | ||
config.read_file(f) | ||
# If no configuration file is found | ||
except IOError: | ||
# Notify the user | ||
print(f"ERROR: No config file ~/.tootnotifyrc found!") | ||
# And exit with a non-zero status | ||
exit(2) | ||
|
||
# Variables that are read in from the configuration file | ||
# Instance URL | ||
api_base_url = config['tootnotify']['api_base_url'] | ||
# API Client Key | ||
client_id = config['tootnotify']['client_id'] | ||
# API Client Secret | ||
client_secret = config['tootnotify']['client_secret'] | ||
# API Access Token | ||
access_token = config['tootnotify']['access_token'] | ||
# Default recipient for the private toots | ||
DEFAULT_RECIPIENT = config['tootnotify']['DEFAULT_RECIPIENT'] | ||
|
||
# Setup the Mastodon API credentials and access, using the values imported from | ||
# the 'credentials.py' file within the project folder. | ||
# the '~/.tootnotifyrc' file within the users $HOME folder. | ||
mastodon = Mastodon(client_id, | ||
client_secret, | ||
access_token, | ||
|
@@ -139,7 +173,7 @@ def main(argv): | |
|
||
# Argument for printing out the current version of this script | ||
parser.add_argument( | ||
"--version", action="version", version="%(prog)s v1.0.0b [07/12/2023]" | ||
"--version", action="version", version="%(prog)s v1.0.0-RC1 [07/12/2023]" | ||
) | ||
|
||
# Parse arguments passed into the main function | ||
|
@@ -227,7 +261,7 @@ def check_media_upload(media_id_dict, verbose=False): | |
print(f"API ERROR: Could not verify media update!\n\t{e}") | ||
status = None | ||
|
||
# If the status's url is not None, return a true value | ||
# If the status's URL is not None, return a true value | ||
if status['url'] != None: | ||
ready = True | ||
|
||
|