<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Klemens</title>
    <description>The latest articles on DEV Community by Klemens (@klemon).</description>
    <link>https://dev.to/klemon</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F839815%2F4c463638-d370-4416-b4a1-43a7703db579.jpeg</url>
      <title>DEV Community: Klemens</title>
      <link>https://dev.to/klemon</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/klemon"/>
    <language>en</language>
    <item>
      <title>Ditch Your VPN Subscription: Create Your Own Pay-As-You-Go VPN on GCP in Minutes!</title>
      <dc:creator>Klemens</dc:creator>
      <pubDate>Tue, 31 Oct 2023 21:21:36 +0000</pubDate>
      <link>https://dev.to/klemon/ditch-your-vpn-subscription-create-your-own-pay-as-you-go-vpn-on-gcp-in-minutes-4p8a</link>
      <guid>https://dev.to/klemon/ditch-your-vpn-subscription-create-your-own-pay-as-you-go-vpn-on-gcp-in-minutes-4p8a</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This guide walks you through the process of setting up a Virtual Private Server (VPS) with OpenVPN on Google Cloud Platform (GCP) using Terraform. Unlike traditional VPN services like NordVPN that require a monthly subscription, this setup allows you to pay only for the minutes you actually use. Plus, you can easily tear down and spin up your VPN server as needed, offering unparalleled flexibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Choose This Approach?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No Monthly Subscription&lt;/strong&gt;: Only pay for what you use, down to the minute.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quick Setup and Teardown&lt;/strong&gt;: Easily spin up or tear down your VPN server whenever you need it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Full Control&lt;/strong&gt;: You have complete control over the server, its security settings, and its location.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Terraform installed on your machine.&lt;/li&gt;
&lt;li&gt;A Google Cloud Platform (GCP) account with necessary permissions to create resources.&lt;/li&gt;
&lt;li&gt;Git (Optional, for cloning the repository)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Clone the Repository
&lt;/h2&gt;

&lt;p&gt;First, clone the repository containing the Terraform scripts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/kwisser/create-cloud-compute-engine-ovpn-server
&lt;span class="nb"&gt;cd &lt;/span&gt;create-cloud-compute-engine-ovpn-server/infrastructure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Step 2: Choose a Zone for Your VPN Location
&lt;/h2&gt;

&lt;p&gt;Select a suitable zone for deploying the VM instance. The choice of zone can affect the latency and speed of your VPN. You can find a list of available regions and zones on &lt;a href="https://cloud.google.com/compute/docs/regions-zones"&gt;GCP here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: Execute Terraform Scripts
&lt;/h2&gt;

&lt;p&gt;Navigate to the &lt;code&gt;infrastructure&lt;/code&gt; directory and initialize Terraform. This will download the necessary provider plugins.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;infrastructure
terraform init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now, plan and apply the Terraform configuration. This will show the resources that will be created and apply the changes, respectively. You will have to enter the following variables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;project_id&lt;/code&gt;: Your GCP project ID&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;name&lt;/code&gt;: Name of your VM instance&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;machine_type&lt;/code&gt;: Machine type (e.g., &lt;code&gt;f1-micro&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;zone&lt;/code&gt;: Zone (e.g., &lt;code&gt;us-central1-a&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;vm_username&lt;/code&gt;: Your username
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;terraform plan
terraform apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Upon successful execution, a &lt;code&gt;client.ovpn&lt;/code&gt; file will be generated in the user directory. This file can be used to connect to the VPN server from a client machine.&lt;/p&gt;
&lt;h2&gt;
  
  
  Credits
&lt;/h2&gt;

&lt;p&gt;The OpenVPN installation script is sourced from &lt;a href="https://github.com/angristan/openvpn-install"&gt;angristan/openvpn-install&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Support &amp;amp; Contributions
&lt;/h2&gt;

&lt;p&gt;For issues or contributions, feel free to open a pull request or create an issue in the repository.&lt;/p&gt;



&lt;p&gt;Enjoy the flexibility and cost-effectiveness of your own pay-as-you-go VPN server on GCP!&lt;/p&gt;

&lt;p&gt;You can find the full code in the GitHub repository &lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/kwisser"&gt;
        kwisser
      &lt;/a&gt; / &lt;a href="https://github.com/kwisser/create-cloud-compute-engine-ovpn-server"&gt;
        create-cloud-compute-engine-ovpn-server
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Terraform script which creates a compute engine in gcp which hosts a openvpn server.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h2 id="user-content-setting-up-a-vps-server-with-openvpn-on-gcp-using-terraform"&gt;&lt;a class="heading-link" href="https://github.com/kwisser/create-cloud-compute-engine-ovpn-server#setting-up-a-vps-server-with-openvpn-on-gcp-using-terraform"&gt;Setting up a VPS Server with OpenVPN on GCP using Terraform&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This guide walks through the process of setting up a Virtual Private Server (VPS) with OpenVPN on Google Cloud Platform (GCP) using Terraform. The provided Terraform script will automate the provisioning of a Google Compute Engine instance, and the installation of OpenVPN server on it. Upon successful execution, a &lt;code&gt;client.ovpn&lt;/code&gt; configuration file will be generated in the user directory, which can be used to connect to the VPN server from a client machine.&lt;/p&gt;
&lt;h3 id="user-content-pre-requisites"&gt;&lt;a class="heading-link" href="https://github.com/kwisser/create-cloud-compute-engine-ovpn-server#pre-requisites"&gt;Pre-requisites&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Ensure you have &lt;a href="https://www.terraform.io/downloads.html" rel="nofollow"&gt;Terraform installed&lt;/a&gt; on your machine.&lt;/li&gt;
&lt;li&gt;A Google Cloud Platform (GCP) account with necessary permissions to create resources.&lt;/li&gt;
&lt;li&gt;Git (Optional, for cloning the repository)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="user-content-step-1-clone-the-repository"&gt;&lt;a class="heading-link" href="https://github.com/kwisser/create-cloud-compute-engine-ovpn-server#step-1-clone-the-repository"&gt;Step 1: Clone the Repository&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Clone the repository containing the Terraform scripts.&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;git clone https://github.com/kwisser/create-cloud-compute-engine-ovpn-server
&lt;span class="pl-c1"&gt;cd&lt;/span&gt; create-cloud-compute-engine-ovpn-server/infrastructure&lt;/pre&gt;

&lt;/div&gt;
&lt;h2 id="user-content-step-2-choose-a-zone-for-your-vpn-location"&gt;&lt;a class="heading-link" href="https://github.com/kwisser/create-cloud-compute-engine-ovpn-server#step-2-choose-a-zone-for-your-vpn-location"&gt;Step 2: Choose a Zone for Your VPN Location&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Select a suitable zone for deploying the VM instance. The choice of zone…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/kwisser/create-cloud-compute-engine-ovpn-server"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;.&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>devops</category>
      <category>cloud</category>
      <category>gcp</category>
    </item>
    <item>
      <title>Developing a YouTube Subscription Analysis Application with Python</title>
      <dc:creator>Klemens</dc:creator>
      <pubDate>Tue, 08 Aug 2023 06:06:43 +0000</pubDate>
      <link>https://dev.to/klemon/developing-a-youtube-subscription-analysis-application-with-python-36ga</link>
      <guid>https://dev.to/klemon/developing-a-youtube-subscription-analysis-application-with-python-36ga</guid>
      <description>&lt;p&gt;YouTube has grown into a vast platform where users follow various channels, each representing different topics and interests. Managing these subscriptions and understanding what content you are mostly engaged with can be overwhelming. In this article, we'll walk through the creation of a Python application that analyzes a user's subscriptions and visualizes the distribution of topics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Authenticate with the YouTube API
&lt;/h2&gt;

&lt;p&gt;First, we need to authenticate with the YouTube Data API v3 to access information about a user's subscriptions.&lt;/p&gt;

&lt;p&gt;Install the Google Client Library&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--upgrade&lt;/span&gt; google-auth-oauthlib google-auth-httplib2 google-api-python-client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Authenticate and Save Credentials&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;pickle&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;google_auth_oauthlib.flow&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;googleapiclient.discovery&lt;/span&gt;

&lt;span class="n"&gt;scopes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"https://www.googleapis.com/auth/youtube.force-ssl"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_authenticated_service&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;credentials_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"credentials.pickle"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;credentials_path&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;credentials_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"rb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;credentials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pickle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;flow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;google_auth_oauthlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;InstalledAppFlow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;from_client_secrets_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s"&gt;"client_secret.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scopes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;credentials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;flow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run_console&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;credentials_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"wb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;pickle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;youtube&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;googleapiclient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;discovery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"youtube"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"v3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;credentials&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;youtube&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Make sure to download the client_secret.json file from your Google Cloud Console.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Retrieve Subscriptions and Analyze Topics
&lt;/h2&gt;

&lt;p&gt;After authentication, we can retrieve subscriptions and count the topics using a defaultdict.&lt;/p&gt;

&lt;p&gt;Getting Subscriptions and Topics&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;collections&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;defaultdict&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_subscriptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;youtube&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;subscriptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="n"&gt;next_page_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
    &lt;span class="n"&gt;topic_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;defaultdict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;youtube&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subscriptions&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;part&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"snippet"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;mine&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;maxResults&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;pageToken&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;next_page_token&lt;/span&gt;
        &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="n"&gt;subscriptions&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"items"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;next_page_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"nextPageToken"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;next_page_token&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;subscription&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;subscriptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;snippet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"snippet"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;channelId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;snippet&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"resourceId"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s"&gt;"channelId"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;youtube&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;channels&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;part&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"topicDetails"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;channelId&lt;/span&gt;
        &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"items"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;topicDetails&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"topicDetails"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;
            &lt;span class="n"&gt;topicCategories&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;topicDetails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"topicCategories"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;topicCategories&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;topic&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;topicCategories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;topic_count&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;topic_count&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Step 3: Visualize the Data with Matplotlib
&lt;/h2&gt;

&lt;p&gt;Finally, we visualize the counted topics using Matplotlib.&lt;/p&gt;

&lt;p&gt;Plotting the Topics&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;plot_topics&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;topic_count&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;topics&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;counts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;zip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;topic_count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;topics&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;xlabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Topics'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ylabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Counts'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Distribution of Topics in YouTube Subscriptions'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;xticks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rotation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'vertical'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Running the Full Code&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;youtube&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_authenticated_service&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;topic_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_subscriptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;youtube&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;plot_topics&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;topic_count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We've created an application that authenticates with the YouTube API, analyzes subscriptions, and visualizes the distribution of topics. This is an excellent starting point for anyone interested in YouTube data analysis.&lt;/p&gt;

&lt;p&gt;You can find the full code in the GitHub repository &lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/kwisser"&gt;
        kwisser
      &lt;/a&gt; / &lt;a href="https://github.com/kwisser/youtube-subscription-analyzer"&gt;
        youtube-subscription-analyzer
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      YouTube Subscriptions Analyzer is a Python script that authenticates with the YouTube API, fetches a user's subscriptions, and visualizes the distribution of topics in a pie chart.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1 id="user-content-youtube-subscriptions-analyzer"&gt;&lt;a class="heading-link" href="https://github.com/kwisser/youtube-subscription-analyzer#youtube-subscriptions-analyzer"&gt;YouTube Subscriptions Analyzer&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;YouTube Subscriptions Analyzer is a Python script that authenticates with the YouTube API, fetches a user's subscriptions, and visualizes the distribution of topics in a pie chart.&lt;/p&gt;
&lt;h2 id="user-content-features"&gt;&lt;a class="heading-link" href="https://github.com/kwisser/youtube-subscription-analyzer#features"&gt;Features&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Retrieves a user's YouTube subscriptions&lt;/li&gt;
&lt;li&gt;Aggregates topics across all subscriptions&lt;/li&gt;
&lt;li&gt;Visualizes the distribution of topics in a pie chart&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/kwisser/youtube-subscription-analyzer/blob/main/images/screenshot_distribution_of_youtube_subscriptions.JPG"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nWVuX6vs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/kwisser/youtube-subscription-analyzer/raw/main/images/screenshot_distribution_of_youtube_subscriptions.JPG" alt="Screenshot of the app"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="user-content-requirements"&gt;&lt;a class="heading-link" href="https://github.com/kwisser/youtube-subscription-analyzer#requirements"&gt;Requirements&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Python 3.6 or higher&lt;/li&gt;
&lt;li&gt;Google API credentials&lt;/li&gt;
&lt;li&gt;Libraries: google-auth-oauthlib, googleapiclient, matplotlib&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="user-content-setup"&gt;&lt;a class="heading-link" href="https://github.com/kwisser/youtube-subscription-analyzer#setup"&gt;Setup&lt;/a&gt;&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Clone the Repository&lt;/strong&gt;:&lt;/p&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;git clone https://github.com/kwisser/YoutubeSubscriptions.git
cd youtube-subscriptions-analyzer
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Install Dependencies&lt;/strong&gt;:&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;pip install google-auth-oauthlib google-auth-httplib2 google-api-python-client matplotlib&lt;/pre&gt;

&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Set up Google API credentials&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Visit the &lt;a href="https://console.developers.google.com/" rel="nofollow"&gt;Google Developer Console&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Create a project and set up the YouTube API v3 credentials.&lt;/li&gt;
&lt;li&gt;Download the &lt;code&gt;client_secret.json&lt;/code&gt; file and place it in the project's root directory.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="user-content-usage"&gt;&lt;a class="heading-link" href="https://github.com/kwisser/youtube-subscription-analyzer#usage"&gt;Usage&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Run the script with:&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;python main.py&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Follow the on-screen instructions to authenticate with your Google account. The script will fetch your YouTube subscriptions and generate a pie chart.&lt;/p&gt;
&lt;h2 id="user-content-contributing"&gt;&lt;a class="heading-link" href="https://github.com/kwisser/youtube-subscription-analyzer#contributing"&gt;Contributing&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;If you'd like to…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/kwisser/youtube-subscription-analyzer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>opensource</category>
      <category>datascience</category>
    </item>
  </channel>
</rss>
