Skip to content

Commit

Permalink
feat: integrate TikTok into API and frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpomerenke committed Oct 20, 2024
1 parent 1ded0c6 commit 06af854
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
14 changes: 13 additions & 1 deletion backend-python/media_impact_monitor/trends/keyword_trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
get_mediacloud_counts,
)
from media_impact_monitor.data_loaders.news_print.genios import get_genios_counts
from media_impact_monitor.data_loaders.social_media.tiktok import (
get_video_history_for_hashtag,
)
from media_impact_monitor.data_loaders.web.google_trends import get_google_trends_counts
from media_impact_monitor.types_ import TrendSearch
from media_impact_monitor.util.paths import src
Expand All @@ -31,6 +34,8 @@ def get_keyword_trend(q: TrendSearch) -> tuple[pd.DataFrame | None, list[str]]:
)
case "web_google":
ds = get_google_trends_counts(query=query, end_date=q.end_date)
case "social_tiktok":
ds = get_video_history_for_hashtag(query, n=1000, verbose=True)["posts"]
case _:
raise ValueError(f"Unsupported media source: {q.media_source}")
dss[topic] = ds
Expand Down Expand Up @@ -65,7 +70,14 @@ def topic_queries(media_source: str) -> dict[str, str]:
# media_source,
# ),
}
if media_source != "web_google":
if media_source == "social_tiktok":
keyword_queries = {
"climate activism": "climateprotest", # TODO: improve
"climate policy": "climateaction", # TODO: improve
"climate science": "climatechange", # TODO: improve
"climate crisis framing": "climatecrisis", # TODO: improve
}
elif media_source != "web_google":
keyword_queries["climate activism"] = xs_with_ys(
keywords["climate_science"]
+ keywords["climate_policy"]
Expand Down
2 changes: 1 addition & 1 deletion backend-python/media_impact_monitor/types_.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# FIXME: consider renaming "Topic" to "Issue" to avoid confusion with topics within the issue (like science or policy)
Topic = Literal["climate_change"]
Query = str # for now, just a single keyword
MediaSource = Literal["news_online", "news_print", "web_google"]
MediaSource = Literal["news_online", "news_print", "web_google", "social_tiktok"]

StartDateField = Field(
default=date(2020, 1, 1),
Expand Down
8 changes: 8 additions & 0 deletions frontend-nextjs/src/components/DataSourceSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
type LucideIcon,
NewspaperIcon,
SearchIcon,
Music2Icon
} from 'lucide-react'
import { useMemo, useState } from 'react'

Expand Down Expand Up @@ -52,6 +53,13 @@ const options: OptionType[] = [
description: texts.filters.mediaSource.values.printNews.description,
links: texts.filters.mediaSource.values.printNews.links,
},
{
name: texts.filters.mediaSource.values.tiktok.name,
value: 'social_tiktok',
Icon: Music2Icon,
description: texts.filters.mediaSource.values.tiktok.description,
links: texts.filters.mediaSource.values.tiktok.links,
},
{
name: texts.filters.mediaSource.values.googleTrends.name,
value: 'web_google',
Expand Down
4 changes: 2 additions & 2 deletions frontend-nextjs/src/stores/filtersStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from "zustand/middleware";


export type MediaSourceType = "news_online" | "news_print" | "web_google";
export type MediaSourceType = "news_online" | "news_print" | "social_tiktok" | "web_google";

export type FiltersState = {
from: Date;
Expand Down Expand Up @@ -80,7 +80,7 @@ const getFiltersZodSchema = (today: Date) => {
.boolean()
.default(defaultInitState.isDefaultTimeRange),
organizers: z.array(z.string()).default(defaultInitState.organizers),
mediaSource: z.enum(["news_online", "news_print", "web_google"]),
mediaSource: z.enum(["news_online", "news_print", "social_tiktok", "web_google"]),
})
.default(defaultInitState);
}
Expand Down
26 changes: 23 additions & 3 deletions frontend-nextjs/src/utility/textUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const textsEnGB = {
values: {
onlineNews: {
name: 'Online News',
description: 'Articles from online news pages.',
description: 'Articles in online news pages.',
links: [
{
label: 'Official Website',
Expand All @@ -151,7 +151,7 @@ const textsEnGB = {
},
printNews: {
name: 'Print News',
description: 'Articles from print newspapers.',
description: 'Articles in print newspapers.',
links: [
{
label: 'Official Website',
Expand All @@ -163,9 +163,19 @@ const textsEnGB = {
},
],
},
tiktok: {
name: 'TikTok',
description: 'Video posts on TikTok.',
links: [
{
label: 'Official Website',
href: 'https://www.tiktok.com/',
},
],
},
googleTrends: {
name: 'Google Trends',
description: 'Search trends from Google.',
description: 'Search trends on Google.',
links: [
{
label: 'Official Website',
Expand Down Expand Up @@ -776,6 +786,16 @@ const textsXXX = {
},
],
},
tiktok: {
name: 'XXX',
description: 'XXX',
links: [
{
label: 'XXX',
href: 'XXX',
},
],
},
googleTrends: {
name: 'XXX',
description: 'XXX',
Expand Down

0 comments on commit 06af854

Please sign in to comment.