|
6 | 6 | from datetime import datetime, timedelta
|
7 | 7 | import base64
|
8 | 8 | import hashlib
|
| 9 | +import random |
9 | 10 |
|
10 | 11 | import feedparser
|
11 | 12 | from mastodon import Mastodon
|
|
25 | 26 | include_link_thumbnail = True
|
26 | 27 | use_privacy_frontends = True
|
27 | 28 | use_shortlink = True
|
| 29 | +use_monetised_links = True |
28 | 30 | maximum_toots_count = 1
|
29 | 31 |
|
30 | 32 | rss_feed_url = sys.argv[1]
|
@@ -65,12 +67,24 @@ def determine_content_language(text):
|
65 | 67 |
|
66 | 68 | return language
|
67 | 69 |
|
| 70 | +def get_monetised_link(original_link): |
| 71 | + userid = '1092341' |
| 72 | + |
| 73 | + if isinstance(original_link, bytes): |
| 74 | + buffer = original_link |
| 75 | + else: |
| 76 | + buffer = original_link.encode('latin-1' if isinstance(original_link, str) else 'utf-8') |
| 77 | + |
| 78 | + encoded_link = base64.b64encode(buffer).decode('utf-8') |
| 79 | + monetised_link = f"https://link-to.net/{userid}/{random.random() * 1000}/dynamic?r={encoded_link}" |
| 80 | + |
| 81 | + return monetised_link |
| 82 | + |
68 | 83 | if not os.path.isfile("app_" + mastodon_instance + '.secret'):
|
69 | 84 | if Mastodon.create_app(
|
70 | 85 | rss_feed_domain,
|
71 | 86 | api_base_url = 'https://' + mastodon_instance,
|
72 |
| - to_file = "app_" + mastodon_instance + '.secret' |
73 |
| - ): |
| 87 | + to_file = "app_" + mastodon_instance + '.secret'): |
74 | 88 | print('Successfully created the application on instance ' + mastodon_instance)
|
75 | 89 | else:
|
76 | 90 | print('Failed to create the application on instance ' + mastodon_instance)
|
@@ -245,7 +259,7 @@ def determine_content_language(text):
|
245 | 259 | feed_entry_link = re.sub('\?utm.*$', '', feed_entry_link)
|
246 | 260 | feed_entry_link = re.sub('/$', '', feed_entry_link)
|
247 | 261 |
|
248 |
| - toot_body += '\n\n🔗 ' + feed_entry_link |
| 262 | + toot_body += '\n\n🔗 ' + get_monetised_link(feed_entry_link) |
249 | 263 |
|
250 | 264 | if include_author and 'authors' in feed_entry:
|
251 | 265 | toot_body += '\nby ' + feed_entry.authors[0].name
|
|
0 commit comments