<?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>Forem: frascu</title>
    <description>The latest articles on Forem by frascu (@frascu).</description>
    <link>https://forem.com/frascu</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%2F384526%2F73a198bc-3a90-4e69-997b-e25e349e8380.png</url>
      <title>Forem: frascu</title>
      <link>https://forem.com/frascu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/frascu"/>
    <language>en</language>
    <item>
      <title>Today's Tee Bot with Python and Github Actions</title>
      <dc:creator>frascu</dc:creator>
      <pubDate>Fri, 23 Oct 2020 11:55:45 +0000</pubDate>
      <link>https://forem.com/frascu/today-s-tee-bot-with-python-and-github-actions-13l3</link>
      <guid>https://forem.com/frascu/today-s-tee-bot-with-python-and-github-actions-13l3</guid>
      <description>&lt;p&gt;If you know me personally, you can see that I love nerd tee-shirts.&lt;br&gt;
There are lots of websites that sell tees with several designs.&lt;br&gt;
In particular, I prefer tee websites that propose t-shirts having designs made by little designers.&lt;br&gt;
It means that any person can create a design and send it to one of these websites. If the project is very voted by the users of online tee shop, the administrators can decide to put on sale for 24 hours. Therefore, Every day a different t-shirt is sold.&lt;/p&gt;

&lt;p&gt;Then, I decided to create a tee bot that sends today's tees sold from different tee shops.&lt;/p&gt;
&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;Every day the telegram bot extracts today's tees with web scraping and sends the images and the titles on a public telegram channel.&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;You can find the code in my GitHub repository: &lt;a href="https://github.com/frascu/varieteebot"&gt;varieteebot&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The repository contains mainly three files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;tee.py&lt;/strong&gt;: it contains the function &lt;code&gt;get_tees&lt;/code&gt; that returns a list of objects of type &lt;code&gt;Image&lt;/code&gt;.
Each object contains: 

&lt;ul&gt;
&lt;li&gt;tee title&lt;/li&gt;
&lt;li&gt;URL of the image source&lt;/li&gt;
&lt;li&gt;URL of the tee shop&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;run.py&lt;/strong&gt;: it sends the list of tees to the public telegram channel using the Telegram API. This script has two parameters:

&lt;ul&gt;
&lt;li&gt;bot token&lt;/li&gt;
&lt;li&gt;channel id &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;python-app-test.yml&lt;/strong&gt;: Github action that on the event &lt;code&gt;push&lt;/code&gt; of the branch &lt;code&gt;main&lt;/code&gt; installs the pip dependencies and executes the script using the GitHub secrets &lt;code&gt;BOT_TOKEN&lt;/code&gt; and &lt;code&gt;CHANNEL_TEST_ID&lt;/code&gt;. This action is used for the test.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;python-app-prod.yml&lt;/strong&gt;: Github action that on the event &lt;code&gt;schedule&lt;/code&gt; (every day at 7 UTC) installs the pip dependencies and executes the script using the GitHub secrets &lt;code&gt;BOT_TOKEN&lt;/code&gt; and &lt;code&gt;CHANNEL_ID&lt;/code&gt;.  This action is used for the main channel.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create the telegram bot using &lt;a href="https://t.me/botfather"&gt;BotFather&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Create a public telegram channel&lt;/li&gt;
&lt;li&gt;Add the bot as the administrator of the channel&lt;/li&gt;
&lt;li&gt;Fork my GitHub repository &lt;a href="https://github.com/frascu/varieteebot"&gt;varieteebot&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;In the repository settings create 3 secrets:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;BOT_TOKEN&lt;/code&gt;: the token returned by the BotFather and used to call the Telegram Bot API&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CHANNEL_ID&lt;/code&gt;: the public telegram channel id on which the tees are sent (&lt;em&gt;@channelname&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CHANNEL_ID_TEST&lt;/code&gt;: the channel id for the test (I used my personal chat id)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Test opening the section &lt;em&gt;Actions&lt;/em&gt; of the repository and clicking on &lt;em&gt;Tee Bot [TEST]&lt;/em&gt; and on &lt;em&gt;Run workflow&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Test in your local environment by typing the following command&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;python run.py &lt;span class="o"&gt;{&lt;/span&gt;BOT_TOKEN&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;CHANNEL_ID&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  My tee's channel
&lt;/h2&gt;

&lt;p&gt;My fantastic channel is &lt;a href="http://t.me/varietee"&gt;VarieTee&lt;/a&gt;.&lt;br&gt;
If you like it you can follow the channel and give me feedback.&lt;/p&gt;

</description>
      <category>github</category>
      <category>python</category>
      <category>actionshackathon</category>
      <category>devops</category>
    </item>
    <item>
      <title>Learning Python as Java Developer - Intro</title>
      <dc:creator>frascu</dc:creator>
      <pubDate>Thu, 09 Jul 2020 12:01:23 +0000</pubDate>
      <link>https://forem.com/frascu/learning-python-as-java-developer-intro-2l22</link>
      <guid>https://forem.com/frascu/learning-python-as-java-developer-intro-2l22</guid>
      <description>&lt;h4&gt;
  
  
  Introduction
&lt;/h4&gt;

&lt;p&gt;Hi *,&lt;br&gt;
I am Francesco and I am a Software Developer.&lt;br&gt;
I know several programming languages like Java, C, C++, PHP and Javascript. My strong skill is Java and If I could speak Java as a spoken language, it would be fantastic. Unfortunately, I have to use Italian or English :P&lt;br&gt;
If you are curious to know my working path and my course of study,  visit my &lt;a href="https://bit.ly/2AHdFbC"&gt;linkedin&lt;/a&gt; profile.&lt;/p&gt;

&lt;h4&gt;
  
  
  History
&lt;/h4&gt;

&lt;p&gt;The Italian quarantine forced me to stay at home, but it allowed me to acquire new skills by attending online courses and, when I discovered dev.to, by reading the posts here too.&lt;br&gt;
In that period I studied several topics like MongoDB, Microservices and, last but not least, Python.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Python?
&lt;/h4&gt;

&lt;p&gt;Python has attracted me and it has been love at first sight, therefore I have continued to study it.&lt;br&gt;
It has a wonderful syntax, a big community and there are a lot of open-source projects that use it. It is perfect for scripting, web, AI, big data and whatever you want. &lt;br&gt;
By using Java as the main programming language, Python seems minimalist and it is strange when you notice that one python instruction can correspond with more java instructions.&lt;br&gt;
In the end, it is very cool.&lt;/p&gt;

&lt;h4&gt;
  
  
  Goal
&lt;/h4&gt;

&lt;p&gt;With this post and the following ones, I want to learn Python as a Java Developer by sharing this path with you.&lt;/p&gt;

&lt;h4&gt;
  
  
  Regards
&lt;/h4&gt;

&lt;p&gt;See you next post!&lt;/p&gt;

&lt;p&gt;P. S. add a reaction or comment to give me feedback :)&lt;/p&gt;

</description>
      <category>java</category>
      <category>python</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
