<?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: Joaquin Guardado</title>
    <description>The latest articles on DEV Community by Joaquin Guardado (@jqn).</description>
    <link>https://dev.to/jqn</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%2F250407%2F0c51c59a-c204-4a60-ba25-2be0c124ee89.png</url>
      <title>DEV Community: Joaquin Guardado</title>
      <link>https://dev.to/jqn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jqn"/>
    <language>en</language>
    <item>
      <title>Learn To Setup Python 3 As A Default On your Mac</title>
      <dc:creator>Joaquin Guardado</dc:creator>
      <pubDate>Sat, 26 Sep 2020 06:34:25 +0000</pubDate>
      <link>https://dev.to/jqn/learn-to-setup-python-3-as-a-default-on-your-mac-1bd6</link>
      <guid>https://dev.to/jqn/learn-to-setup-python-3-as-a-default-on-your-mac-1bd6</guid>
      <description>&lt;h2&gt;
  
  
  Minimum requirements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Command Line tools or Xcode
&lt;code&gt;$ xcode-select --instal&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://brew.sh/"&gt;Homebrew&lt;/a&gt;
&lt;code&gt;$ ruby -e "$(curl -fsSL [https://raw.githubusercontent.com/Homebrew/install/master/install](https://raw.githubusercontent.com/Homebrew/install/master/install))"&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Python3
&lt;/h2&gt;

&lt;p&gt;At the time of this writing your Macbook ships with an out of date version of &lt;strong&gt;&lt;a href="https://www.python.org/download/releases/2.0/"&gt;Python&lt;/a&gt;&lt;/strong&gt;, &lt;strong&gt;version 2.7&lt;/strong&gt; which was officially deprecated on Januray 1st, 2020. This means you need to update it to version 3 before building any new projects in your local development environment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Jul  5 2020, 02:24:03)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.21) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My preferred method of achieving this is to use &lt;a href="https://brew.sh/"&gt;Homebrew&lt;/a&gt; a very popular MacOs package manager. This will allow you to switch between &lt;a href="https://www.python.org/downloads/"&gt;&lt;strong&gt;Python3&lt;/strong&gt;&lt;/a&gt; and &lt;strong&gt;&lt;a href="https://www.python.org/download/releases/2.0/"&gt;Python 2&lt;/a&gt;&lt;/strong&gt; in case you still need it. Please make sure you have it installed before continuing.&lt;/p&gt;

&lt;p&gt;Open your terminal and run the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew install python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To look at where it is installed run this command to get a similar output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ which python3
/usr/local/bin/python3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you wish to be able to run a command with just &lt;strong&gt;python&lt;/strong&gt; instead of &lt;strong&gt;python3&lt;/strong&gt; create an alias in your &lt;strong&gt;.zshrc&lt;/strong&gt;. Copy the python3 installation path from above and run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo "alias python=/usr/local/bin/python3" &amp;gt;&amp;gt; ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Close your terminal and open it back up. Now if you run the command &lt;strong&gt;python&lt;/strong&gt; you should get the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python --version
Python 3.8.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if you need &lt;strong&gt;Python 2&lt;/strong&gt;  to work on some older projects run it like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Aslo If at any time you would like to set &lt;strong&gt;Python 2&lt;/strong&gt; as default on your Mac again just remove or comment out the alias in your &lt;strong&gt;.&lt;a href="https://www.zsh.org/"&gt;zshrc&lt;/a&gt;&lt;/strong&gt; with &lt;a href="https://vim.rtorr.com/"&gt;vim&lt;/a&gt; or any editor you like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ vi ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Edit your &lt;strong&gt;.zshrc&lt;/strong&gt;  and comment out the alias.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#alias python=/usr/local/bin/python3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Pip
&lt;/h2&gt;

&lt;p&gt;Finally don't forget to update &lt;a href="https://pypi.org/project/pip/"&gt;&lt;strong&gt;pip&lt;/strong&gt;&lt;/a&gt; to &lt;strong&gt;pip3&lt;/strong&gt;. The &lt;strong&gt;pip&lt;/strong&gt; command is the default package manager for &lt;strong&gt;Python&lt;/strong&gt; packages and although the default version of python on your system was updated pip is still running on the old version. To fix that create another alias for &lt;strong&gt;pip3&lt;/strong&gt;. This will ensure the packages installed via pip are compatible with the new default version of &lt;strong&gt;Python&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;First find the location of &lt;strong&gt;pip3&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ which pip3
/usr/local/bin/pip3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create the new alias.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ echo "alias pip=/usr/local/bin/pip3" &amp;gt;&amp;gt; ~/.zshrc 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Close your terminal to reset it and run the &lt;strong&gt;pip&lt;/strong&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ which pip
pip: aliased to /usr/local/bin/pip3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! as always if you have any questions, comments or concerns feel free to reach out to me on &lt;a href="https://twitter.com/jQNReactor"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

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

</description>
      <category>python</category>
      <category>beginners</category>
      <category>productivity</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Organize Your Github  Like A Pro With This Python Script</title>
      <dc:creator>Joaquin Guardado</dc:creator>
      <pubDate>Wed, 09 Sep 2020 11:41:06 +0000</pubDate>
      <link>https://dev.to/jqn/quickly-clean-up-your-github-with-this-repo-transfer-utility-40cg</link>
      <guid>https://dev.to/jqn/quickly-clean-up-your-github-with-this-repo-transfer-utility-40cg</guid>
      <description>&lt;h2&gt;
  
  
  What? Why?
&lt;/h2&gt;

&lt;p&gt;You and I use GitHub every day and if you are anything like me very often come across an interesting repo, quickly fork it and save it for playing with it at some point later in the future, sometimes distant future :) &lt;/p&gt;

&lt;p&gt;My GitHub started looking a little too cluttered with these Repos so I decided to do some cleaning. Yes, you could use the browser to point, click, copy, and paste every single repo you want to transfer out of your main account into another one to keep to interesting Repos safe and maintain your main account looking professional, but I find that very time consuming and just plainly bad use of the time we could instead use for twitting and be on our way to becoming social media influencers. &lt;/p&gt;

&lt;h2&gt;
  
  
  How? Here is what we need to get started
&lt;/h2&gt;

&lt;p&gt;We'll use the GitHub API to automate this task 🤖, Python with a virtual environment for our script and the requests library to talk to the API. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First head out to &lt;a href="https://github.com/settings/tokens"&gt;GitHub&lt;/a&gt; and generate a personal access token from the developer settings page. On this page, click Generate a new token, give your token a name and select the scopes you need. I selected all the repo scopes because I'm planning on extending this utility. Here are the &lt;a href="https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/"&gt;docs&lt;/a&gt; for a more detailed dive into scopes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BalyKnUS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xfgc7lc3ymvi8usygrtz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BalyKnUS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xfgc7lc3ymvi8usygrtz.png" alt="scopes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the token and test quickly test it out with curl.&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="nv"&gt;$ GITHUB_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"access_token"&lt;/span&gt;
~ &lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Authorization: token &lt;/span&gt;&lt;span class="nv"&gt;$GITHUB_TOKEN&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; https://api.github.com/gists
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it worked you should receive a similar repose with a list of all your public Gists.&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="o"&gt;[&lt;/span&gt;
 &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"url"&lt;/span&gt;: &lt;span class="s2"&gt;"https://api.github.com/gists/4d5ab8adff9fc8b4cdf7d8e9dfa442c7"&lt;/span&gt;,
    &lt;span class="s2"&gt;"forks_url"&lt;/span&gt;: &lt;span class="s2"&gt;"https://api.github.com/gists/4d5ab8adff9fc8b4cdf7d8e9dfa442c7/forks"&lt;/span&gt;,
    &lt;span class="s2"&gt;"commits_url"&lt;/span&gt;: &lt;span class="s2"&gt;"https://api.github.com/gists/4d5ab8adff9fc8b4cdf7d8e9dfa442c7/commits"&lt;/span&gt;,
    &lt;span class="s2"&gt;"id"&lt;/span&gt;: &lt;span class="s2"&gt;"4d5ab8adff9fc8b4cdf7d8e9dfa442c7"&lt;/span&gt;,
    &lt;span class="s2"&gt;"node_id"&lt;/span&gt;: &lt;span class="s2"&gt;"MDQ6R2lzdDRkNWFiOGFkZmY5ZmM4YjRjZGY3ZDhlOWRmYTQ0MmM3"&lt;/span&gt;,
    &lt;span class="s2"&gt;"git_pull_url"&lt;/span&gt;: &lt;span class="s2"&gt;"https://gist.github.com/4d5ab8adff9fc8b4cdf7d8e9dfa442c7.git"&lt;/span&gt;,
    &lt;span class="s2"&gt;"git_push_url"&lt;/span&gt;: &lt;span class="s2"&gt;"https://gist.github.com/4d5ab8adff9fc8b4cdf7d8e9dfa442c7.git"&lt;/span&gt;,
    &lt;span class="s2"&gt;"html_url"&lt;/span&gt;: &lt;span class="s2"&gt;"https://gist.github.com/4d5ab8adff9fc8b4cdf7d8e9dfa442c7"&lt;/span&gt;,
    &lt;span class="s2"&gt;"files"&lt;/span&gt;: &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"views.py"&lt;/span&gt;: &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"filename"&lt;/span&gt;: &lt;span class="s2"&gt;"views.py"&lt;/span&gt;,
        &lt;span class="s2"&gt;"type"&lt;/span&gt;: &lt;span class="s2"&gt;"application/x-python"&lt;/span&gt;,
        &lt;span class="s2"&gt;"language"&lt;/span&gt;: &lt;span class="s2"&gt;"Python"&lt;/span&gt;,
        &lt;span class="s2"&gt;"raw_url"&lt;/span&gt;: &lt;span class="s2"&gt;"https://gist.githubusercontent.com/jqn/4d5ab8adff9fc8b4cdf7d8e9dfa442c7/raw/7acabeae8db34dcae72fbb1dbb002557a70632ef/views.py"&lt;/span&gt;,
        &lt;span class="s2"&gt;"size"&lt;/span&gt;: 347
      &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;,
...
&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The second thing we need is a Virtual Environment. If you are a beginner or just unsure on how to do this please give this a read &lt;a href="https://medium.com/@jQN/getting-started-with-flask-a53198e11012?source=friends_link&amp;amp;sk=dfce26cf7df6b143b58f5b572bb7e5ba"&gt;Learn How To Get Started With Flask&lt;/a&gt; It's geared towards getting you started with Flask but it goes over how to configure a local Python development environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I use &lt;a href="https://virtualenvwrapper.readthedocs.io/en/latest/"&gt;virtualenvwrapper&lt;/a&gt;&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="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; ~/www/automation
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/www/automation
&lt;span class="nv"&gt;$ &lt;/span&gt;mkvirtualenv automation_hacks
&lt;span class="o"&gt;(&lt;/span&gt;automation&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$ &lt;/span&gt;automation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now with a Virtual Environment ready let's get the coding started.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new Python script and install the required packages. Inside the automation directory run the following commands.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;github_hacks.py
&lt;span class="nv"&gt;$ &lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;requests
&lt;span class="nv"&gt;$ &lt;/span&gt;pip freeze &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the current directory structure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;automation
├── github_hacks.py
└── requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And with &lt;a href="https://code.visualstudio.com/"&gt;VSCode&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ code github_hacks.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://code.visualstudio.com/"&gt;VSCode&lt;/a&gt; is not required for this step so feel free to use your favorite text editor.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;And now "The code"
&lt;/li&gt;
&lt;/ul&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;requests&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;sys&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;pprint&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pprint&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&lt;/span&gt;

&lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"access_token"&lt;/span&gt;
&lt;span class="n"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;repo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;new_owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="n"&gt;query_url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s"&gt;"https://api.github.com/repos/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/transfer"&lt;/span&gt;

&lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'Authorization'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s"&gt;'token &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="s"&gt;'Accept'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'application/vnd.github.v3+json'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;'new_owner'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;new_owner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="n"&gt;pprint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Finally, we can run it like this:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;$ python github_hacks.py owner repo new_owner&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you go back to your GitHub the repo was transferred to the new owner.&lt;/p&gt;

&lt;p&gt;Currently, this script takes a single Repo at the time but it can be expanded to take multiple Repos and transfer them to another owner/organization.&lt;/p&gt;

&lt;p&gt;This works best when transferring to an organization you own. If transferring to a new owner the owner has to accept the transfer first. &lt;/p&gt;

&lt;p&gt;I did tryout &lt;a href="https://github.com/PyGithub/PyGithub"&gt;PyGithub&lt;/a&gt; but currently, it doesn't have the transfer repo feature. There are also other ready to use libraries listed in the Github API &lt;a href="https://docs.github.com/en/rest/overview/libraries"&gt;docs&lt;/a&gt; but most of them are outdated as of the writing of this article.&lt;/p&gt;

&lt;p&gt;Questions? Problems? Don't hesitate to reach out on &lt;a href="https://twitter.com/jQNReactor"&gt;Twitter&lt;/a&gt; or comment below. &lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/"&gt;Github Developer - Scopes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.github.com/rest/reference/repos#transfer-a-repository"&gt;Github Rest API&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://requests.readthedocs.io/en/latest/user/quickstart/"&gt;requests&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.datacamp.com/community/tutorials/f-string-formatting-in-python#SC"&gt;f-string Formatting in Python&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>productivity</category>
      <category>lifehacks</category>
      <category>automation</category>
    </item>
    <item>
      <title>Deploy A Flask App On AWS EC2 </title>
      <dc:creator>Joaquin Guardado</dc:creator>
      <pubDate>Mon, 31 Aug 2020 07:55:03 +0000</pubDate>
      <link>https://dev.to/jqn/deploy-a-flask-app-on-aws-ec2-in-4-steps-2h85</link>
      <guid>https://dev.to/jqn/deploy-a-flask-app-on-aws-ec2-in-4-steps-2h85</guid>
      <description>&lt;p&gt;Flask is a web framework for python, meaning that it provides a simple interface for dynamically generating responses to web requests. Let’s start by launching a Flask server on an Amazon Web Services EC2 instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Starting up an EC2 instance
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Launch an EC2 instance.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to the AWS console &lt;a href="https://aws.amazon.com/console/"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Select EC2 from AWS services.&lt;/li&gt;
&lt;li&gt;Click on Launch Instance.&lt;/li&gt;
&lt;li&gt;Select the &lt;strong&gt;Ubuntu Server 16.04 LTS (HVM), SSD Volume Type — ami-43a15f3e&lt;/strong&gt; instead of the Amazon Linux. The exact versions may change with time.&lt;/li&gt;
&lt;li&gt;Click on Review and Launch.&lt;/li&gt;
&lt;li&gt;Configure the security groups as shown below. This setting allows access to port 80 (HTTP) from anywhere, and ssh access only from any IP address.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rtR_QyN_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/a1aeddcb-c92a-4737-b58d-a92ba9cb40de/" alt="1_dCTaAa6TZLTyah4cbHFS-Q.png"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2. Setting up the instance
&lt;/h2&gt;

&lt;p&gt;Now that we’ve connected to the instance, it’s time to install some of the programs we’ll need.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Connect to the instance using ssh from the Terminal.&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;$ ssh -i "yourapp.pem" ubuntu@yourapppublicinstance.compute-1.amazonaws.com&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Install the apache webserver and mod_wsgi.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt-get update
$ sudo apt-get install apache2
$ sudo apt-get install libapache2-mod-wsgi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you point your browser at your instance’s public DNS name you should see the Apache server’s “It works!” page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4uKSTDaw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/5c126c49-0c71-4268-b003-0e36cd9191eb/" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4uKSTDaw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/5c126c49-0c71-4268-b003-0e36cd9191eb/" alt="0_DHsd8UnFQ_BX5Y9V.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Install Flask using the pip tool (which also needs to be installed).&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt-get install python-pip
$ sudo pip install flask
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Create a directory for our Flask app.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We’ll create a directory in our home directory to work in, and link to it from the site-root defined in apache’s configuration &lt;code&gt;/var/www/html&lt;/code&gt; by default, see &lt;code&gt;/etc/apache2/sites-enabled/000-default.conf&lt;/code&gt; for the current value).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir ~/flaskapp
$ sudo ln -sT ~/flaskapp /var/www/html/flaskapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To verify our operation is working, create a simple index.html file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd ~/flaskapp
$ echo "Hello World" &amp;gt; index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should now see “Hello World” displayed if you navigate to (your instance public DNS)/flaskapp in your browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_7bUmzuj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/7f823fdf-1ee0-4992-b3ec-6a407dba75e3/" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_7bUmzuj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/7f823fdf-1ee0-4992-b3ec-6a407dba75e3/" alt="0_m7sMR_PKOvUzTG1b.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Running a simple Flask app
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Create an app.&lt;/strong&gt;&lt;br&gt;
We’ll use the simple “Hello world” &lt;a href="https://flask.palletsprojects.com/en/1.1.x/quickstart/#quickstart"&gt;example&lt;/a&gt; from the Flask documentation. Put the following content in a file named &lt;code&gt;flaskapp.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
  return 'Hello from Flask!'
if __name__ == '__main__':
  app.run()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Create a .wsgi file to load the app.&lt;/strong&gt;&lt;br&gt;
Put the following content in a file named &lt;code&gt;flaskapp.wsgi&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#flaskapp.wsgi
import sys
sys.path.insert(0, '/var/www/html/flaskapp')

from flaskapp import app as application
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Enable mod_wsgi.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The apache server displays HTML pages by default but to serve dynamic content from a Flask app we’ll have to make a few changes. In the apache configuration file located at /etc/apache2/sites-enabled/000-default.conf, add the following block just after the DocumentRoot /var/www/html line:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---hrk19DM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/9f995eba-0d7a-4777-9b21-a42b9f4a9436/" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---hrk19DM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/9f995eba-0d7a-4777-9b21-a42b9f4a9436/" alt="0_NgmwfmUHKb3g07Ae.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WSGIDaemonProcess flaskapp threads=5
WSGIScriptAlias / /var/www/html/flaskapp/flaskapp.wsgi

&amp;lt;Directory flaskapp&amp;gt;
    WSGIProcessGroup flaskapp
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
&amp;lt;/Directory&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Restart the webserver.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use this command to restart the server with the new configuration&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sudo service apache2 restart&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Test configuration.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you navigate your browser to your EC2 instance’s public DNS again, you should see the text returned by the hello_world function of our app, “Hello from Flask!”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hk3hhIVX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/3eed92d9-d87c-45ed-9757-2a0191594896/" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hk3hhIVX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ucarecdn.com/3eed92d9-d87c-45ed-9757-2a0191594896/" alt="0_aHAl4M15XURcGNHS.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our server is now running and ready to crunch some data (if something isn’t working, try checking the log file in &lt;code&gt;/var/log/apache2/error.log&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Have Flask app do work.
&lt;/h2&gt;

&lt;p&gt;Now that we have a server ready to do work we’ll set up a simple service to provide letter counts from an input string.&lt;br&gt;
&lt;strong&gt;1. Collect information from the url.&lt;/strong&gt;&lt;br&gt;
Flask allows us to route requests to functions based on the url requested. We can also get input from the url to pass into the function. Add the following to flaskapp.py:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# flaskapp.py
@app.route('/countme/&amp;lt;input_str&amp;gt;')
def count_me(input_str):
    return input_str
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This count_me() function will return anything after the countme/ portion of the url. Restart the webserver to see it in action:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sudo service apache2 restart&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Process information&lt;/strong&gt;&lt;br&gt;
Let’s make our &lt;code&gt;count_me()&lt;/code&gt; function a little more interesting. Modify &lt;code&gt;flaskapp.py&lt;/code&gt; like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# flaskapp.py
from collections import Counter
...
@app.route('/countme/&amp;lt;input_str&amp;gt;')
def count_me(input_str):
    input_counter = Counter(input_str)
    response = []
    for letter, count in input_counter.most_common():
        response.append('"{}": {}'.format(letter, count))
    return '&amp;lt;br&amp;gt;'.join(response)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart the server and view the results:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sudo service apache2 restart&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note that it is bad practice to format HTML responses inside these functions, templates should generally be used instead.&lt;br&gt;
The entire &lt;code&gt;count_me()&lt;/code&gt; function could be written in one logical line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return '&amp;lt;br&amp;gt;'.join('"{}": {}'.format(let, cnt)
                   for let, cnt in Counter(in_str).most_common())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the application throws any errors the error log can help you debug.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sudo tail -f /var/log/apache2/error.log&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you enjoyed this tutorial, please give me some likes. Happy coding!&lt;/p&gt;

</description>
      <category>python</category>
      <category>flask</category>
      <category>aws</category>
      <category>ubuntu</category>
    </item>
  </channel>
</rss>
