first commit
This commit is contained in:
parent
0ec4f915f0
commit
36a9ec862d
|
@ -0,0 +1,4 @@
|
|||
secrets
|
||||
secrets/*
|
||||
saved_media
|
||||
saved_media/*
|
27
README.md
27
README.md
|
@ -1,3 +1,26 @@
|
|||
# Mastodon_DL_Favorites_Image
|
||||
# Mastodon DL Favorites Image
|
||||
|
||||
This tool permit DL image of your last 40 favs
|
||||
This tool permit DL image of your last 40 favs
|
||||
|
||||
## How to set up
|
||||
Install Pillow Mastodon.py and requests
|
||||
`pip install Pillow Mastodon.py requests`
|
||||
clone it
|
||||
`git clone https://github.com/Dryusdan/random-unsplash-hour.git`
|
||||
create `secrets/secrets.txt` and paste this :
|
||||
```
|
||||
client_id: looooong
|
||||
client_secret: veryyyy loooong
|
||||
access_token: toooo loooooong
|
||||
mastodon_hostname: miaou.drycat.fr
|
||||
```
|
||||
|
||||
create save_media folder is the same path
|
||||
|
||||
## How to run it
|
||||
|
||||
```
|
||||
python dlimage.py
|
||||
```
|
||||
|
||||
:)
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/python3
|
||||
# coding: utf-8
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
from mastodon import Mastodon
|
||||
import requests
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import argparse
|
||||
import math
|
||||
|
||||
def get_parameter( parameter, file_path ):
|
||||
# Check if secrets file exists
|
||||
if not os.path.isfile(file_path):
|
||||
print("File %s not found, exiting."%file_path)
|
||||
sys.exit(0)
|
||||
|
||||
# Find parameter in file
|
||||
with open( file_path ) as f:
|
||||
for line in f:
|
||||
if line.startswith( parameter ):
|
||||
return line.replace(parameter + ":", "").strip()
|
||||
|
||||
# Cannot find parameter, exit
|
||||
print(file_path + " Missing parameter %s "%parameter)
|
||||
sys.exit(0)
|
||||
def get_media():
|
||||
media_attachments = toot.media_attachments
|
||||
for media in media_attachments:
|
||||
print(media.url[-20:])
|
||||
response = requests.get(media.remote_url)
|
||||
pattern = Image.open(BytesIO(response.content), "r").convert('RGB')
|
||||
pattern.save('save_media/'+media.url[-20:])
|
||||
|
||||
secrets_filepath = "secrets/secrets.txt"
|
||||
|
||||
uc_client_id = get_parameter("client_id", secrets_filepath)
|
||||
uc_client_secret = get_parameter("client_secret", secrets_filepath)
|
||||
uc_access_token = get_parameter("access_token", secrets_filepath)
|
||||
mastodon_hostname = get_parameter("mastodon_hostname", secrets_filepath)
|
||||
|
||||
mastodon = Mastodon(
|
||||
client_id = uc_client_id,
|
||||
client_secret = uc_client_secret,
|
||||
access_token = uc_access_token,
|
||||
api_base_url = 'https://' + mastodon_hostname,
|
||||
)
|
||||
|
||||
masto_allfav = mastodon.favourites(None, None, 40)
|
||||
for toot in masto_allfav:
|
||||
if toot.account.acct == "bonjourtoutlemonde@hostux.social":
|
||||
get_media()
|
||||
else :
|
||||
if toot.account.acct == "BonjourMadame@hostux.social":
|
||||
get_media()
|
||||
|
Reference in New Issue