mirror of
https://github.com/hemna/aprsd-twitter-plugin.git
synced 2026-06-08 00:44:56 -04:00
switch to pyproject.toml and update tox.ini
This commit is contained in:
@@ -12,5 +12,4 @@
|
||||
|
||||
import pbr.version
|
||||
|
||||
|
||||
__version__ = pbr.version.VersionInfo("aprsd_twitter_plugin").version_string()
|
||||
|
||||
@@ -2,6 +2,5 @@ from oslo_config import cfg
|
||||
|
||||
from aprsd_twitter_plugin.conf import twitter
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
twitter.register_opts(CONF)
|
||||
|
||||
@@ -31,7 +31,6 @@ import importlib
|
||||
import os
|
||||
import pkgutil
|
||||
|
||||
|
||||
LIST_OPTS_FUNC_NAME = "list_opts"
|
||||
|
||||
|
||||
@@ -64,9 +63,10 @@ def _import_modules(module_names):
|
||||
for modname in module_names:
|
||||
mod = importlib.import_module("aprsd_twitter_plugin.conf." + modname)
|
||||
if not hasattr(mod, LIST_OPTS_FUNC_NAME):
|
||||
msg = "The module 'aprsd_twitter_plugin.conf.%s' should have a '%s' "\
|
||||
"function which returns the config options." % \
|
||||
(modname, LIST_OPTS_FUNC_NAME)
|
||||
msg = (
|
||||
f"The module 'aprsd_twitter_plugin.conf.{modname}' should have a "
|
||||
f"'{LIST_OPTS_FUNC_NAME}' function which returns the config options."
|
||||
)
|
||||
raise Exception(msg)
|
||||
else:
|
||||
imported_modules.append(mod)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from oslo_config import cfg
|
||||
|
||||
|
||||
twitter_group = cfg.OptGroup(
|
||||
name="aprsd_twitter_plugin",
|
||||
title="APRSD Twitter Plugin settings",
|
||||
@@ -10,17 +9,23 @@ twitter_opts = [
|
||||
cfg.StrOpt(
|
||||
"callsign",
|
||||
help="Callsign allowed to send tweets! "
|
||||
"Any callsign starting with this will be allowed to tweet to"
|
||||
"the configured twitter account. "
|
||||
"For example, if you set this to WB4BOR then any"
|
||||
"callsign starting with WB4BOR will be allowed to tweet."
|
||||
"This way WB4BOR-1 can tweet from this instance.",
|
||||
"Any callsign starting with this will be allowed to tweet to"
|
||||
"the configured twitter account. "
|
||||
"For example, if you set this to WB4BOR then any"
|
||||
"callsign starting with WB4BOR will be allowed to tweet."
|
||||
"This way WB4BOR-1 can tweet from this instance.",
|
||||
),
|
||||
cfg.StrOpt(
|
||||
"bearer_token",
|
||||
help="Your twitter Bearer Token"
|
||||
"Information for creating your api keys is here: "
|
||||
"https://developer.twitter.com/en/docs/authentication/oauth-2-0/authorization-code",
|
||||
),
|
||||
cfg.StrOpt(
|
||||
"apiKey",
|
||||
help="Your twitter apiKey"
|
||||
"Information for creating your api keys is here: "
|
||||
"https://developer.twitter.com/en/docs/authentication/oauth-1-0a/api-key-and-secret",
|
||||
"Information for creating your api keys is here: "
|
||||
"https://developer.twitter.com/en/docs/authentication/oauth-1-0a/api-key-and-secret",
|
||||
),
|
||||
cfg.StrOpt(
|
||||
"apiKey_secret",
|
||||
@@ -41,9 +46,7 @@ twitter_opts = [
|
||||
),
|
||||
]
|
||||
|
||||
ALL_OPTS = (
|
||||
twitter_opts
|
||||
)
|
||||
ALL_OPTS = twitter_opts
|
||||
|
||||
|
||||
def register_opts(cfg):
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import logging
|
||||
|
||||
import tweepy
|
||||
from aprsd import conf # noqa
|
||||
from aprsd import plugin
|
||||
from aprsd import (
|
||||
conf, # noqa
|
||||
plugin,
|
||||
)
|
||||
from oslo_config import cfg
|
||||
|
||||
import aprsd_twitter_plugin
|
||||
from aprsd_twitter_plugin import conf # noqa
|
||||
|
||||
from aprsd_twitter_plugin import conf as twitter_conf # noqa
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger("APRSD")
|
||||
|
||||
|
||||
class SendTweetPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||
|
||||
version = aprsd_twitter_plugin.__version__
|
||||
# Look for any command that starts with tw or tW or TW or Tw
|
||||
# or case insensitive version of 'twitter'
|
||||
@@ -37,37 +37,32 @@ class SendTweetPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||
|
||||
if not CONF.aprsd_twitter_plugin.callsign:
|
||||
LOG.error(
|
||||
"No aprsd_twitter_pligin.callsign is set."
|
||||
" Callsign is needed to allow tweets!",
|
||||
"No aprsd_twitter_pligin.callsign is set. Callsign is needed to allow tweets!",
|
||||
)
|
||||
self.enabled = False
|
||||
|
||||
# Ensure the access token exists.
|
||||
if not CONF.aprsd_twitter_plugin.apiKey:
|
||||
LOG.error(
|
||||
"No aprsd_twitter_plugin.apiKey is set!."
|
||||
" Plugin Disabled.",
|
||||
"No aprsd_twitter_plugin.apiKey is set!. Plugin Disabled.",
|
||||
)
|
||||
self.enabled = False
|
||||
|
||||
if not CONF.aprsd_twitter_plugin.apiKey_secret:
|
||||
LOG.error(
|
||||
"No aprsd_twitter_plugin.apiKey_secret is set."
|
||||
" Plugin Disabled.",
|
||||
"No aprsd_twitter_plugin.apiKey_secret is set. Plugin Disabled.",
|
||||
)
|
||||
self.enabled = False
|
||||
|
||||
if not CONF.aprsd_twitter_plugin.access_token:
|
||||
LOG.error(
|
||||
"No aprsd_twitter_plugin.access_token exists."
|
||||
" Plugin Disabled.",
|
||||
"No aprsd_twitter_plugin.access_token exists. Plugin Disabled.",
|
||||
)
|
||||
self.enabled = False
|
||||
|
||||
if not CONF.aprsd_twitter_plugin.access_token_secret:
|
||||
LOG.error(
|
||||
"No aprsd_twitter_plugin.access_token_secret exists."
|
||||
" Plugin Disabled.",
|
||||
"No aprsd_twitter_plugin.access_token_secret exists. Plugin Disabled.",
|
||||
)
|
||||
self.enabled = False
|
||||
|
||||
@@ -83,11 +78,21 @@ class SendTweetPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||
CONF.aprsd_twitter_plugin.access_token_secret,
|
||||
)
|
||||
|
||||
bearer_token = CONF.aprsd_twitter_plugin.bearer_token
|
||||
|
||||
api = tweepy.API(
|
||||
auth,
|
||||
bearer_token,
|
||||
wait_on_rate_limit=True,
|
||||
)
|
||||
|
||||
tweepy.OAuth2UserHandler(
|
||||
client_id="Client ID here",
|
||||
redirect_uri="Callback / Redirect URI / URL here",
|
||||
scope=["tweet.write"],
|
||||
# Client Secret is only necessary if using a confidential client
|
||||
client_secret="Client Secret here",
|
||||
)
|
||||
|
||||
try:
|
||||
api.verify_credentials()
|
||||
LOG.debug("Logged in to Twitter Authentication OK")
|
||||
@@ -99,7 +104,6 @@ class SendTweetPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||
return api
|
||||
|
||||
def process(self, packet):
|
||||
|
||||
"""This is called when a received packet matches self.command_regex."""
|
||||
|
||||
LOG.info("SendTweetPlugin Plugin")
|
||||
@@ -123,10 +127,7 @@ class SendTweetPlugin(plugin.APRSDRegexCommandPluginBase):
|
||||
return "Failed to Auth"
|
||||
|
||||
if CONF.aprsd_twitter_plugin.add_aprs_hashtag:
|
||||
message += (
|
||||
" #aprs #aprsd #hamradio "
|
||||
"https://github.com/hemna/aprsd-twitter-plugin"
|
||||
)
|
||||
message += " #aprs #aprsd #hamradio https://github.com/hemna/aprsd-twitter-plugin"
|
||||
|
||||
# Now lets tweet!
|
||||
client.update_status(message)
|
||||
|
||||
Reference in New Issue
Block a user