Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
Dryusdan | fa1550e26a | |
Luc Didry | e5e4938479 | |
Dryusdan | 67849b7f9f | |
Tristan Le Chanony | 38c1afa81a | |
Tristan Le Chanony | d7287622b9 |
|
@ -32,6 +32,7 @@ If you don't want any "spoiler text", just leave the line empty.
|
|||
| limit | Limit send per minute per person | int |
|
||||
| limit_hour | Limit send par hour per person | int |
|
||||
| collection_url | URL of website you deserve image. `<collection>` is a variable who depend on collection.json (you can remove this variable) | string |
|
||||
| unsplash_client_id | Access key of your Unsplash App (you can create it on api.unsplash.com ) | string |
|
||||
|
||||
Copy `blacklist.sample.json` to `blacklist.json` and replace or add accounts that should not receive any image
|
||||
|
||||
|
|
17
bot.py
17
bot.py
|
@ -32,7 +32,8 @@ def post_img_local(mastodon, text, log, config):
|
|||
|
||||
continu = True;
|
||||
while continu:
|
||||
file = random.choice(os.listdir(img_path+"/"))
|
||||
secure_random = random.SystemRandom()
|
||||
file = secure_random.choice(os.listdir(img_path+"/"))
|
||||
if os.path.isdir(img_path+file):
|
||||
img_path = img_path+file+"/"
|
||||
else:
|
||||
|
@ -69,7 +70,19 @@ def post_img_local(mastodon, text, log, config):
|
|||
return media_dict;
|
||||
|
||||
def post_unsplash_random_image(mastodon, log, config):
|
||||
response = requests.get('https://api.unsplash.com/photos/random?client_id=03ad5bfbaa0acd6c96a728d425e533683ec25e5fb7fcf99f6461720b3d0d75a1')
|
||||
collection_url = get_parameter("collection_url", config)
|
||||
unsplash_client_id = get_parameter("unsplash_client_id", config)
|
||||
collecion_file = open(collection_filepath,'r')
|
||||
collections = json.loads(collecion_file.read())
|
||||
collecion_file.close()
|
||||
|
||||
count_collection = len(collections)-1
|
||||
if count_collection > -1:
|
||||
id_collection = randint(0,count_collection)
|
||||
collection_url="&collections="+str(collections[id_collection])
|
||||
else:
|
||||
collection_url=''
|
||||
response = requests.get("https://api.unsplash.com/photos/random?client_id="+unsplash_client_id+collection_url)
|
||||
randim_json = json.loads(response.text)
|
||||
randim_url = "{}&q=85&crop=entropy&cs=tinysrgb&w=2048&fit=max".format(randim_json['urls']['raw'])
|
||||
|
||||
|
|
|
@ -10,3 +10,4 @@ spoiler_text: some text here
|
|||
limit: 2
|
||||
limit_hour: 10
|
||||
collection_url: https://source.unsplash.com/collection/<collection>/
|
||||
unsplash_client_id: 03ad5bfbaa0acd6c96a728d425e533683ec25e5fb7fcf99f6461720b3d0d75a1
|
||||
|
|
Reference in New Issue