From 6bbbd129aaf99f80bcc64717a8e8e7d1ea8d0de2 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Fri, 19 Feb 2021 20:27:28 +0300 Subject: [PATCH] Init --- .gitignore | 1 + post.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .gitignore create mode 100644 post.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d85d67 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +token.dat diff --git a/post.py b/post.py new file mode 100644 index 0000000..eca4cc1 --- /dev/null +++ b/post.py @@ -0,0 +1,39 @@ +import sys +import os.path as op +from urllib.parse import urlparse + +import requests +from bs4 import BeautifulSoup +from mastodon import Mastodon + +URL_HEAD = 'https://anime-pictures.net' + +def main(): + # Searching for the url of the highest rated art + resp = requests.get(URL_HEAD) + soup = BeautifulSoup(resp.text, 'lxml') + final_url = URL_HEAD + str(soup.findAll('span', {'class': 'img_block2'})[12]).split('"')[5] + print(final_url) + + # Requesting its page and getting the actual full image + resp = requests.get(final_url) + soup = BeautifulSoup(resp.text, 'lxml') + src_url = URL_HEAD + str(soup.find('div', {'id': 'big_preview_cont'})).split('"')[5] + + src_ext = src_url.split('.')[-1] + if src_ext == 'jpg': + src_ext = 'jpeg' + + # Logging in and posting + mastodon = Mastodon( + access_token = 'token.dat', + api_base_url = 'https://udongein.xyz/' + ) + + media = mastodon.media_post(requests.get(src_url).content, 'image/' + src_ext) + toot = ':senko:\nurl: ' + final_url + + mastodon.status_post(toot, media_ids=[media], visibility='unlisted', sensitive=False) + +if __name__ == '__main__': + sys.exit(main()) \ No newline at end of file