From 7ebcb3b62210365e1038364f01a746143c04339a Mon Sep 17 00:00:00 2001 From: Alex Nodeland Date: Thu, 20 Jun 2024 15:35:32 -0400 Subject: [PATCH 1/3] feat: add tiktok trending song --- .../TikTok_Get_keyword_trending_songs.ipynb | 699 ++++++++++++++++++ 1 file changed, 699 insertions(+) create mode 100644 TikTok/TikTok_Get_keyword_trending_songs.ipynb diff --git a/TikTok/TikTok_Get_keyword_trending_songs.ipynb b/TikTok/TikTok_Get_keyword_trending_songs.ipynb new file mode 100644 index 0000000000..e8466ae972 --- /dev/null +++ b/TikTok/TikTok_Get_keyword_trending_songs.ipynb @@ -0,0 +1,699 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "81cc5584", + "metadata": {}, + "source": [ + "\"TikTok.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "compressed-wilson", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# TikTok - Get trending songs by keyword" + ] + }, + { + "cell_type": "markdown", + "id": "religious-programmer", + "metadata": {}, + "source": [ + "**Tags:** #tiktok #content #trends #songs" + ] + }, + { + "cell_type": "markdown", + "id": "1fe9f56e-561c-4f52-aef8-b861c9462107", + "metadata": {}, + "source": [ + "**Author:** [Alex Nodeland](https://www.linkedin.com/in/alexnodeland/)" + ] + }, + { + "cell_type": "markdown", + "id": "0de144be-594d-463e-9849-696fb2f6d1a8", + "metadata": {}, + "source": [ + "**Last update:** 2024-06-20 (Created: 2024-06-20)" + ] + }, + { + "cell_type": "markdown", + "id": "31ea7cdb-e10d-43fc-b026-f69249a59736", + "metadata": {}, + "source": [ + "**Description:** This notebook demonstrates how to extract the top trending songs on top trending platform, TikTok, by keyword." + ] + }, + { + "cell_type": "markdown", + "id": "d4b89388-5cd5-409a-8169-c53cc8dfab96", + "metadata": {}, + "source": [ + "**References:**\n", + "- [Naas Documentation](https://site.naas.ai/)\n", + "- [Apify TikTok Scraper Documentation](https://apify.com/clockworks/tiktok-scraper)" + ] + }, + { + "cell_type": "markdown", + "id": "distinguished-truth", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "numeric-mediterranean", + "metadata": {}, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "potential-surfing", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "from datetime import datetime\n", + "import nest_asyncio\n", + "import pandas as pd\n", + "try:\n", + " from apify_client import ApifyClient\n", + "except:\n", + " !pip install --user apify-client\n", + " from apify_client import ApifyClient" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "52badee0", + "metadata": {}, + "outputs": [], + "source": [ + "nest_asyncio.apply()" + ] + }, + { + "cell_type": "markdown", + "id": "aggressive-trustee", + "metadata": {}, + "source": [ + "### Setup variables\n", + "\n", + "\n", + "**Mandatory**\n", + "- `APIFY_API_TOKEN`: This variable represents the API token required to access the Apify TikTok Scraper API. You can obtain this token by signing up on the Apify platform.\n", + "- `searchQueries`: This variable represents the keywords for which you want to extract the top trending songs on TikTok.\n", + "\n", + "\n", + "**Optional**\n", + "\n", + "- `hashtags`: This variable represents the hashtags you want to search for in the TikTok videos. If not provided, the default value is `None`.\n", + "- `resultsPerPage`: This variable represents the number of results per page. If not provided, the default value is `100`." + ] + }, + { + "cell_type": "markdown", + "id": "323e09ce", + "metadata": {}, + "source": [ + "#### Apify API Token" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "id": "continuous-melbourne", + "metadata": {}, + "outputs": [], + "source": [ + "# Mandatory\n", + "APIFY_API_TOKEN = 'apify_api_........'\n", + "searchQueries = ['afrobeat']\n", + "\n", + "# Optional - modify if desired\n", + "hashtags = []\n", + "resultsPerPage = 5\n", + "\n", + "# Prepare the actor input\n", + "RUN_INPUT = {\n", + " \"hashtags\": hashtags,\n", + " \"resultsPerPage\": resultsPerPage,\n", + " \"searchQueries\": searchQueries\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "af18cb32", + "metadata": {}, + "source": [ + "#### Create connection object" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "id": "11dc686a", + "metadata": {}, + "outputs": [], + "source": [ + "client = ApifyClient(APIFY_API_TOKEN)" + ] + }, + { + "cell_type": "markdown", + "id": "registered-showcase", + "metadata": {}, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "tested-astrology", + "metadata": {}, + "source": [ + "### Get data from Apify TikTok Scraper API" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "id": "crude-louisville", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "def get_songs_by_keyword(run_input) -> pd.DataFrame:\n", + " \"\"\"\n", + " Get songs by keyword\n", + "\n", + " Args:\n", + " keyword (str): keyword to search for\n", + "\n", + " Returns:\n", + " response (pd.DataFrame): DataFrame with songs\n", + " \"\"\"\n", + " print(f\"Searching for songs with keyword: {run_input['searchQueries']}\")\n", + " \n", + " try:\n", + " # Run the Actor and wait for it to finish\n", + " run = client.actor(\"clockworks/tiktok-scraper\").call(run_input=run_input)\n", + " print(f\"Actor run completed successfully, with id: {run['id']}\")\n", + "\n", + " # Fetch Actor results from the run's dataset\n", + " items = [item for item in client.dataset(run[\"defaultDatasetId\"]).iterate_items()]\n", + "\n", + " # Convert the list of items to a DataFrame\n", + " response = pd.DataFrame(items)\n", + " except Exception as e:\n", + " print(f\"An error occurred while running the actor: {e}\")\n", + " response = pd.DataFrame()\n", + "\n", + " return response" + ] + }, + { + "cell_type": "markdown", + "id": "eb8fe904", + "metadata": {}, + "source": [ + "### Extract data from the response" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "31247107", + "metadata": {}, + "outputs": [], + "source": [ + "# Instantiate the ABI Content Table Data Model as a pandas dataframe\n", + "attributes = {\n", + " \"ENTITY\": [],\n", + " \"SCENARIO\": [],\n", + " \"SOURCE\": [],\n", + " \"PUBLISHED_DATE\": [],\n", + " \"DATE & TIME\": [],\n", + " \"ID\": [],\n", + " \"TITLE\": [],\n", + " \"TEXT\": [],\n", + " \"CONCEPT\": [],\n", + " \"SENTIMENT\": [],\n", + " \"TARGET\": [],\n", + " \"OBJECTIVE\": [],\n", + " \"VIEWS\": [],\n", + " \"LIKES\": [],\n", + " \"COMMENTS\": [],\n", + " \"SHARES\": [],\n", + " \"ENGAGEMENTS\": [],\n", + " \"ENGAGEMENT_SCORE\": [],\n", + " \"TYPE\": [],\n", + " \"AUTHOR_NAME\": [],\n", + " \"AUTHOR_URL\": [],\n", + " \"LENGTH\": [],\n", + " \"PEOPLE_MENTIONED\": [],\n", + " \"ORGANIZATION_MENTIONED\": [],\n", + " \"CONTENT_TITLE_SHARED\": [],\n", + " \"CONTENT_URL_SHARED\": [],\n", + " \"LINKEDIN_LINKS\": [],\n", + " \"IMAGE_SHARED\": [],\n", + " \"TAGS\": [],\n", + " \"URL\": [],\n", + " \"DATE_EXTRACT\": [],\n", + " \"SCENARIO_ORDER\": []\n", + "}\n", + "content_template = pd.DataFrame(attributes)\n", + "\n", + "def extract_data(response: pd.DataFrame, content_template: pd.DataFrame) -> pd.DataFrame:\n", + " \"\"\"\n", + " Extract data from response\n", + "\n", + " Args:\n", + " response (pd.DataFrame): DataFrame with songs\n", + "\n", + " Returns:\n", + " content (pd.DataFrame): DataFrame with extracted data\n", + " \"\"\"\n", + " print(f\"Extracting data from response\")\n", + " content = content_template.copy()\n", + " try:\n", + " content = pd.concat([content, response.apply(lambda row: pd.Series({\n", + " \"ENTITY\": row['musicMeta']['musicName'],\n", + " \"SCENARIO\": f\"Trending {row['searchQuery']} Songs on TikTok\",\n", + " \"SOURCE\": \"TikTok\",\n", + " \"PUBLISHED_DATE\": row['createTimeISO'],\n", + " \"DATE & TIME\": datetime.now().strftime(\"%Y-%m-%dT%H:%M:%S.000Z\"),\n", + " \"ID\": row['id'],\n", + " \"TITLE\": row['musicMeta']['musicName'],\n", + " \"TEXT\": row['text'],\n", + " \"CONCEPT\": \"\",\n", + " \"SENTIMENT\": \"\",\n", + " \"TARGET\": \"\",\n", + " \"OBJECTIVE\": \"\",\n", + " \"VIEWS\": row['playCount'],\n", + " \"LIKES\": row['diggCount'],\n", + " \"COMMENTS\": row['commentCount'],\n", + " \"SHARES\": row['shareCount'],\n", + " \"ENGAGEMENTS\": row['diggCount'] + row['commentCount'] + row['shareCount'] + row['collectCount'],\n", + " \"ENGAGEMENT_SCORE\": \"\",\n", + " \"TYPE\": \"video\",\n", + " \"AUTHOR_NAME\": row['authorMeta']['nickName'],\n", + " \"AUTHOR_URL\": f\"https://www.tiktok.com/@{row['authorMeta']['name']}\",\n", + " \"LENGTH\": row['videoMeta']['duration'],\n", + " \"PEOPLE_MENTIONED\": \", \".join(row['mentions']) if 'mentions' in row else '',\n", + " \"ORGANIZATION_MENTIONED\": \"\",\n", + " \"CONTENT_TITLE_SHARED\": \"\",\n", + " \"CONTENT_URL_SHARED\": \"\",\n", + " \"LINKEDIN_LINKS\": \"\",\n", + " \"IMAGE_SHARED\": row['videoMeta']['coverUrl'],\n", + " \"TAGS\": \", \".join([tag['name'] for tag in row['hashtags']]) if 'hashtags' in row else '',\n", + " \"URL\": row['webVideoUrl'],\n", + " \"DATE_EXTRACT\": datetime.now().strftime(\"%Y-%m-%dT%H:%M:%S.000Z\"),\n", + " \"SCENARIO_ORDER\": \"\"\n", + " }), axis=1)], ignore_index=True)\n", + " print(f\"Data extracted successfully\")\n", + " except Exception as e:\n", + " print(f\"An error occurred while extracting data: {e}\")\n", + " return content" + ] + }, + { + "cell_type": "markdown", + "id": "lonely-pacific", + "metadata": { + "execution": { + "iopub.execute_input": "2021-07-02T23:32:10.789097Z", + "iopub.status.busy": "2021-07-02T23:32:10.788829Z", + "iopub.status.idle": "2021-07-02T23:32:10.796900Z", + "shell.execute_reply": "2021-07-02T23:32:10.796358Z", + "shell.execute_reply.started": "2021-07-02T23:32:10.789033Z" + } + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "890f7c86-b7bb-4f5d-9a1b-e492dd9580fd", + "metadata": {}, + "source": [ + "### Call the function" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "9c4e3b7b-6440-4844-8054-265f1aec65eb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The input is: \n", + " {'hashtags': [], 'resultsPerPage': 5, 'searchQueries': ['afrobeat']}\n", + "Searching for songs with keyword: ['afrobeat']\n", + "Actor run completed successfully, with id: yw2K9hdwSjKboHZhr\n" + ] + } + ], + "source": [ + "print(f\"The input is: \\n\", RUN_INPUT)\n", + "response = get_songs_by_keyword(RUN_INPUT)" + ] + }, + { + "cell_type": "markdown", + "id": "2209a3f2", + "metadata": {}, + "source": [ + "### Extract the output from the response" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "id": "8479fff7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Extracting data from response\n", + "Data extracted successfully\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
ENTITYSCENARIOSOURCEPUBLISHED_DATEDATE & TIMEIDTITLETEXTCONCEPTSENTIMENT...PEOPLE_MENTIONEDORGANIZATION_MENTIONEDCONTENT_TITLE_SHAREDCONTENT_URL_SHAREDLINKEDIN_LINKSIMAGE_SHAREDTAGSURLDATE_EXTRACTSCENARIO_ORDER
0son originalTrending afrobeat Songs on TikTokTikTok2023-03-09T17:43:04.000Z2024-06-20T15:32:29.000Z7208603444557450501son originalYeah i need a MOTIVE #fyp #afrobeats #trending......https://p16-sign-va.tiktokcdn.com/obj/tos-mali...fyp, afrobeats, trending, h4zehttps://www.tiktok.com/@itzh4ze/video/72086034...2024-06-20T15:32:29.000Z
1original soundTrending afrobeat Songs on TikTokTikTok2023-07-11T16:07:57.000Z2024-06-20T15:32:29.000Z7254593493585104155original soundThe vibe is just right 👌🏼🔥 @IFETE ⏳ #afrobeats......@IFETEhttps://p16-sign-useast2a.tiktokcdn.com/obj/to..., afrobeats, afrobeat, afrodance, afrodancershttps://www.tiktok.com/@afrodance.1/video/7254...2024-06-20T15:32:29.000Z
2DJ Phaphane Mashup Afrobeats 2022Trending afrobeat Songs on TikTokTikTok2023-12-05T23:01:28.000Z2024-06-20T15:32:29.000Z7309249546570288417DJ Phaphane Mashup Afrobeats 2022If you got them all we are offically friends🤝💙......@DJhttps://p16-sign-useast2a.tiktokcdn.com/obj/to...afrobeatsdancechallenge, dance, foryou, afroda...https://www.tiktok.com/@jacobworth01/video/730...2024-06-20T15:32:29.000Z
3Sip (Alcohol)Trending afrobeat Songs on TikTokTikTok2023-03-19T10:33:07.000Z2024-06-20T15:32:29.000Z7212203499260529926Sip (Alcohol)#joeboy #sip #alcohol #songlyrics #afrobeats #......https://p16-sign-va.tiktokcdn.com/tos-maliva-p...joeboy, sip, alcohol, songlyrics, afrobeats, k...https://www.tiktok.com/@kingflickr/video/72122...2024-06-20T15:32:29.000Z
4original soundTrending afrobeat Songs on TikTokTikTok2024-02-04T13:47:49.000Z2024-06-20T15:32:29.000Z7331743101570108677original sound#ayrastarr #commas #lyricsvideo #afrobeats #af......https://p16-sign-va.tiktokcdn.com/obj/tos-mali...ayrastarr, commas, lyricsvideo, afrobeats, afr...https://www.tiktok.com/@lyricsvillla/video/733...2024-06-20T15:32:29.000Z
\n", + "

5 rows × 32 columns

\n", + "
" + ], + "text/plain": [ + " ENTITY SCENARIO \\\n", + "0 son original Trending afrobeat Songs on TikTok \n", + "1 original sound Trending afrobeat Songs on TikTok \n", + "2 DJ Phaphane Mashup Afrobeats 2022 Trending afrobeat Songs on TikTok \n", + "3 Sip (Alcohol) Trending afrobeat Songs on TikTok \n", + "4 original sound Trending afrobeat Songs on TikTok \n", + "\n", + " SOURCE PUBLISHED_DATE DATE & TIME \\\n", + "0 TikTok 2023-03-09T17:43:04.000Z 2024-06-20T15:32:29.000Z \n", + "1 TikTok 2023-07-11T16:07:57.000Z 2024-06-20T15:32:29.000Z \n", + "2 TikTok 2023-12-05T23:01:28.000Z 2024-06-20T15:32:29.000Z \n", + "3 TikTok 2023-03-19T10:33:07.000Z 2024-06-20T15:32:29.000Z \n", + "4 TikTok 2024-02-04T13:47:49.000Z 2024-06-20T15:32:29.000Z \n", + "\n", + " ID TITLE \\\n", + "0 7208603444557450501 son original \n", + "1 7254593493585104155 original sound \n", + "2 7309249546570288417 DJ Phaphane Mashup Afrobeats 2022 \n", + "3 7212203499260529926 Sip (Alcohol) \n", + "4 7331743101570108677 original sound \n", + "\n", + " TEXT CONCEPT SENTIMENT ... \\\n", + "0 Yeah i need a MOTIVE #fyp #afrobeats #trending... ... \n", + "1 The vibe is just right 👌🏼🔥 @IFETE ⏳ #afrobeats... ... \n", + "2 If you got them all we are offically friends🤝💙... ... \n", + "3 #joeboy #sip #alcohol #songlyrics #afrobeats #... ... \n", + "4 #ayrastarr #commas #lyricsvideo #afrobeats #af... ... \n", + "\n", + " PEOPLE_MENTIONED ORGANIZATION_MENTIONED CONTENT_TITLE_SHARED \\\n", + "0 \n", + "1 @IFETE \n", + "2 @DJ \n", + "3 \n", + "4 \n", + "\n", + " CONTENT_URL_SHARED LINKEDIN_LINKS \\\n", + "0 \n", + "1 \n", + "2 \n", + "3 \n", + "4 \n", + "\n", + " IMAGE_SHARED \\\n", + "0 https://p16-sign-va.tiktokcdn.com/obj/tos-mali... \n", + "1 https://p16-sign-useast2a.tiktokcdn.com/obj/to... \n", + "2 https://p16-sign-useast2a.tiktokcdn.com/obj/to... \n", + "3 https://p16-sign-va.tiktokcdn.com/tos-maliva-p... \n", + "4 https://p16-sign-va.tiktokcdn.com/obj/tos-mali... \n", + "\n", + " TAGS \\\n", + "0 fyp, afrobeats, trending, h4ze \n", + "1 , afrobeats, afrobeat, afrodance, afrodancers \n", + "2 afrobeatsdancechallenge, dance, foryou, afroda... \n", + "3 joeboy, sip, alcohol, songlyrics, afrobeats, k... \n", + "4 ayrastarr, commas, lyricsvideo, afrobeats, afr... \n", + "\n", + " URL \\\n", + "0 https://www.tiktok.com/@itzh4ze/video/72086034... \n", + "1 https://www.tiktok.com/@afrodance.1/video/7254... \n", + "2 https://www.tiktok.com/@jacobworth01/video/730... \n", + "3 https://www.tiktok.com/@kingflickr/video/72122... \n", + "4 https://www.tiktok.com/@lyricsvillla/video/733... \n", + "\n", + " DATE_EXTRACT SCENARIO_ORDER \n", + "0 2024-06-20T15:32:29.000Z \n", + "1 2024-06-20T15:32:29.000Z \n", + "2 2024-06-20T15:32:29.000Z \n", + "3 2024-06-20T15:32:29.000Z \n", + "4 2024-06-20T15:32:29.000Z \n", + "\n", + "[5 rows x 32 columns]" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "content = extract_data(response, content_template)\n", + "# Save the extracted data to a CSV file\n", + "content.to_csv('trending_songs.csv', index=False)\n", + "content" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.3.3" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 81e92ddddf2106bb13199294943f1925922d9c46 Mon Sep 17 00:00:00 2001 From: Alex Nodeland Date: Fri, 21 Jun 2024 09:20:44 -0400 Subject: [PATCH 2/3] feat: add more music metadata attributes --- .../TikTok_Get_keyword_trending_songs.ipynb | 274 +++++++++--------- 1 file changed, 137 insertions(+), 137 deletions(-) diff --git a/TikTok/TikTok_Get_keyword_trending_songs.ipynb b/TikTok/TikTok_Get_keyword_trending_songs.ipynb index e8466ae972..6cf0d3d6c6 100644 --- a/TikTok/TikTok_Get_keyword_trending_songs.ipynb +++ b/TikTok/TikTok_Get_keyword_trending_songs.ipynb @@ -82,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 2, "id": "potential-surfing", "metadata": { "tags": [] @@ -101,7 +101,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 3, "id": "52badee0", "metadata": {}, "outputs": [], @@ -133,18 +133,18 @@ "id": "323e09ce", "metadata": {}, "source": [ - "#### Apify API Token" + "#### Apify API Token & Query Details" ] }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 4, "id": "continuous-melbourne", "metadata": {}, "outputs": [], "source": [ "# Mandatory\n", - "APIFY_API_TOKEN = 'apify_api_........'\n", + "APIFY_API_TOKEN = 'apify_api_...'\n", "searchQueries = ['afrobeat']\n", "\n", "# Optional - modify if desired\n", @@ -169,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 5, "id": "11dc686a", "metadata": {}, "outputs": [], @@ -195,7 +195,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 6, "id": "crude-louisville", "metadata": { "papermill": {}, @@ -242,7 +242,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 11, "id": "31247107", "metadata": {}, "outputs": [], @@ -280,7 +280,14 @@ " \"TAGS\": [],\n", " \"URL\": [],\n", " \"DATE_EXTRACT\": [],\n", - " \"SCENARIO_ORDER\": []\n", + " \"SCENARIO_ORDER\": [],\n", + " \"MUSIC_NAME\": [],\n", + " \"MUSIC_AUTHOR\": [],\n", + " \"MUSIC_ORIGINAL\": [],\n", + " \"MUSIC_ALBUM\": [],\n", + " \"MUSIC_PLAY_URL\": [],\n", + " \"MUSIC_COVER_MEDIUM_URL\": [],\n", + " \"MUSIC_ID\": [],\n", "}\n", "content_template = pd.DataFrame(attributes)\n", "\n", @@ -306,30 +313,37 @@ " \"ID\": row['id'],\n", " \"TITLE\": row['musicMeta']['musicName'],\n", " \"TEXT\": row['text'],\n", - " \"CONCEPT\": \"\",\n", - " \"SENTIMENT\": \"\",\n", - " \"TARGET\": \"\",\n", - " \"OBJECTIVE\": \"\",\n", + " # \"CONCEPT\": \"\",\n", + " # \"SENTIMENT\": \"\",\n", + " # \"TARGET\": \"\",\n", + " # \"OBJECTIVE\": \"\",\n", " \"VIEWS\": row['playCount'],\n", " \"LIKES\": row['diggCount'],\n", " \"COMMENTS\": row['commentCount'],\n", " \"SHARES\": row['shareCount'],\n", " \"ENGAGEMENTS\": row['diggCount'] + row['commentCount'] + row['shareCount'] + row['collectCount'],\n", - " \"ENGAGEMENT_SCORE\": \"\",\n", + " # \"ENGAGEMENT_SCORE\": \"\",\n", " \"TYPE\": \"video\",\n", " \"AUTHOR_NAME\": row['authorMeta']['nickName'],\n", " \"AUTHOR_URL\": f\"https://www.tiktok.com/@{row['authorMeta']['name']}\",\n", " \"LENGTH\": row['videoMeta']['duration'],\n", " \"PEOPLE_MENTIONED\": \", \".join(row['mentions']) if 'mentions' in row else '',\n", - " \"ORGANIZATION_MENTIONED\": \"\",\n", - " \"CONTENT_TITLE_SHARED\": \"\",\n", - " \"CONTENT_URL_SHARED\": \"\",\n", - " \"LINKEDIN_LINKS\": \"\",\n", + " # \"ORGANIZATION_MENTIONED\": \"\",\n", + " # \"CONTENT_TITLE_SHARED\": \"\",\n", + " # \"CONTENT_URL_SHARED\": \"\",\n", + " # \"LINKEDIN_LINKS\": \"\",\n", " \"IMAGE_SHARED\": row['videoMeta']['coverUrl'],\n", " \"TAGS\": \", \".join([tag['name'] for tag in row['hashtags']]) if 'hashtags' in row else '',\n", " \"URL\": row['webVideoUrl'],\n", - " \"DATE_EXTRACT\": datetime.now().strftime(\"%Y-%m-%dT%H:%M:%S.000Z\"),\n", - " \"SCENARIO_ORDER\": \"\"\n", + " \"DATE_EXTRACT\": datetime.now().strftime(\"%Y-%m-%d\"),\n", + " # \"SCENARIO_ORDER\": \"\",\n", + " \"MUSIC_NAME\": row['musicMeta']['musicName'],\n", + " \"MUSIC_AUTHOR\": row['musicMeta']['musicAuthor'],\n", + " \"MUSIC_ORIGINAL\": row['musicMeta']['musicOriginal'],\n", + " \"MUSIC_ALBUM\": row['musicMeta']['musicAlbum'],\n", + " \"MUSIC_PLAY_URL\": row['musicMeta']['playUrl'],\n", + " \"MUSIC_COVER_MEDIUM_URL\": row['musicMeta']['coverMediumUrl'],\n", + " \"MUSIC_ID\": row['musicMeta']['musicId'],\n", " }), axis=1)], ignore_index=True)\n", " print(f\"Data extracted successfully\")\n", " except Exception as e:\n", @@ -363,7 +377,7 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 9, "id": "9c4e3b7b-6440-4844-8054-265f1aec65eb", "metadata": {}, "outputs": [ @@ -374,7 +388,7 @@ "The input is: \n", " {'hashtags': [], 'resultsPerPage': 5, 'searchQueries': ['afrobeat']}\n", "Searching for songs with keyword: ['afrobeat']\n", - "Actor run completed successfully, with id: yw2K9hdwSjKboHZhr\n" + "Actor run completed successfully, with id: rNAd6YRwX6Bd9UssA\n" ] } ], @@ -393,7 +407,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 12, "id": "8479fff7", "metadata": {}, "outputs": [ @@ -437,16 +451,16 @@ " CONCEPT\n", " SENTIMENT\n", " ...\n", - " PEOPLE_MENTIONED\n", - " ORGANIZATION_MENTIONED\n", - " CONTENT_TITLE_SHARED\n", - " CONTENT_URL_SHARED\n", - " LINKEDIN_LINKS\n", - " IMAGE_SHARED\n", - " TAGS\n", " URL\n", " DATE_EXTRACT\n", " SCENARIO_ORDER\n", + " MUSIC_NAME\n", + " MUSIC_AUTHOR\n", + " MUSIC_ORIGINAL\n", + " MUSIC_ALBUM\n", + " MUSIC_PLAY_URL\n", + " MUSIC_COVER_MEDIUM_URL\n", + " MUSIC_ID\n", " \n", " \n", " \n", @@ -456,23 +470,23 @@ " Trending afrobeat Songs on TikTok\n", " TikTok\n", " 2023-03-09T17:43:04.000Z\n", - " 2024-06-20T15:32:29.000Z\n", + " 2024-06-21T09:16:28.000Z\n", " 7208603444557450501\n", " son original\n", " Yeah i need a MOTIVE #fyp #afrobeats #trending...\n", - " \n", - " \n", + " NaN\n", + " NaN\n", " ...\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " https://p16-sign-va.tiktokcdn.com/obj/tos-mali...\n", - " fyp, afrobeats, trending, h4ze\n", " https://www.tiktok.com/@itzh4ze/video/72086034...\n", - " 2024-06-20T15:32:29.000Z\n", + " 2024-06-21\n", + " NaN\n", + " son original\n", + " DJ Phaphane\n", + " 1.0\n", + " \n", " \n", + " https://p16-sign-useast2a.tiktokcdn.com/tos-us...\n", + " 7063182037963787013\n", " \n", " \n", " 1\n", @@ -480,23 +494,23 @@ " Trending afrobeat Songs on TikTok\n", " TikTok\n", " 2023-07-11T16:07:57.000Z\n", - " 2024-06-20T15:32:29.000Z\n", + " 2024-06-21T09:16:28.000Z\n", " 7254593493585104155\n", " original sound\n", " The vibe is just right 👌🏼🔥 @IFETE ⏳ #afrobeats...\n", - " \n", - " \n", + " NaN\n", + " NaN\n", " ...\n", - " @IFETE\n", - " \n", - " \n", - " \n", - " \n", - " https://p16-sign-useast2a.tiktokcdn.com/obj/to...\n", - " , afrobeats, afrobeat, afrodance, afrodancers\n", " https://www.tiktok.com/@afrodance.1/video/7254...\n", - " 2024-06-20T15:32:29.000Z\n", + " 2024-06-21\n", + " NaN\n", + " original sound\n", + " Afro Dance\n", + " 1.0\n", + " \n", " \n", + " https://p16-sign-va.tiktokcdn.com/tos-maliva-a...\n", + " 7254593439345036059\n", " \n", " \n", " 2\n", @@ -504,23 +518,23 @@ " Trending afrobeat Songs on TikTok\n", " TikTok\n", " 2023-12-05T23:01:28.000Z\n", - " 2024-06-20T15:32:29.000Z\n", + " 2024-06-21T09:16:28.000Z\n", " 7309249546570288417\n", " DJ Phaphane Mashup Afrobeats 2022\n", " If you got them all we are offically friends🤝💙...\n", - " \n", - " \n", + " NaN\n", + " NaN\n", " ...\n", - " @DJ\n", - " \n", - " \n", - " \n", - " \n", - " https://p16-sign-useast2a.tiktokcdn.com/obj/to...\n", - " afrobeatsdancechallenge, dance, foryou, afroda...\n", " https://www.tiktok.com/@jacobworth01/video/730...\n", - " 2024-06-20T15:32:29.000Z\n", + " 2024-06-21\n", + " NaN\n", + " DJ Phaphane Mashup Afrobeats 2022\n", + " DJ Phaphane\n", + " 1.0\n", + " \n", " \n", + " https://p16-sign-useast2a.tiktokcdn.com/tos-us...\n", + " 7172939294423321349\n", " \n", " \n", " 3\n", @@ -528,23 +542,23 @@ " Trending afrobeat Songs on TikTok\n", " TikTok\n", " 2023-03-19T10:33:07.000Z\n", - " 2024-06-20T15:32:29.000Z\n", + " 2024-06-21T09:16:28.000Z\n", " 7212203499260529926\n", " Sip (Alcohol)\n", " #joeboy #sip #alcohol #songlyrics #afrobeats #...\n", - " \n", - " \n", + " NaN\n", + " NaN\n", " ...\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " https://p16-sign-va.tiktokcdn.com/tos-maliva-p...\n", - " joeboy, sip, alcohol, songlyrics, afrobeats, k...\n", " https://www.tiktok.com/@kingflickr/video/72122...\n", - " 2024-06-20T15:32:29.000Z\n", + " 2024-06-21\n", + " NaN\n", + " Sip (Alcohol)\n", + " Joeboy\n", + " 0.0\n", + " Sip (Alcohol)\n", " \n", + " https://p16-va-default.akamaized.net/img/tos-u...\n", + " 7000724233064024066\n", " \n", " \n", " 4\n", @@ -552,27 +566,27 @@ " Trending afrobeat Songs on TikTok\n", " TikTok\n", " 2024-02-04T13:47:49.000Z\n", - " 2024-06-20T15:32:29.000Z\n", + " 2024-06-21T09:16:28.000Z\n", " 7331743101570108677\n", " original sound\n", " #ayrastarr #commas #lyricsvideo #afrobeats #af...\n", - " \n", - " \n", + " NaN\n", + " NaN\n", " ...\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " https://p16-sign-va.tiktokcdn.com/obj/tos-mali...\n", - " ayrastarr, commas, lyricsvideo, afrobeats, afr...\n", " https://www.tiktok.com/@lyricsvillla/video/733...\n", - " 2024-06-20T15:32:29.000Z\n", + " 2024-06-21\n", + " NaN\n", + " original sound\n", + " lyrics villa\n", + " 1.0\n", + " \n", " \n", + " https://p16-sign-va.tiktokcdn.com/tos-maliva-a...\n", + " 7331743124488899333\n", " \n", " \n", "\n", - "

5 rows × 32 columns

\n", + "

5 rows × 39 columns

\n", "" ], "text/plain": [ @@ -584,11 +598,11 @@ "4 original sound Trending afrobeat Songs on TikTok \n", "\n", " SOURCE PUBLISHED_DATE DATE & TIME \\\n", - "0 TikTok 2023-03-09T17:43:04.000Z 2024-06-20T15:32:29.000Z \n", - "1 TikTok 2023-07-11T16:07:57.000Z 2024-06-20T15:32:29.000Z \n", - "2 TikTok 2023-12-05T23:01:28.000Z 2024-06-20T15:32:29.000Z \n", - "3 TikTok 2023-03-19T10:33:07.000Z 2024-06-20T15:32:29.000Z \n", - "4 TikTok 2024-02-04T13:47:49.000Z 2024-06-20T15:32:29.000Z \n", + "0 TikTok 2023-03-09T17:43:04.000Z 2024-06-21T09:16:28.000Z \n", + "1 TikTok 2023-07-11T16:07:57.000Z 2024-06-21T09:16:28.000Z \n", + "2 TikTok 2023-12-05T23:01:28.000Z 2024-06-21T09:16:28.000Z \n", + "3 TikTok 2023-03-19T10:33:07.000Z 2024-06-21T09:16:28.000Z \n", + "4 TikTok 2024-02-04T13:47:49.000Z 2024-06-21T09:16:28.000Z \n", "\n", " ID TITLE \\\n", "0 7208603444557450501 son original \n", @@ -597,59 +611,45 @@ "3 7212203499260529926 Sip (Alcohol) \n", "4 7331743101570108677 original sound \n", "\n", - " TEXT CONCEPT SENTIMENT ... \\\n", - "0 Yeah i need a MOTIVE #fyp #afrobeats #trending... ... \n", - "1 The vibe is just right 👌🏼🔥 @IFETE ⏳ #afrobeats... ... \n", - "2 If you got them all we are offically friends🤝💙... ... \n", - "3 #joeboy #sip #alcohol #songlyrics #afrobeats #... ... \n", - "4 #ayrastarr #commas #lyricsvideo #afrobeats #af... ... \n", - "\n", - " PEOPLE_MENTIONED ORGANIZATION_MENTIONED CONTENT_TITLE_SHARED \\\n", - "0 \n", - "1 @IFETE \n", - "2 @DJ \n", - "3 \n", - "4 \n", - "\n", - " CONTENT_URL_SHARED LINKEDIN_LINKS \\\n", - "0 \n", - "1 \n", - "2 \n", - "3 \n", - "4 \n", + " TEXT CONCEPT SENTIMENT ... \\\n", + "0 Yeah i need a MOTIVE #fyp #afrobeats #trending... NaN NaN ... \n", + "1 The vibe is just right 👌🏼🔥 @IFETE ⏳ #afrobeats... NaN NaN ... \n", + "2 If you got them all we are offically friends🤝💙... NaN NaN ... \n", + "3 #joeboy #sip #alcohol #songlyrics #afrobeats #... NaN NaN ... \n", + "4 #ayrastarr #commas #lyricsvideo #afrobeats #af... NaN NaN ... \n", "\n", - " IMAGE_SHARED \\\n", - "0 https://p16-sign-va.tiktokcdn.com/obj/tos-mali... \n", - "1 https://p16-sign-useast2a.tiktokcdn.com/obj/to... \n", - "2 https://p16-sign-useast2a.tiktokcdn.com/obj/to... \n", - "3 https://p16-sign-va.tiktokcdn.com/tos-maliva-p... \n", - "4 https://p16-sign-va.tiktokcdn.com/obj/tos-mali... \n", + " URL DATE_EXTRACT \\\n", + "0 https://www.tiktok.com/@itzh4ze/video/72086034... 2024-06-21 \n", + "1 https://www.tiktok.com/@afrodance.1/video/7254... 2024-06-21 \n", + "2 https://www.tiktok.com/@jacobworth01/video/730... 2024-06-21 \n", + "3 https://www.tiktok.com/@kingflickr/video/72122... 2024-06-21 \n", + "4 https://www.tiktok.com/@lyricsvillla/video/733... 2024-06-21 \n", "\n", - " TAGS \\\n", - "0 fyp, afrobeats, trending, h4ze \n", - "1 , afrobeats, afrobeat, afrodance, afrodancers \n", - "2 afrobeatsdancechallenge, dance, foryou, afroda... \n", - "3 joeboy, sip, alcohol, songlyrics, afrobeats, k... \n", - "4 ayrastarr, commas, lyricsvideo, afrobeats, afr... \n", + " SCENARIO_ORDER MUSIC_NAME MUSIC_AUTHOR \\\n", + "0 NaN son original DJ Phaphane \n", + "1 NaN original sound Afro Dance \n", + "2 NaN DJ Phaphane Mashup Afrobeats 2022 DJ Phaphane \n", + "3 NaN Sip (Alcohol) Joeboy \n", + "4 NaN original sound lyrics villa \n", "\n", - " URL \\\n", - "0 https://www.tiktok.com/@itzh4ze/video/72086034... \n", - "1 https://www.tiktok.com/@afrodance.1/video/7254... \n", - "2 https://www.tiktok.com/@jacobworth01/video/730... \n", - "3 https://www.tiktok.com/@kingflickr/video/72122... \n", - "4 https://www.tiktok.com/@lyricsvillla/video/733... \n", + " MUSIC_ORIGINAL MUSIC_ALBUM MUSIC_PLAY_URL \\\n", + "0 1.0 \n", + "1 1.0 \n", + "2 1.0 \n", + "3 0.0 Sip (Alcohol) \n", + "4 1.0 \n", "\n", - " DATE_EXTRACT SCENARIO_ORDER \n", - "0 2024-06-20T15:32:29.000Z \n", - "1 2024-06-20T15:32:29.000Z \n", - "2 2024-06-20T15:32:29.000Z \n", - "3 2024-06-20T15:32:29.000Z \n", - "4 2024-06-20T15:32:29.000Z \n", + " MUSIC_COVER_MEDIUM_URL MUSIC_ID \n", + "0 https://p16-sign-useast2a.tiktokcdn.com/tos-us... 7063182037963787013 \n", + "1 https://p16-sign-va.tiktokcdn.com/tos-maliva-a... 7254593439345036059 \n", + "2 https://p16-sign-useast2a.tiktokcdn.com/tos-us... 7172939294423321349 \n", + "3 https://p16-va-default.akamaized.net/img/tos-u... 7000724233064024066 \n", + "4 https://p16-sign-va.tiktokcdn.com/tos-maliva-a... 7331743124488899333 \n", "\n", - "[5 rows x 32 columns]" + "[5 rows x 39 columns]" ] }, - "execution_count": 77, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } From 4d46307405c40037cabb29dc846afb758fb30277 Mon Sep 17 00:00:00 2001 From: FlorentLvr Date: Fri, 28 Jun 2024 13:09:09 +0200 Subject: [PATCH 3/3] feat: improve description + variables description --- .../TikTok_Get_keyword_trending_songs.ipynb | 322 ++---------------- 1 file changed, 30 insertions(+), 292 deletions(-) diff --git a/TikTok/TikTok_Get_keyword_trending_songs.ipynb b/TikTok/TikTok_Get_keyword_trending_songs.ipynb index 6cf0d3d6c6..965b93427e 100644 --- a/TikTok/TikTok_Get_keyword_trending_songs.ipynb +++ b/TikTok/TikTok_Get_keyword_trending_songs.ipynb @@ -40,7 +40,7 @@ "id": "0de144be-594d-463e-9849-696fb2f6d1a8", "metadata": {}, "source": [ - "**Last update:** 2024-06-20 (Created: 2024-06-20)" + "**Last update:** 2024-06-28 (Created: 2024-06-20)" ] }, { @@ -48,7 +48,7 @@ "id": "31ea7cdb-e10d-43fc-b026-f69249a59736", "metadata": {}, "source": [ - "**Description:** This notebook demonstrates how to extract the top trending songs on top trending platform, TikTok, by keyword." + "**Description:** This notebook demonstrates how to extract the top trending songs on top trending platform, TikTok, by keyword. You need to create a free account and [rent an Actor](https://console.apify.com/actors/GdWCkxBtKWOsKjdch/input) to start playing with this template." ] }, { @@ -82,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "potential-surfing", "metadata": { "tags": [] @@ -96,16 +96,7 @@ " from apify_client import ApifyClient\n", "except:\n", " !pip install --user apify-client\n", - " from apify_client import ApifyClient" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "52badee0", - "metadata": {}, - "outputs": [], - "source": [ + " from apify_client import ApifyClient\n", "nest_asyncio.apply()" ] }, @@ -116,16 +107,15 @@ "source": [ "### Setup variables\n", "\n", - "\n", "**Mandatory**\n", - "- `APIFY_API_TOKEN`: This variable represents the API token required to access the Apify TikTok Scraper API. You can obtain this token by signing up on the Apify platform.\n", - "- `searchQueries`: This variable represents the keywords for which you want to extract the top trending songs on TikTok.\n", - "\n", + "- `APIFY_API_TOKEN`: API token required to access the [Apify TikTok Scraper API](https://console.apify.com/settings/integrations)\n", + "- `searchQueries`: Keywords for which you want to extract the top trending songs on TikTok.\n", + "- `csv_output`: CSV file path to be saved as output.\n", "\n", "**Optional**\n", "\n", - "- `hashtags`: This variable represents the hashtags you want to search for in the TikTok videos. If not provided, the default value is `None`.\n", - "- `resultsPerPage`: This variable represents the number of results per page. If not provided, the default value is `100`." + "- `hashtags`: Hashtags you want to search for in the TikTok videos. If not provided, the default value is `None`.\n", + "- `resultsPerPage`: Number of results per page. If not provided, the default value is `100`." ] }, { @@ -138,14 +128,15 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "continuous-melbourne", "metadata": {}, "outputs": [], "source": [ "# Mandatory\n", - "APIFY_API_TOKEN = 'apify_api_...'\n", + "APIFY_API_TOKEN = 'apify_api_xxxx'\n", "searchQueries = ['afrobeat']\n", + "csv_output = 'trending_songs.csv'\n", "\n", "# Optional - modify if desired\n", "hashtags = []\n", @@ -159,6 +150,14 @@ "}" ] }, + { + "cell_type": "markdown", + "id": "registered-showcase", + "metadata": {}, + "source": [ + "## Model" + ] + }, { "cell_type": "markdown", "id": "af18cb32", @@ -169,7 +168,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "11dc686a", "metadata": {}, "outputs": [], @@ -177,14 +176,6 @@ "client = ApifyClient(APIFY_API_TOKEN)" ] }, - { - "cell_type": "markdown", - "id": "registered-showcase", - "metadata": {}, - "source": [ - "## Model" - ] - }, { "cell_type": "markdown", "id": "tested-astrology", @@ -195,7 +186,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "crude-louisville", "metadata": { "papermill": {}, @@ -242,7 +233,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "31247107", "metadata": {}, "outputs": [], @@ -377,21 +368,10 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "9c4e3b7b-6440-4844-8054-265f1aec65eb", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The input is: \n", - " {'hashtags': [], 'resultsPerPage': 5, 'searchQueries': ['afrobeat']}\n", - "Searching for songs with keyword: ['afrobeat']\n", - "Actor run completed successfully, with id: rNAd6YRwX6Bd9UssA\n" - ] - } - ], + "outputs": [], "source": [ "print(f\"The input is: \\n\", RUN_INPUT)\n", "response = get_songs_by_keyword(RUN_INPUT)" @@ -407,257 +387,15 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "8479fff7", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Extracting data from response\n", - "Data extracted successfully\n" - ] - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
ENTITYSCENARIOSOURCEPUBLISHED_DATEDATE & TIMEIDTITLETEXTCONCEPTSENTIMENT...URLDATE_EXTRACTSCENARIO_ORDERMUSIC_NAMEMUSIC_AUTHORMUSIC_ORIGINALMUSIC_ALBUMMUSIC_PLAY_URLMUSIC_COVER_MEDIUM_URLMUSIC_ID
0son originalTrending afrobeat Songs on TikTokTikTok2023-03-09T17:43:04.000Z2024-06-21T09:16:28.000Z7208603444557450501son originalYeah i need a MOTIVE #fyp #afrobeats #trending...NaNNaN...https://www.tiktok.com/@itzh4ze/video/72086034...2024-06-21NaNson originalDJ Phaphane1.0https://p16-sign-useast2a.tiktokcdn.com/tos-us...7063182037963787013
1original soundTrending afrobeat Songs on TikTokTikTok2023-07-11T16:07:57.000Z2024-06-21T09:16:28.000Z7254593493585104155original soundThe vibe is just right 👌🏼🔥 @IFETE ⏳ #afrobeats...NaNNaN...https://www.tiktok.com/@afrodance.1/video/7254...2024-06-21NaNoriginal soundAfro Dance1.0https://p16-sign-va.tiktokcdn.com/tos-maliva-a...7254593439345036059
2DJ Phaphane Mashup Afrobeats 2022Trending afrobeat Songs on TikTokTikTok2023-12-05T23:01:28.000Z2024-06-21T09:16:28.000Z7309249546570288417DJ Phaphane Mashup Afrobeats 2022If you got them all we are offically friends🤝💙...NaNNaN...https://www.tiktok.com/@jacobworth01/video/730...2024-06-21NaNDJ Phaphane Mashup Afrobeats 2022DJ Phaphane1.0https://p16-sign-useast2a.tiktokcdn.com/tos-us...7172939294423321349
3Sip (Alcohol)Trending afrobeat Songs on TikTokTikTok2023-03-19T10:33:07.000Z2024-06-21T09:16:28.000Z7212203499260529926Sip (Alcohol)#joeboy #sip #alcohol #songlyrics #afrobeats #...NaNNaN...https://www.tiktok.com/@kingflickr/video/72122...2024-06-21NaNSip (Alcohol)Joeboy0.0Sip (Alcohol)https://p16-va-default.akamaized.net/img/tos-u...7000724233064024066
4original soundTrending afrobeat Songs on TikTokTikTok2024-02-04T13:47:49.000Z2024-06-21T09:16:28.000Z7331743101570108677original sound#ayrastarr #commas #lyricsvideo #afrobeats #af...NaNNaN...https://www.tiktok.com/@lyricsvillla/video/733...2024-06-21NaNoriginal soundlyrics villa1.0https://p16-sign-va.tiktokcdn.com/tos-maliva-a...7331743124488899333
\n", - "

5 rows × 39 columns

\n", - "
" - ], - "text/plain": [ - " ENTITY SCENARIO \\\n", - "0 son original Trending afrobeat Songs on TikTok \n", - "1 original sound Trending afrobeat Songs on TikTok \n", - "2 DJ Phaphane Mashup Afrobeats 2022 Trending afrobeat Songs on TikTok \n", - "3 Sip (Alcohol) Trending afrobeat Songs on TikTok \n", - "4 original sound Trending afrobeat Songs on TikTok \n", - "\n", - " SOURCE PUBLISHED_DATE DATE & TIME \\\n", - "0 TikTok 2023-03-09T17:43:04.000Z 2024-06-21T09:16:28.000Z \n", - "1 TikTok 2023-07-11T16:07:57.000Z 2024-06-21T09:16:28.000Z \n", - "2 TikTok 2023-12-05T23:01:28.000Z 2024-06-21T09:16:28.000Z \n", - "3 TikTok 2023-03-19T10:33:07.000Z 2024-06-21T09:16:28.000Z \n", - "4 TikTok 2024-02-04T13:47:49.000Z 2024-06-21T09:16:28.000Z \n", - "\n", - " ID TITLE \\\n", - "0 7208603444557450501 son original \n", - "1 7254593493585104155 original sound \n", - "2 7309249546570288417 DJ Phaphane Mashup Afrobeats 2022 \n", - "3 7212203499260529926 Sip (Alcohol) \n", - "4 7331743101570108677 original sound \n", - "\n", - " TEXT CONCEPT SENTIMENT ... \\\n", - "0 Yeah i need a MOTIVE #fyp #afrobeats #trending... NaN NaN ... \n", - "1 The vibe is just right 👌🏼🔥 @IFETE ⏳ #afrobeats... NaN NaN ... \n", - "2 If you got them all we are offically friends🤝💙... NaN NaN ... \n", - "3 #joeboy #sip #alcohol #songlyrics #afrobeats #... NaN NaN ... \n", - "4 #ayrastarr #commas #lyricsvideo #afrobeats #af... NaN NaN ... \n", - "\n", - " URL DATE_EXTRACT \\\n", - "0 https://www.tiktok.com/@itzh4ze/video/72086034... 2024-06-21 \n", - "1 https://www.tiktok.com/@afrodance.1/video/7254... 2024-06-21 \n", - "2 https://www.tiktok.com/@jacobworth01/video/730... 2024-06-21 \n", - "3 https://www.tiktok.com/@kingflickr/video/72122... 2024-06-21 \n", - "4 https://www.tiktok.com/@lyricsvillla/video/733... 2024-06-21 \n", - "\n", - " SCENARIO_ORDER MUSIC_NAME MUSIC_AUTHOR \\\n", - "0 NaN son original DJ Phaphane \n", - "1 NaN original sound Afro Dance \n", - "2 NaN DJ Phaphane Mashup Afrobeats 2022 DJ Phaphane \n", - "3 NaN Sip (Alcohol) Joeboy \n", - "4 NaN original sound lyrics villa \n", - "\n", - " MUSIC_ORIGINAL MUSIC_ALBUM MUSIC_PLAY_URL \\\n", - "0 1.0 \n", - "1 1.0 \n", - "2 1.0 \n", - "3 0.0 Sip (Alcohol) \n", - "4 1.0 \n", - "\n", - " MUSIC_COVER_MEDIUM_URL MUSIC_ID \n", - "0 https://p16-sign-useast2a.tiktokcdn.com/tos-us... 7063182037963787013 \n", - "1 https://p16-sign-va.tiktokcdn.com/tos-maliva-a... 7254593439345036059 \n", - "2 https://p16-sign-useast2a.tiktokcdn.com/tos-us... 7172939294423321349 \n", - "3 https://p16-va-default.akamaized.net/img/tos-u... 7000724233064024066 \n", - "4 https://p16-sign-va.tiktokcdn.com/tos-maliva-a... 7331743124488899333 \n", - "\n", - "[5 rows x 39 columns]" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "content = extract_data(response, content_template)\n", + "\n", "# Save the extracted data to a CSV file\n", - "content.to_csv('trending_songs.csv', index=False)\n", + "content.to_csv(csv_output, index=False)\n", "content" ] } @@ -678,7 +416,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.3" + "version": "3.9.6" }, "papermill": { "default_parameters": {},