Преглед изворни кода

Document config re toot and alt-text templates

Fix template behavior when comment is `None`
(not relevant in our use case, but may be important one day).

`example.json` now contains a single image
(reference for available template fields).
master
The Dod пре 2 дана
родитељ
комит
39aa69d85b
4 измењених фајлова са 6 додато и 10354 уклоњено
  1. 2
    0
      bloomscroller.py
  2. 3
    0
      config.py
  3. 1
    5138
      example.json
  4. 0
    5216
      example2.json

+ 2
- 0
bloomscroller.py Прегледај датотеку

23
     mastodon = Mastodon(access_token="secrets.txt")
23
     mastodon = Mastodon(access_token="secrets.txt")
24
     image = get_next_image(get_images(config.ALBUM_API), get_previous_id())
24
     image = get_next_image(get_images(config.ALBUM_API), get_previous_id())
25
     if image:
25
     if image:
26
+        if image['comment'] is None:
27
+            image['comment'] = ""  # Better not mess up templates when no comment.
26
         media = mastodon.media_post(
28
         media = mastodon.media_post(
27
             requests.get(
29
             requests.get(
28
                 image["derivatives"][config.MEDIA_SIZE]["url"]).content,
30
                 image["derivatives"][config.MEDIA_SIZE]["url"]).content,

+ 3
- 0
config.py Прегледај датотеку

5
 
5
 
6
 ALBUM_API = "https://photos.nandn.org.il/piwigo/ws.php?format=json&method=pwg.categories.getImages&cat_id=21&per_page=529"
6
 ALBUM_API = "https://photos.nandn.org.il/piwigo/ws.php?format=json&method=pwg.categories.getImages&cat_id=21&per_page=529"
7
 
7
 
8
+# Both templates can use image fields like {name} and {comment} (see example.json)
9
+# I don't need it in my use case, but go ahead
8
 TOOT_TEMPLATE = "#Bloomscrolling"
10
 TOOT_TEMPLATE = "#Bloomscrolling"
9
 ALT_TEXT_TEMPLATE = "Flowers from n&n's garden arranged in a vase.\nPhotographed at {date_creation}."
11
 ALT_TEXT_TEMPLATE = "Flowers from n&n's garden arranged in a vase.\nPhotographed at {date_creation}."
12
+
10
 TOOT_LANGUAGE = "en"
13
 TOOT_LANGUAGE = "en"
11
 TOOT_VISIBILITY = "public"
14
 TOOT_VISIBILITY = "public"
12
 MEDIA_SIZE = "4xlarge"
15
 MEDIA_SIZE = "4xlarge"

+ 1
- 5138
example.json
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 0
- 5216
example2.json
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


Loading…
Откажи
Сачувај