11from html import unescape
2+ from typing import Dict , List , Optional , Tuple
23
34import pytz
45from bs4 import BeautifulSoup
6+ from mastodon import Mastodon
57from twootfeed .utils .feed_generation import generate_feed
68
79
8- def format_toot (toot , text_length_limit ) :
10+ def format_toot (toot : Dict , text_length_limit : int ) -> Dict :
911 rss_toot = {
1012 'display_name' : toot ['account' ]['display_name' ],
1113 'screen_name' : toot ['account' ]['username' ],
@@ -25,7 +27,7 @@ def format_toot(toot, text_length_limit):
2527 if source :
2628 rss_toot ['htmltext' ] += '<i>Source: {}</i>' .format (source .get ('name' ))
2729
28- medialist = toot .get ('media_attachments' )
30+ medialist = toot .get ('media_attachments' , [] )
2931 if len (medialist ) > 0 :
3032 rss_toot ['htmltext' ] += '<br>'
3133 for media in medialist :
@@ -53,8 +55,12 @@ def format_toot(toot, text_length_limit):
5355
5456
5557def 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 :
5864 text_length_limit = int (param ['feed' ].get ('text_length_limit' , 100 ))
5965 f = generate_feed (feed_title , feed_link , param , feed_desc )
6066
@@ -86,7 +92,9 @@ def generate_mastodon_feed(
8692 return xml
8793
8894
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 ]:
9098 if len (first_toots ) == 0 :
9199 return first_toots
92100 result = first_toots
@@ -104,7 +112,12 @@ def get_next_toots(api, first_toots, max_items):
104112 return result
105113
106114
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 ]:
108121 if api :
109122 max_items = param ['feed' ]['max_items' ]
110123 if query_feed :
0 commit comments