Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion generator/generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import urllib.parse

from abc import ABC, abstractmethod
from utils.post_utils import CASSETTE_EMOJI, TROPHY_EMOJI, CLOCK_EMOJI, TV_EMOJI
Expand All @@ -14,7 +15,7 @@ def __init__(self, formatter=None, shorten_urls=False):

def get_single_watch_link_string(self, watch_link, country, include_comments=True):
has_comment = False
watch_link_string = get_short_url(watch_link['link']) if self.shorten_urls else watch_link['link']
watch_link_string = get_short_url(watch_link['link']) if self.shorten_urls else urllib.parse.quote(watch_link['link']).replace("%3A//", "://")
if include_comments and "comment" in watch_link and watch_link['comment'] != "" and watch_link['comment'] != "Recommended link":
watch_link_string += " (" + watch_link['comment'] + ")"
has_comment = True
Expand Down
13 changes: 8 additions & 5 deletions test/publisher/test_x_daily_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@ def test_when_calling_daily_publisher_with_multiple_events_should_generate_and_p
events = [
{'country': 'Australia', 'name': 'Australia Decides', 'stage': 'Final', 'dateTimeCet': '2021-02-13T10:30:00', 'watchLinks': [{'link': 'https://facebook.com', 'comment': 'Recommended link', 'live': 1}]},
{'country': 'Norway', 'name': 'Melodi Grand Prix', 'stage': 'Heat 5', 'dateTimeCet': '2021-02-13T19:50:00', 'watchLinks': [{'link': 'https://nrk.no/mgp', 'comment': 'Recommended link', 'live': 1}]},
{'country': 'Sweden', 'name': 'Melodifestivalen', 'stage': 'Heat 2', 'dateTimeCet': '2021-02-13T20:00:00', 'watchLinks': [{'link': 'https://svtplay.se', 'comment': 'Recommended link', 'live': 1}]}
{'country': 'Sweden', 'name': 'Melodifestivalen', 'stage': 'Heat 2', 'dateTimeCet': '2021-02-13T20:00:00', 'watchLinks': [{'link': 'https://svtplay.se', 'comment': 'Recommended link', 'live': 1}]},
{'country': 'Serbia', 'name': 'Pesma za Evroviziju', 'stage': 'Final', 'dateTimeCet': '2021-02-13T21:00:00', 'watchLinks': [{'link': 'https://youtu.be/@pesmaevroviziju', 'comment': 'Recommended link', 'live': 1}]}
]

summary = self.publisher.publish(events, run_date=datetime.datetime(1970, 1, 1, 16, 0, 0, 0))

self.assertEqual(len(summary), 4)
self.assertEqual(summary[0], "TONIGHT | 3 selection shows across Europe and Australia! (thread \U00002B07\U0000FE0F)")
self.assertEqual(len(summary), 5)
self.assertEqual(summary[0], "TONIGHT | 4 selection shows across Europe and Australia! (thread \U00002B07\U0000FE0F)")
self.assertEqual(summary[1], "TONIGHT | \U0001F1E6\U0001F1FA AUSTRALIA\n---------\n\U0001F4FC Australia Decides\n\U0001F3C6 Final\n\U0001F553 10:30 CET\n---------\n\U0001F4FA https://facebook.com.")
self.assertEqual(summary[2], "TONIGHT | \U0001F1F3\U0001F1F4 NORWAY\n---------\n\U0001F4FC Melodi Grand Prix\n\U0001F3C6 Heat 5\n\U0001F553 19:50 CET\n---------\n\U0001F4FA https://nrk.no/mgp.")
self.assertEqual(summary[3], "TONIGHT | \U0001F1F8\U0001F1EA SWEDEN\n---------\n\U0001F4FC Melodifestivalen\n\U0001F3C6 Heat 2\n\U0001F553 20:00 CET\n---------\n\U0001F4FA https://svtplay.se.")
self.assertEqual(summary[4], "TONIGHT | \U0001F1F7\U0001F1F8 SERBIA\n---------\n\U0001F4FC Pesma za Evroviziju\n\U0001F3C6 Final\n\U0001F553 21:00 CET\n---------\n\U0001F4FA https://youtu.be/%40pesmaevroviziju.")

published_posts = self.publisher.client.posts
self.assertEqual(len(published_posts), 4)
self.assertEqual(published_posts[0], "TONIGHT | 3 selection shows across Europe and Australia! (thread \U00002B07\U0000FE0F)")
self.assertEqual(len(published_posts), 5)
self.assertEqual(published_posts[0], "TONIGHT | 4 selection shows across Europe and Australia! (thread \U00002B07\U0000FE0F)")
self.assertEqual(published_posts[1], "TONIGHT | \U0001F1E6\U0001F1FA AUSTRALIA\n---------\n\U0001F4FC Australia Decides\n\U0001F3C6 Final\n\U0001F553 10:30 CET\n---------\n\U0001F4FA https://facebook.com.")
self.assertEqual(published_posts[2], "TONIGHT | \U0001F1F3\U0001F1F4 NORWAY\n---------\n\U0001F4FC Melodi Grand Prix\n\U0001F3C6 Heat 5\n\U0001F553 19:50 CET\n---------\n\U0001F4FA https://nrk.no/mgp.")
self.assertEqual(published_posts[3], "TONIGHT | \U0001F1F8\U0001F1EA SWEDEN\n---------\n\U0001F4FC Melodifestivalen\n\U0001F3C6 Heat 2\n\U0001F553 20:00 CET\n---------\n\U0001F4FA https://svtplay.se.")
self.assertEqual(published_posts[4], "TONIGHT | \U0001F1F7\U0001F1F8 SERBIA\n---------\n\U0001F4FC Pesma za Evroviziju\n\U0001F3C6 Final\n\U0001F553 21:00 CET\n---------\n\U0001F4FA https://youtu.be/%40pesmaevroviziju.")