Skip to content

Commit

Permalink
Fix kotlin weekly feed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ychescale9 committed Nov 20, 2023
1 parent bcf5b8d commit b1775fd
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 391 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,7 @@ class RealFeedClient(

context(CacheContext<KotlinWeeklyItem>)
override suspend fun loadKotlinWeeklyFeed(): List<KotlinWeeklyItem> = getFromCacheOrFetch {
httpClient.get(clientConfigs.kotlinWeeklyFeedUrl).body<KotlinWeeklyRss>().channel.items.filter {
it.creator.contains(KOTLIN_WEEKLY_TWITTER_USERNAME)
}.map {
it.copy(
title = StringEscapeUtils.unescapeXml(it.title).trim(),
description = StringEscapeUtils.unescapeXml(it.description).trim(),
creator = StringEscapeUtils.unescapeXml(it.creator).trim(),
)
}
}

companion object {
private const val KOTLIN_WEEKLY_TWITTER_USERNAME = "@KotlinWeekly"
httpClient.get(clientConfigs.kotlinWeeklyFeedUrl).body<KotlinWeeklyRss>().channel.items
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ data class KotlinWeeklyItem(
@XmlElement(true)
val title: String,
@XmlElement(true)
val description: String,
@XmlElement(true)
val link: String,
@XmlElement(true)
val guid: String,
@XmlElement(true)
@XmlSerialName(value = "creator", namespace = Namespace.dc, prefix = "")
val creator: String,
@XmlElement(true)
val pubDate: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import java.time.format.DateTimeFormatter
fun KotlinWeeklyItem.toKotlinWeeklyEntry(logoUrl: String): KotlinWeekly {
return KotlinWeekly(
id = guid,
title = title.trim().removePrefix(TITLE_PREFIX),
title = title,
publishTimestamp = LocalDateTime
.parse(pubDate, DateTimeFormatter.RFC_1123_DATE_TIME)
.toEpochSecond(ZoneOffset.UTC).toString(),
contentUrl = contentUrlRegex.find(description)?.value.orEmpty(),
contentUrl = link,
newsletterLogoUrl = logoUrl,
)
}

const val KOTLIN_WEEKLY_LOGO_URL = "https://pbs.twimg.com/profile_images/883969154667204608/26qTz9AE_400x400.jpg"

private const val TITLE_PREFIX = "@KotlinWeekly: "
private val contentUrlRegex = "https://t.co[^\"]+".toRegex()
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ server.compression.mime-types=application/json
ks.kotlin-blog-feed-url=https://blog.jetbrains.com/kotlin/feed/
ks.kotlin-youtube-feed-url=https://www.youtube.com/feeds/videos.xml?channel_id=UCP7uiEZIqci43m22KDl0sNw
ks.talking-kotlin-feed-url=https://talkingkotlin.com/feed
ks.kotlin-weekly-feed-url=https://rss.app/feeds/QKefltG2nWU9PWuu.xml
ks.kotlin-weekly-feed-url=https://us12.campaign-archive.com/feed?u=f39692e245b94f7fb693b6d82&id=93b2272cb6
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,8 @@ val DummyTalkingKotlinItem = TalkingKotlinItem(
)

val DummyKotlinWeeklyItem = KotlinWeeklyItem(
title = " @KotlinWeekly: Kotlin Weekly #312 has just been published! ",
description = " <blockquote class=\"twitter-tweet\" data-width=\"550\"><p lang=\"en\" dir=\"ltr\">Kotlin Weekly #312 has just been published! - <a href=\"https://t.co/7JzvarYb05\">https://t.co/7JzvarYb05</a></p>— Kotlin Weekly (@KotlinWeekly) <a href=\"https://twitter.com/KotlinWeekly/status/1551221582248419328?ref_src=twsrc%5Etfw\">July 24, 2022</a></blockquote> <script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script> ",
link = "https://twitter.com/KotlinWeekly/status/1551221582248419328",
guid = "21a2c7f9e24fae1631468c5507e4ff7c",
creator = " @KotlinWeekly ",
pubDate = "Sun, 24 Jul 2022 15:03:40 GMT",
title = "Kotlin Weekly #381",
link = "https://mailchi.mp/kotlinweekly/kotlin-weekly-381",
guid = "https://mailchi.mp/kotlinweekly/kotlin-weekly-381",
pubDate = "Sun, 19 Nov 2023 09:13:00 +0000",
)
Original file line number Diff line number Diff line change
Expand Up @@ -270,20 +270,16 @@ class RealFeedClientTest {

val expected = listOf(
KotlinWeeklyItem(
title = "@KotlinWeekly: Kotlin Weekly #312 has just been published!",
description = "<blockquote class=\"twitter-tweet\" data-width=\"550\"><p lang=\"en\" dir=\"ltr\">Kotlin Weekly #312 has just been published! - <a href=\"https://t.co/7JzvarYb05\">https://t.co/7JzvarYb05</a></p>— Kotlin Weekly (@KotlinWeekly) <a href=\"https://twitter.com/KotlinWeekly/status/1551221582248419328?ref_src=twsrc%5Etfw\">July 24, 2022</a></blockquote> <script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>",
link = "https://twitter.com/KotlinWeekly/status/1551221582248419328",
guid = "21a2c7f9e24fae1631468c5507e4ff7c",
creator = "@KotlinWeekly",
pubDate = "Sun, 24 Jul 2022 15:03:40 GMT",
title = "Kotlin Weekly #381",
link = "https://mailchi.mp/kotlinweekly/kotlin-weekly-381",
guid = "https://mailchi.mp/kotlinweekly/kotlin-weekly-381",
pubDate = "Sun, 19 Nov 2023 09:13:00 +0000",
),
KotlinWeeklyItem(
title = "@KotlinWeekly: Kotlin Weekly #311 has just been published!",
description = "<blockquote class=\"twitter-tweet\" data-width=\"550\"><p lang=\"en\" dir=\"ltr\">Kotlin Weekly #311 has just been published! - <a href=\"https://t.co/o3TtU1evhD\">https://t.co/o3TtU1evhD</a></p>— Kotlin Weekly (@KotlinWeekly) <a href=\"https://twitter.com/KotlinWeekly/status/1548584086289121281?ref_src=twsrc%5Etfw\">July 17, 2022</a></blockquote> <script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>",
link = "https://twitter.com/KotlinWeekly/status/1548584086289121281",
guid = "a2871bba25914e5fc06ed853674b16ef",
creator = "@KotlinWeekly",
pubDate = "Sun, 17 Jul 2022 08:23:12 GMT",
title = "Kotlin Weekly #380",
link = "https://mailchi.mp/kotlinweekly/kotlin-weekly-380",
guid = "https://mailchi.mp/kotlinweekly/kotlin-weekly-380",
pubDate = "Sun, 12 Nov 2023 09:14:59 +0000",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ class KotlinWeeklyEntryMapperTest {
@Test
fun `toKotlinWeeklyEntry() converts KotlinWeeklyItem to KotlinWeekly`() {
val expected = KotlinWeekly(
id = "21a2c7f9e24fae1631468c5507e4ff7c",
title = "Kotlin Weekly #312 has just been published!",
publishTimestamp = "1658675020",
contentUrl = "https://t.co/7JzvarYb05",
id = "https://mailchi.mp/kotlinweekly/kotlin-weekly-381",
title = "Kotlin Weekly #381",
publishTimestamp = "1700385180",
contentUrl = "https://mailchi.mp/kotlinweekly/kotlin-weekly-381",
newsletterLogoUrl = "logo-url",
)
val actual = KotlinWeeklyItem(
title = " @KotlinWeekly: Kotlin Weekly #312 has just been published! ",
description = " <blockquote class=\"twitter-tweet\" data-width=\"550\"><p lang=\"en\" dir=\"ltr\">Kotlin Weekly #312 has just been published! - <a href=\"https://t.co/7JzvarYb05\">https://t.co/7JzvarYb05</a></p>— Kotlin Weekly (@KotlinWeekly) <a href=\"https://twitter.com/KotlinWeekly/status/1551221582248419328?ref_src=twsrc%5Etfw\">July 24, 2022</a></blockquote> <script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script> ",
link = "https://twitter.com/KotlinWeekly/status/1551221582248419328",
guid = "21a2c7f9e24fae1631468c5507e4ff7c",
creator = " @KotlinWeekly ",
pubDate = "Sun, 24 Jul 2022 15:03:40 GMT",
title = "Kotlin Weekly #381",
link = "https://mailchi.mp/kotlinweekly/kotlin-weekly-381",
guid = "https://mailchi.mp/kotlinweekly/kotlin-weekly-381",
pubDate = "Sun, 19 Nov 2023 09:13:00 +0000",
).toKotlinWeeklyEntry(logoUrl = "logo-url")

assertEquals(expected, actual)
Expand Down
Loading

0 comments on commit b1775fd

Please sign in to comment.