Skip to content

Commit

Permalink
Merge pull request #11 from stanfordio/token
Browse files Browse the repository at this point in the history
Re-support use of TRUTHSOCIAL_TOKEN, login if not provided
  • Loading branch information
lxcode authored Jan 10, 2023
2 parents 1c115b5 + f38ebbb commit a87cc51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "truthbrush"
version = "0.1.2"
version = "0.1.3"
description = "API client for Truth Social"
authors = ["R. Miles McCain <github@sendmiles.email>"]
license = "Apache 2.0"
Expand Down
16 changes: 8 additions & 8 deletions truthbrush/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,28 @@ class LoginErrorException(Exception):


class Api:
def __init__(self, username: str = None, password: str = None):
def __init__(self, username: str = None, password: str = None, token: str = None):
self.ratelimit_max = 300
self.ratelimit_remaining = None
self.ratelimit_reset = None
self.__username = username
self.__password = password
self.auth_id = ""
self.auth_id = token

def __check_login(self):
"""Runs before any login-walled function to check for login credentials and generates an auth ID token"""
if self.__username is None:
raise LoginErrorException("Username is missing.")
if self.__password is None:
raise LoginErrorException("Password is missing.")
if self.auth_id == "":
if self.auth_id is None:
if self.__username is None:
raise LoginErrorException("Username is missing.")
if self.__password is None:
raise LoginErrorException("Password is missing.")
self.auth_id = self.get_auth_id(self.__username, self.__password)

def _make_session(self):
s = requests.Session()
s.proxies.update(proxies)
retries = Retry(
total=10,
total=5,
backoff_factor=0.5,
status_forcelist=[413, 429, 503, 403, 500, 501, 502, 503, 504, 524],
)
Expand Down
7 changes: 6 additions & 1 deletion truthbrush/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from .api import Api

load_dotenv() # take environment variables from .env.
api = Api(os.getenv("TRUTHSOCIAL_USERNAME"), os.getenv("TRUTHSOCIAL_PASSWORD"))
api = Api(
os.getenv("TRUTHSOCIAL_USERNAME"),
os.getenv("TRUTHSOCIAL_PASSWORD"),
os.getenv("TRUTHSOCIAL_TOKEN"),
)


@click.group()
Expand Down Expand Up @@ -70,6 +74,7 @@ def ads():

print(json.dumps(api.ads()))


@cli.command()
@click.argument("handle")
@click.option("--maximum", help="the maximum number of followers to pull", type=int)
Expand Down

0 comments on commit a87cc51

Please sign in to comment.