From 3039e1ef174632ab04b7b2e01d8c12b7c7f4f39a Mon Sep 17 00:00:00 2001 From: akrherz Date: Tue, 25 Feb 2025 14:09:48 -0600 Subject: [PATCH 1/2] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Update=20ruff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f17d483..08ed472 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ ci: autoupdate_schedule: quarterly repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.9.1" + rev: "v0.9.7" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From 9f0fbbda06b6f6895ae41f6416f2e8a0aacaf243 Mon Sep 17 00:00:00 2001 From: akrherz Date: Tue, 25 Feb 2025 21:42:14 -0600 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=9A=A7=20Bandaid=20on=20X=20v2=20medi?= =?UTF-8?q?a=20upload=20for=20#104?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/iembot/util.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/iembot/util.py b/src/iembot/util.py index 2b87761..0543d34 100644 --- a/src/iembot/util.py +++ b/src/iembot/util.py @@ -22,7 +22,7 @@ import twitter from pyiem.reference import TWEET_CHARS from pyiem.util import utc -from requests_oauthlib import OAuth1 +from requests_oauthlib import OAuth1, OAuth1Session from twisted.internet import reactor from twisted.mail import smtp from twisted.python import log @@ -68,12 +68,17 @@ def tweet(bot, user_id, twttxt, **kwargs): bot.tw_users[user_id]["access_token"], bot.tw_users[user_id]["access_token_secret"], ) + oauth = OAuth1Session( + bot.config["bot.twitter.consumerkey"], + bot.config["bot.twitter.consumersecret"], + bot.tw_users[user_id]["access_token"], + bot.tw_users[user_id]["access_token_secret"], + ) log.msg( f"Tweeting {bot.tw_users[user_id]['screen_name']}({user_id}) " f"'{twttxt}' media:{kwargs.get('twitter_media')}" ) media = kwargs.get("twitter_media") - media_id = None def _helper(params): """Wrap common stuff""" @@ -92,9 +97,13 @@ def _helper(params): } # If we have media, we have some work to do! if media is not None: - media_id = api.UploadMediaSimple(media) + payload = requests.get(media, timeout=30).content + res = oauth.post( + "https://api.x.com/2/media/upload", + files={"media": (media, payload, "image/png")}, + ).json() # string required - params["media"] = {"media_ids": [f"{media_id}"]} + params["media"] = {"media_ids": [f"{res['id']}"]} res = _helper(params) except TwitterError as exp: errcode = twittererror_exp_to_code(exp)