From 4d46307405c40037cabb29dc846afb758fb30277 Mon Sep 17 00:00:00 2001 From: FlorentLvr Date: Fri, 28 Jun 2024 13:09:09 +0200 Subject: [PATCH] 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": {},