1
1
from html import unescape
2
+ from typing import Dict , List , Optional , Tuple
2
3
3
4
import pytz
4
5
from bs4 import BeautifulSoup
6
+ from mastodon import Mastodon
5
7
from twootfeed .utils .feed_generation import generate_feed
6
8
7
9
8
- def format_toot (toot , text_length_limit ) :
10
+ def format_toot (toot : Dict , text_length_limit : int ) -> Dict :
9
11
rss_toot = {
10
12
'display_name' : toot ['account' ]['display_name' ],
11
13
'screen_name' : toot ['account' ]['username' ],
@@ -25,7 +27,7 @@ def format_toot(toot, text_length_limit):
25
27
if source :
26
28
rss_toot ['htmltext' ] += '<i>Source: {}</i>' .format (source .get ('name' ))
27
29
28
- medialist = toot .get ('media_attachments' )
30
+ medialist = toot .get ('media_attachments' , [] )
29
31
if len (medialist ) > 0 :
30
32
rss_toot ['htmltext' ] += '<br>'
31
33
for media in medialist :
@@ -53,8 +55,12 @@ def format_toot(toot, text_length_limit):
53
55
54
56
55
57
def generate_mastodon_feed (
56
- result , param , feed_title , feed_link , feed_desc = None
57
- ):
58
+ result : List [Dict ],
59
+ param : Dict ,
60
+ feed_title : str ,
61
+ feed_link : str ,
62
+ feed_desc : Optional [str ] = None ,
63
+ ) -> str :
58
64
text_length_limit = int (param ['feed' ].get ('text_length_limit' , 100 ))
59
65
f = generate_feed (feed_title , feed_link , param , feed_desc )
60
66
@@ -86,7 +92,9 @@ def generate_mastodon_feed(
86
92
return xml
87
93
88
94
89
- def get_next_toots (api , first_toots , max_items ):
95
+ def get_next_toots (
96
+ api : Mastodon , first_toots : List [Dict ], max_items : int
97
+ ) -> List [Dict ]:
90
98
if len (first_toots ) == 0 :
91
99
return first_toots
92
100
result = first_toots
@@ -104,7 +112,12 @@ def get_next_toots(api, first_toots, max_items):
104
112
return result
105
113
106
114
107
- def generate_xml (api , param , query_feed = None , favorites = False ):
115
+ def generate_xml (
116
+ api : Mastodon ,
117
+ param : Dict ,
118
+ query_feed : Optional [Dict ] = None ,
119
+ favorites : bool = False ,
120
+ ) -> Tuple [str , int ]:
108
121
if api :
109
122
max_items = param ['feed' ]['max_items' ]
110
123
if query_feed :
0 commit comments