Skip to content

Commit

Permalink
Removed all Twitter references.
Browse files Browse the repository at this point in the history
  • Loading branch information
soup-bowl committed Jul 28, 2024
1 parent dd02e9a commit b8ee3bb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 148 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
<img src="https://user-images.githubusercontent.com/11209477/214368280-532459b4-eb5d-46f7-82cd-2913d4da1633.png" alt="A view of a Mastodon post showing a 5-picture collage, 1 larger image on the left and 4 small images in a grid orientation"/>
</p>

An experimental bot that posts a rundown of your musical week on Mastodon and/or Twitter.

**:warning: The Twitter integration will be phased out as Twitter has taken an agressive stance against automatic tweeting. My development account has been suspended, so I'm no longer able to develop the integration. Mastodon will be the sole focus going forward.**
An experimental bot that posts a rundown of your musical week on Mastodon.

## 🤔 What does this do?

Expand Down Expand Up @@ -54,9 +52,6 @@ See the [configuration example](/config.json.example) to see how to setup the to
* Mastodon: global `MASTODON_URL`, `MASTODON_KEY` and `MASTODON_SECRET`.
* Easily register an application in **Preferences**, then **Development**.
* Permissions needed are **write:media** and **write:statuses**.
* Twitter: global `TWITTER_CONSUMER_KEY`, `TWITTER_CONSUMER_SECRET`, and per-user `TWITTER_ACCESS_TOKEN`, and `TWITTER_ACCESS_TOKEN`.
* You can [register for Twitter API keys here](https://developer.twitter.com/en/portal/dashboard).
* Ensure your access token has **read and write** capabilities (default is read only).

With everything set, you can just run `python3 -m htw` from CLI, and all the magic should happen. You can see the optional arguments by running `python3 -m htw --help`.

Expand Down
4 changes: 0 additions & 4 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
"clients": [
{
"lastfmUsername": "example",
"twitterAccessToken": "key",
"twitterAccessSecret": "key",
"mastodonUsername": "[email protected]",
"mastodonAccessToken": "key"
}
],
"config": {
"lastfmKey": "key",
"twitterConsumerKey": "key",
"twitterConsumerSecret": "key",
"mastodonURL": "https://mastodon.social",
"mastodonKey": "key",
"mastodonSecret": "key"
Expand Down
34 changes: 5 additions & 29 deletions htw/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from htw.lfm import LFM, LFMPeriod
from htw.collage import Collage
from htw.twitter import Twitter
from htw.compose import Compose
from htw.mastodon import Mastodon

class CLI():
Expand All @@ -24,8 +24,6 @@ def __init__(self):
self.conf_path = "config.json"
self.lfm_period = LFMPeriod.WEEK
self.lastfm_key = getenv('LASTFM_KEY')
self.twitter_key = getenv('TWITTER_CONSUMER_KEY')
self.twitter_srt = getenv('TWITTER_CONSUMER_SECRET')
self.mastodon_key = getenv('MASTODON_KEY')
self.mastodon_srt = getenv('MASTODON_SECRET')
self.mastodon_url = getenv('MASTODON_URL')
Expand Down Expand Up @@ -138,32 +136,14 @@ def process_user(self, user_conf):

if not self.suppress:
print("- Composing tweet...")
tweet = Twitter().compose_tweet(artists, user_conf['lastfmUsername'])
tweet = Compose().compose_tweet(artists, user_conf['lastfmUsername'])

if self.display_only:
print(tweet)
print("---")
print(f"\033[92mCollage\033[00m: {pic}")
colgen.cleanup()
return True

if 'twitterAccessToken' in user_conf:
if not self.suppress:
print("- Posting to \033[96mTwitter\033[00m...")

try:
Twitter(
self.twitter_key,
self.twitter_srt,
user_conf['twitterAccessToken'],
user_conf['twitterAccessSecret']
).post_to_twitter(tweet, pic)
return True
except Exception as error:
print("\033[91mError\033[00m: " + str(error) + ".")
return False
finally:
colgen.cleanup()

if 'mastodonAccessToken' in user_conf:
if not self.suppress:
Expand Down Expand Up @@ -200,10 +180,6 @@ def read_config(self, location):

if 'lastfmKey' in conf['config']:
self.lastfm_key = conf['config']['lastfmKey'] if self.lastfm_key is None else self.lastfm_key
if 'twitterConsumerKey' in conf['config']:
self.twitter_key = conf['config']['twitterConsumerKey'] if self.twitter_key is None else self.twitter_key
if 'twitterConsumerSecret' in conf['config']:
self.twitter_srt = conf['config']['twitterConsumerSecret'] if self.twitter_srt is None else self.twitter_srt

if 'mastodonURL' in conf['config']:
self.mastodon_url = conf['config']['mastodonURL'] if self.mastodon_url is None else self.mastodon_url
Expand All @@ -219,7 +195,7 @@ def print_help(self):
if self.suppress:
return

print("Run without arguments to process last.fm & Twitter using environmental variables.")
print("Run without arguments to process last.fm & Mastodon using environmental variables.")
print("Script will also check and use environment variables stored in '.env'.")
print("")
print("\033[93mOptions:\033[00m")
Expand All @@ -231,7 +207,7 @@ def print_help(self):
print("\033[92m-k, --keep \033[00mThe collage is dumped into the working directory instead ", end='')
print("of a temporary disposable directory.")
print("\033[92m-s, --silent \033[00mScript does not output anything, just success/fail code.")
print("\033[92m-d, --display \033[00mDisplays tweet, but does not post to Twitter.")
print("\033[92m-d, --display \033[00mDisplays tweet, but does not post to Mastodon.")
print("")
print("\033[92m-v, --version \033[00mDisplay script version.")
print("\033[92m-h, --help \033[00mDisplay help information.")
Expand All @@ -244,4 +220,4 @@ def print_version(self):
return

print("Hot this Week by soup-bowl - \033[93mpre-alpha\033[00m.")
print("https://github.com/soup-bowl/lastfm-twitter/")
print("https://github.com/soup-bowl/hot-this-week")
23 changes: 23 additions & 0 deletions htw/compose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Contains the communication class for composing messages.
"""

class Compose():
"""Contains the communication class for composing messages.
"""

def compose_tweet(self, lfm_collection, name):
"""Compose tweet message contents.
Args:
lfm_collection ([type]): Last.fm user data collection.
name (str): Last.fm username.
Returns:
[str]: Message contents.
"""
message = "\U0001F4BF my week with #lastfm:\n"
for artist in lfm_collection:
message = message + f"{artist['name']} ({artist['plays']})\n"
message = message + f"https://www.last.fm/user/{name}"
return message
58 changes: 0 additions & 58 deletions htw/twitter.py

This file was deleted.

51 changes: 1 addition & 50 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ license = "MIT"
[tool.poetry.dependencies]
python = "^3.8"
lxml = "^5.2.2"
twython = "^3.9.1"
urllib3 = "^2.2.2"
Pillow = "^10.0.1"
"Mastodon.py" = "^1.7.0"
Expand Down

0 comments on commit b8ee3bb

Please sign in to comment.