From c0533a477273909a49e89e06d75760dedc0d86ff Mon Sep 17 00:00:00 2001 From: Ching Date: Mon, 17 Jul 2023 14:34:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(crawler):=20=E4=BF=AE=E6=94=B9=E5=98=9F?= =?UTF-8?q?=E6=96=87=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改嘟文格式 Signed-off-by: Ching --- crawler.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/crawler.py b/crawler.py index 00b2c45..e697677 100644 --- a/crawler.py +++ b/crawler.py @@ -127,18 +127,19 @@ def toot(): if redis_db.sismember('send-chh-article-id', article['article_id']): continue + # download article image to a temp file + img = requests.get(article['img_url']) # upload article image to mastodon - media = mastodon_client.media_post(article['img_url']) + media = mastodon_client.media_post(img.content, 'image/jpeg') # toot the article info - toot_content = """{title} - {category} by {author} \n - {content} \n - {url}""".format(title=article['title'], - category=article['category'], - author=article['author'], - content=article['content'], - url=article['url']) + toot_content = """{title} - #{category} by {author} \n {content} \n\n {url} \n\n #chh #chiphell \n """.format( + title=article['title'], + category=article['category'], + author=article['author'], + content=article['content'], + url=article['url']) - mastodon_client.toot(toot_content, media_ids=[media['id']]) + mastodon_client.status_post(toot_content, media_ids=[media['id']]) # add the article['id'] to the set redis_db.sadd('send-chh-article-id', article['article_id']) @@ -147,3 +148,4 @@ def toot(): if __name__ == '__main__': crawler() toot() + requests.get('https://up.tunpok.com/api/push/yoLZhc0rZR?status=up&msg=OK&ping=')