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=')