Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 15e1ac3

Browse files
committed
Mastodon - add user home timeline
1 parent 2168649 commit 15e1ac3

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

twootfeed/mastodon/generate_toots_feed.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ def generate_xml(
157157
feed_title = param['mastodon']['title'] + ' Bookmarks'
158158
feed_link = param['mastodon']['url'] + '/web/bookmarks'
159159
feed_desc = param['feed']['author_name'] + ' bookmarks toots.'
160+
elif target == 'home_timeline':
161+
result = api.timeline_home()
162+
result = get_next_toots(api, result, max_items)
163+
feed_title = param['mastodon']['title'] + ' Home Timeline'
164+
feed_link = param['mastodon']['url']
165+
feed_desc = param['feed']['author_name'] + ' home timeline.'
160166
else:
161167
raise Exception('Invalid target')
162168
xml = generate_mastodon_feed(

twootfeed/mastodon/routes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ def toot_favorites_feed() -> Tuple[str, int]:
3232
def toot_bookmarks_feed() -> Tuple[str, int]:
3333
"""generate a rss feed authenticated user's bookmarks"""
3434
return generate_xml(mastodon_api, mastodon_param, target='bookmarks')
35+
36+
37+
@mastodon_bp.route('/home_timeline', methods=['GET'])
38+
def home_timeline() -> Tuple[str, int]:
39+
"""generate a rss feed authenticated user's bookmarks"""
40+
return generate_xml(mastodon_api, mastodon_param, target='home_timeline')

twootfeed/tests/data.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,3 +846,57 @@
846846
'<br>♻ : 0, ✰ : 0</div></blockquote>',
847847
'text': 'Boosted by User A: What\'s New in #python today?',
848848
}
849+
850+
toot_1_home_timeline_feed = (
851+
'<?xml version="1.0" encoding="UTF-8"?>\n'
852+
'<rss version="2.0">'
853+
'<channel>'
854+
'<title>Recherche Mastodon : Home Timeline</title>'
855+
'<link>https://mastodon.social</link><'
856+
'description> home timeline.</description>'
857+
'<language>fr</language>'
858+
'<lastBuildDate></lastBuildDate>'
859+
'<item>'
860+
'<title>User (UserD): What\'s New in #python today?</title>'
861+
'<link>https://mastodon.social/@UserD/111111111111111111</link>'
862+
'<description>&lt;blockquote&gt;&lt;div&gt;&lt;img src="https://files.'
863+
'mastodon.social/accounts/avatars/000/000/000/original/DxDxDxDxDxDxDxDx'
864+
'.jpg" alt="User" width= 100px"/&gt; &lt;strong&gt;User: &lt;/strong&gt'
865+
';&lt;p&gt;What\'s New in &lt;a href="https://linuxjobs.social/tags/'
866+
'python" class="mention hashtag" rel="nofollow noopener" target="_blank'
867+
'"&gt;#&lt;span&gt;python&lt;/span&gt;&lt;/a&gt; today?&lt;/p&gt;&lt;br'
868+
'&gt;♻ : 0, ✰ : 0&lt;/div&gt;&lt;/blockquote&gt;</description>'
869+
'<pubDate>Thu, 25 Oct 2018 16:16:42 +0200</pubDate>'
870+
'</item>'
871+
'</channel>'
872+
'</rss>'
873+
)
874+
875+
toot_100_home_timeline_feed = (
876+
'<?xml version="1.0" encoding="UTF-8"?>\n'
877+
'<rss version="2.0">'
878+
'<channel>'
879+
'<title>Recherche Mastodon : Home Timeline</title>'
880+
'<link>https://mastodon.social</link><'
881+
'description> home timeline.</description>'
882+
'<language>fr</language>'
883+
'<lastBuildDate></lastBuildDate>'
884+
+ (
885+
'<item>'
886+
'<title>User (UserD): What\'s New in #python today?</title>'
887+
'<link>https://mastodon.social/@UserD/111111111111111111</link>'
888+
'<description>&lt;blockquote&gt;&lt;div&gt;&lt;img src="https://files.'
889+
'mastodon.social/accounts/avatars/000/000/000/original/'
890+
'DxDxDxDxDxDxDxDx.jpg" alt="User" width= 100px"/&gt; &lt;strong&gt;'
891+
'User: &lt;/strong&gt;&lt;p&gt;What\'s New in &lt;a href="https://'
892+
'linuxjobs.social/tags/python" class="mention hashtag" rel="nofollow '
893+
'noopener" target="_blank"&gt;#&lt;span&gt;python&lt;/span&gt;&lt;/a&'
894+
'gt; today?&lt;/p&gt;&lt;br&gt;♻ : 0, ✰ : 0&lt;/div&gt;&lt;/blockquote'
895+
'&gt;</description>'
896+
'<pubDate>Thu, 25 Oct 2018 16:16:42 +0200</pubDate>'
897+
'</item>'
898+
)
899+
* 100
900+
+ '</channel>'
901+
'</rss>'
902+
)

twootfeed/tests/test_mastodon_feed_generation.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
toot_1_bookmarks_feed,
2121
toot_1_favorites_feed,
2222
toot_1_feed,
23+
toot_1_home_timeline_feed,
2324
toot_1_search_feed,
2425
toot_100_bookmarks_feed,
2526
toot_100_favorites_feed,
2627
toot_100_feed,
28+
toot_100_home_timeline_feed,
2729
)
2830
from .utils import MastodonApi
2931

@@ -182,6 +184,30 @@ def test_generate_xml_bookmarks_limit_ok() -> None:
182184
assert code == 200
183185

184186

187+
def test_generate_xml_home_timeline_ok() -> None:
188+
api = MastodonApi([toot1])
189+
val, code = generate_xml(api, param, target='home_timeline')
190+
val = re.sub(
191+
r'(<lastBuildDate>)(.*)(</lastBuildDate>)',
192+
'<lastBuildDate></lastBuildDate>',
193+
val,
194+
)
195+
assert val == toot_1_home_timeline_feed
196+
assert code == 200
197+
198+
199+
def test_generate_xml_home_timeline_limit_ok() -> None:
200+
api = MastodonApi([toot1] * 150)
201+
val, code = generate_xml(api, param, target='home_timeline')
202+
val = re.sub(
203+
r'(<lastBuildDate>)(.*)(</lastBuildDate>)',
204+
'<lastBuildDate></lastBuildDate>',
205+
val,
206+
)
207+
assert val == toot_100_home_timeline_feed
208+
assert code == 200
209+
210+
185211
def test_it_raises_exception_when_target_is_invalid() -> None:
186212
api = MastodonApi([])
187213
with pytest.raises(Exception, match='Invalid target'):

twootfeed/tests/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ def bookmarks(self) -> List[Dict]:
9292
def favourites(self) -> List[Dict]:
9393
return self.return_result()
9494

95+
def timeline_home(self) -> List[Dict]:
96+
return self.return_result()
97+
9598
def fetch_next(self, toots: List[Dict]) -> List[Dict]:
9699
return self.return_result()
97100

0 commit comments

Comments
 (0)