<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by the niqabi coder mum on Medium]]></title>
        <description><![CDATA[Stories by the niqabi coder mum on Medium]]></description>
        <link>https://medium.com/@niqabicodermum?source=rss-45a65bf23d95------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RkcTeCraJcrEQPKOhRzWCw.jpeg</url>
            <title>Stories by the niqabi coder mum on Medium</title>
            <link>https://medium.com/@niqabicodermum?source=rss-45a65bf23d95------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 01:25:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@niqabicodermum/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[⚡️ Making a Static Site Generator with Python — part 2]]></title>
            <link>https://medium.com/@niqabicodermum/%EF%B8%8F-making-a-static-site-generator-with-python-part-2-4aeb23002842?source=rss-45a65bf23d95------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aeb23002842</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[static-site]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[the niqabi coder mum]]></dc:creator>
            <pubDate>Sat, 04 May 2019 07:38:02 GMT</pubDate>
            <atom:updated>2019-05-04T07:38:02.614Z</atom:updated>
            <content:encoded><![CDATA[<h3>⚡️ Making a Static Site Generator with Python — part 2</h3><p>In the <a href="https://blog.naveeraashraf.com/posts/make-static-site-generator-with-python/">first part</a> of this tutorial we explored the two main components behind making a static site generator or SSG — the Markdown parser, Markdown2, and the templating engine, Jinja2. We saw how to use these components together to create HTML files from Markdown files and pre-created templates.</p><p>In this part we will create our own static site generator. This is the final product</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*KZkViTFSJSyxRTlT.png" /></figure><p>So let’s get started.</p><h3>Structure</h3><p>In this tutorial I will create a recipe blog. Since this tutorial is for educational purpose, I will only create two main views: the home page of the recipe blog with all the posts listed on it, and the individual posts pages. You can find the complete code in the <a href="https://github.com/nqcm/static-site-generator">github repository</a></p><h3>Scaffolding</h3><p>Create a new folder where you want your code to live:</p><pre>mkdir recipe-ssg</pre><p>In this folder, create the content folder where we will write our blog posts in markdown files:</p><pre>cd recipe-ssg &amp; mkdir content</pre><p>We will also need posts written in markdown. If you want to follow along, you can copy the recipes written in markdown from <a href="https://github.com/nqcm/static-site-generator/tree/master/content">here</a>. By the way these are not just place holder recipes. These are my <a href="https://www.instagram.com/niqabi.coder.mum/">tried and tested</a> recipes. If you are a baker, do give these recipes a try!</p><p>We will also need some images. Feel free to use my images from <a href="https://github.com/nqcm/static-site-generator/tree/master/output/img">here</a>. Make a folder in your root project called output. Inside the output folder make another folder called img and add all the image files to this folder.</p><p>You will also need to install <a href="https://github.com/trentm/python-markdown2">Markdown2</a> and <a href="http://jinja.pocoo.org/docs/2.10">Jinja2</a>, using pip or pipenv, ideally inside a <a href="https://docs.python-guide.org/dev/virtualenvs/">virtual environment</a>.</p><pre>pipenv install markdown2<br>pipenv install jinja2</pre><h3>Writing the Python Script</h3><p>Create a new file in your project root and call it main.py. First we will import all the packages we will need:</p><pre>import os<br>from datetime import datetime<br>from jinja2 import Environment, PackageLoader<br>from markdown2 import markdown</pre><p>Next we will parse our markdown files. This is how we did it in the <a href="https://blog.naveeraashraf.com/posts/make-static-site-generator-with-python/">first part</a>:</p><pre>from markdown2 import markdown</pre><pre>with open(&#39;content/turkish-pide.md&#39;, &#39;r&#39;) as file:<br>    parsed_md = markdown(file.read(), extras=[&#39;metadata&#39;])</pre><p>But since we have more than one file now, we will change the code to loop over all the files in the content folder like so:</p><pre>POSTS = {}<br>for markdown_post in os.listdir(&#39;content&#39;):<br>    file_path = os.path.join(&#39;content&#39;, markdown_post)</pre><pre>    with open(file_path, &#39;r&#39;) as file:<br>        POSTS[markdown_post] = markdown(file.read(), extras=[&#39;metadata&#39;])</pre><p>Next we will sort these posts in reverse order so the newest posts show first but the dates are in a string format. So we will first need to convert them to datetime:</p><pre>POSTS = {<br>    post: POSTS[post] for post in sorted(POSTS, key=lambda post: datetime.strptime(POSTS[post].metadata[&#39;date&#39;], &#39;%Y-%m-%d&#39;), reverse=True)<br>}</pre><p>So far so good. You can check if your script is working so far by printing some metadata to the console.</p><h3>Creating Templates</h3><p>Next we will write our templates. Create a templates directory in the project root. We will write two templates, one for the main home page and the other for individual posts. Let&#39;s write the individual posts one first:</p><pre>&lt;!DOCTYPE html&gt;</pre><pre>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;<br>    &lt;title&gt;{{ post.title }}&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h1&gt;{{ post.title }}&lt;/h1&gt;<br>    &lt;small&gt;{{ post.date }}&lt;/small&gt;<br>    &lt;p&gt;<br>        {{ post.content }}<br>    &lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Save the above code into post.html inside the templates directory. Create another file home.html inside templates directory and paste the following code:</p><pre>&lt;!DOCTYPE html&gt;</pre><pre>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;<br>    &lt;title&gt;My Recipes&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><pre>    &lt;h1&gt;My Recipes&lt;/h1&gt;<br>    {% for post in posts %}<br>    &lt;p&gt;<br>        &lt;h2&gt;{{loop.index}}: &lt;a href=&quot;posts/{{ post.slug }}/&quot;&gt;{{post.title}}&lt;/a&gt; &lt;small&gt;{{post.date}}&lt;/small&gt;&lt;/h2&gt;<br>        {{post.summary}}<br>    &lt;/p&gt;<br>    {% endfor %}<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>This template is a little less straight forward than the individual post one. But we are simply using Jinja2’s for loop to loop through all the posts and filling in the place holder with data from those posts. The data will be handed over to this template in a list so we can easily loop over it. When we will go to our main.py again and write the script to pass data along to these templates, this will make much more sense.</p><h3>Using Template Inheritance</h3><p>But before we do that, you may have noticed that there is quite a bit of repetition. We had to write the same scaffolding HTML code for both templates. While this is not a big deal in this case because we have just two templates, but imagine having to rewrite the same code for larger projects.</p><p>For sites with navigation menus and footers a lot of code will need to be written over and over again. And if you had to make a change, let’s say in your navigation menu, you will need to make the change on each and every template.</p><p>This can get incredibly monotonous, not to mention increasing the chance of errors and bugs.</p><p>Fortunately all templating languages offer the solution to this problem through template inheritance. You can read more about Jinja2’s template inheritance from <a href="https://realpython.com/primer-on-jinja-templating/">here</a>.</p><blockquote><em>Templates usually take advantage of inheritance, which includes a single base template that defines the basic structure of all subsequent child templates. You use the tags </em><em>{% extends %} and </em><em>{% block %} to implement inheritance. ~ </em><a href="https://realpython.com/primer-on-jinja-templating/"><em>Real Python</em></a></blockquote><p>Create a new file in templates directory and call it layout.html. In this file we will put all the code that needs to be repeated on every template:</p><pre>&lt;!DOCTYPE html&gt;</pre><pre>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;<br>    &lt;title&gt;My Recipes&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body class=&quot;container&quot;&gt;</pre><pre>    {% block content %} {% endblock %}</pre><pre>    &lt;br&gt;</pre><pre>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Now let’s make suitable changes to the other two templates as well. In the home.html template paste the following code:</p><pre>{% extends &quot;layout.html&quot; %}</pre><pre>{% block content %}</pre><pre>&lt;h1&gt;My Recipes&lt;/h1&gt;</pre><pre>&lt;div&gt;</pre><pre>{% for post in posts %}</pre><pre>    &lt;p&gt;<br>        &lt;h2&gt;{{loop.index}}: &lt;a href=&quot;posts/{{ post.slug }}.html&quot;&gt;{{post.title}}&lt;/a&gt; &lt;small&gt;{{post.date}}&lt;/small&gt;&lt;/h2&gt;<br>        {{post.summary}}<br>    &lt;/p&gt;</pre><pre>{% endfor %}</pre><pre>&lt;/div&gt;</pre><pre>{% endblock %}</pre><p>And in the post.html change the code to:</p><pre>{% extends &quot;layout.html&quot; %}</pre><pre>{% block content %}</pre><pre>&lt;h1&gt;{{post.title}}&lt;/h1&gt;<br>&lt;p&gt;<br>    &lt;small&gt;{{post.date}}&lt;/small&gt;<br>    {{post.content}}<br>&lt;/p&gt;</pre><pre>{% endblock %}</pre><p>Now we have much cleaner code. Now let’s work on rendering these templates.</p><h3>Rendering Home Page</h3><p>In your main.py file, get the templates with Jinja2 just like we did in the <a href="https://blog.naveeraashraf.com/posts/make-static-site-generator-with-python/">first part</a>. But this time we will get two templates:</p><pre>env = Environment(loader=PackageLoader(&#39;main&#39;, &#39;templates&#39;))<br>home_template = env.get_template(&#39;home.html&#39;)<br>post_template = env.get_template(&#39;post.html&#39;)</pre><p>Now let’s pass the data to our home page template from our POSTS list. Since the home page only needs the metadata we will pass it metadata only:</p><pre>posts_metadata = [POSTS[post].metadata for post in POSTS]<br>home_html = home_template.render(posts=posts_metadata)</pre><p>This will pass a list of metadata through the variable posts to our home page template. This is the same posts variable over which we looped in the template.</p><p>One more thing that I want to do is to have the tags of each post in some kind of list so I can loop through them as I may want to make each tag into a clickable link. Currently all the tags are being passed as a single string.</p><p>To change that I will create a new list from the post_metadata[&#39;tags&#39;]variable and pass it along with other data to my home template.</p><pre>posts_metadata = [POSTS[post].metadata for post in POSTS]<br>tags = [post[&#39;tags&#39;] for post in posts_metadata]<br>home_html = home_template.render(posts=posts_metadata, tags=tags)</pre><p>Now let’s write this HTML to a file:</p><pre>with open(&#39;output/home.html&#39;, &#39;w&#39;) as file:<br>    file.write(home_html)</pre><p>Run your main.py and you will get a home.html in your output directory. Open the file in browser and it will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*Qo7ZmcUv5n95YPGT.png" /></figure><h3>Rendering Individual Posts</h3><p>If you click on the title of any of the post in your browser, there will be a not found error. Because the individual post pages haven’t been rendered yet. To do so add the following code to your main.py:</p><pre>for post in POSTS:<br>    post_metadata = POSTS[post].metadata</pre><pre>    post_data = {<br>        &#39;content&#39;: POSTS[post],<br>        &#39;title&#39;: post_metadata[&#39;title&#39;],<br>        &#39;date&#39;: post_metadata[&#39;date&#39;],<br>    }</pre><pre>    post_html = post_template.render(post=post_data)</pre><pre>    post_file_path = &#39;output/posts/{slug}.html&#39;.format(slug=post_metadata[&#39;slug&#39;])</pre><pre>    os.makedirs(os.path.dirname(post_file_path), exist_ok=True)<br>    with open(post_file_path, &#39;w&#39;) as file:<br>        file.write(post_html)</pre><p>Now run the main.py again and now when you click on a link it will take you to the corresponding page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*VE5OerrSprjmpb6c.png" /></figure><h3>Extra Bits</h3><p>Our static site generator is done at this point. But I want to show you a few extra things.</p><p>Let’s say we want to add some css to make our site look nicer. This is where we will be thankful to the template inheritance. Just add the following styling to your layout.html in the templates directory:</p><pre>&lt;style&gt;<br>    .container {<br>        width: 80%;<br>        margin: auto;<br>        margin-top: 3em;<br>    }<br>&lt;/style&gt;</pre><p>Run your main.py again and you will see the styles applied to all pages. Great!</p><p>Let’s add a light-weight css framework to our site. I am using <a href="https://picnicss.com/documentation">Picnic</a>.</p><p>Add this link to the head of your layout.html:</p><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/picnic@6.5.0/picnic.min.css&quot;&gt;</pre><p>Re run main.py and voila!</p><p>Remember those tags we passed as an individual list? Using Jinja2’s build in filters we can now iterate over that list from within our template and put each tag inside it’s own span or button element.</p><pre>{% set list_of_tags = post.tags.split(&quot;,&quot;) %}<br>{% for tag in list_of_tags %}<br>    &lt;button class=&quot;shyButton mybutton&quot;&gt;{{ tag }}&lt;/button&gt;<br>{% endfor %}</pre><p>And after adding some CSS classes to my code here is the final product</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*o3R11GZRlCHfRcIy.png" /></figure><p>and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*u0IYG495vxJhbkaa.png" /></figure><p>You can find the complete code in the <a href="https://github.com/nqcm/static-site-generator">github repository</a>.</p><p>That’s it! I hope you enjoyed this tutorial. If you did don’t forget to share it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aeb23002842" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[⚡️ Making a Static Site Generator with Python — part 1]]></title>
            <link>https://medium.com/@niqabicodermum/%EF%B8%8F-making-a-static-site-generator-with-python-part-1-589009a83797?source=rss-45a65bf23d95------2</link>
            <guid isPermaLink="false">https://medium.com/p/589009a83797</guid>
            <category><![CDATA[static-site-generator]]></category>
            <category><![CDATA[static-site]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[the niqabi coder mum]]></dc:creator>
            <pubDate>Fri, 03 May 2019 08:53:29 GMT</pubDate>
            <atom:updated>2019-05-03T08:53:29.110Z</atom:updated>
            <content:encoded><![CDATA[<h3>⚡️ Making a Static Site Generator with Python — part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*yYZGERIBIzQ3BDpksEy9ow.jpeg" /></figure><p>Static site generators are a secure and fast alternative to traditional content management systems like Wordpress.</p><p>Static Site Generators or SSG are pretty simple to use once you get the hang of them. But initially there may be a learning curve. One way of learning (my preferred way) is to look under the hood and see how things work and try to recreate them. With this end goal in mind we will create our own static site generator using Python. Plus it is a lot of fun to make.</p><p>If you are new to static site generators, you can first read about <a href="https://davidwalsh.name/introduction-static-site-generators">what is a static site generator</a>, <a href="https://learn.cloudcannon.com/jekyll/why-use-a-static-site-generator/">when to use one</a>, and <a href="https://www.sitepoint.com/7-reasons-not-use-static-site-generator/">when not to use one</a>. Also have a look at <a href="https://github.com/myles/awesome-static-generators">a list of many static site generators</a> written in different programming languages.</p><p>So without further ado, let’s start.</p><h3>Understanding how static site generators work</h3><p>The concept behind statistic site generators is pretty simple. You write your posts in markdown and the script in the static site generators turn your markdown into HTML using pre-created templates. These static HTML files can be uploaded to any web server and served to your readers.</p><p>Let’s say you are making a recipe blog. You write your recipe in markdown like this:</p><pre>title: Turkish Pide<br>date: 17-04-19</pre><pre><strong>**Ingredients for the dough:**</strong>**<br>500 gm bread flour<br>1 tblspoon yeast<br>1 tblspoon honey<br>1 tsp salt<br>2 tblsp olive oil<br>250 ml or as req water.</pre><pre><strong>**Ingredients for the filling:**</strong>**<br>1 cup grated Mozerella<br>½ cup crumbled feta <br> <br>Combine the ingredients of the dough and knead until smooth and elastic. Let rest 45 minutes. Divide in two. Roll each in a rectangle. Spread the cheese filling over top. And roll the sides in to form a boat shape. Let rise for 10-15 minutes. Brush the sides with olive oil and bake at 230C for 10-15 minutes or until nicely browned.</pre><p>And you have a template like this:</p><pre>&lt;html&gt;<br>    &lt;head&gt;<br>        &lt;title&gt;{{ title }}&lt;/title&gt;<br>    &lt;/head&gt;<br>    <br>    &lt;body&gt;<br>        &lt;p&gt;<br>            Published at: {{ date }}<br>            {{ content }}<br>        &lt;/p&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p>The static site generator will parse the markdown text and insert each component where it belongs, so you will end up with something like this:</p><pre>&lt;html&gt;<br>    &lt;head&gt;<br>        &lt;title&gt;Turkish Pide&lt;/title&gt;<br>    &lt;/head&gt;</pre><pre>    &lt;body&gt;<br>        &lt;p&gt;<br>            Published at: 17-04-19<br>            &lt;strong&gt;Ingredients for the dough:&lt;/strong&gt;&lt;br&gt;<br>            &lt;ul&gt;<br>                &lt;li&gt;500 gm bread flour&lt;/li&gt;<br>                &lt;li&gt;1 tblspoon yeast&lt;/li&gt;<br>                &lt;li&gt;1 tblspoon honey&lt;/li&gt;<br>                &lt;li&gt;1 tsp salt&lt;/li&gt;<br>                &lt;li&gt;2 tblsp olive oil&lt;/li&gt;<br>                &lt;li&gt;250 ml or as req water.&lt;/li&gt;<br>            &lt;/ul&gt;</pre><pre>            &lt;strong&gt;Ingredients for the filling:&lt;/strong&gt;<br>            &lt;ul&gt;<br>                &lt;li&gt;1 cup grated Mozerella&lt;/li&gt;<br>                &lt;li&gt;½ cup crumbled feta&lt;/li&gt;<br>            &lt;/ul&gt;<br>        <br>            Combine the ingredients of the dough and knead until smooth and elastic. Let rest 45 minutes. Divide in two. Roll each in a rectangle. Spread the cheese filling over top. And roll the sides in to form a boat shape. Let rise for 10-15 minutes. Brush the sides with olive oil and bake at 230C for 10-15 minutes or until nicely browned.<br>        &lt;/p&gt;        <br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p>So we need to find a way to parse the text from markdown to HTML and to insert HTML into pre-created templates.</p><h3>Converting Markdown to HTML</h3><p>Create a new folder where you want your code to live:</p><pre>mkdir recipe-ssg</pre><p>SSG stands for Static Site Generator by the way. And as good as it is for the SEO of my site, I am pretty tired of typing Static Site Generators over and over so I will refer to Static Site Generators as SSG from now on. Phew!</p><p>In this folder, create the content folder where we will write our blog posts in markdown files:</p><pre>cd recipe-ssg &amp; mkdir content</pre><p>In the content folder create a markdown file. You can copy the contents of <a href="https://raw.githubusercontent.com/nqcm/static-site-generator/master/content/turkish-pide.md">this file</a> and call it turkish-pide.md.</p><p>You will notice that the file is divided into two parts. There is some metadata between the two dash separators. And the actual content is below the separator.</p><p>Next we want a way to parse this markdown, convert it into HTML and store this data so it can be consumed by Python. But we don’t need to reinvent the wheel. Th awesome Python community has already written a <a href="https://github.com/trentm/python-markdown2">Markdown Parser</a> for us. We will install it and play around a bit to see how it works.</p><p>Within your <a href="https://docs.python-guide.org/dev/virtualenvs/">virtual environment </a>install markdown2 using pipenv or pip.</p><pre>pipenv install markdown2</pre><p>In the interactive Python shell try:</p><pre>from markdown2 import markdown<br>markdown(&quot;**This is a very important message**&quot;)</pre><pre><em># outputs &#39;&lt;p&gt;&lt;strong&gt;This is a very important message&lt;/strong&gt;&lt;/p&gt;\n&#39;</em></pre><p>Great! Now we can create a simple script to convert our markdown format files into HTML files.</p><p>Create a main.py file in the root of your project (not inside the content) and type the following:</p><pre>from markdown2 import markdown</pre><pre>with open(&#39;content/turkish-pide.md&#39;, &#39;r&#39;) as file:<br>    parsed_md = markdown(file.read(), extras=[&#39;metadata&#39;])<br></pre><pre>print(&#39;Metadata: &#39;, parsed_md.metadata)<br>print(&#39;Content: &#39;, parsed_md)</pre><p>Run main.py and you will see the contents of the turkish-pide.md file printed on the console with HTML tags. Also notice that the metadata is converted into a Python dictionary. We can now use these variables to create pages using templates.</p><p>But first we need to create a template.</p><h3>Creating and Using Templates</h3><p>Templates are ordinary HTML files with placeholders for the variable data. We will use <a href="http://jinja.pocoo.org/docs/2.10">Jinja2</a> templating language for Python which will simply insert the data from our variables in the HTML template. If you are new to templating languages or Jinja2, you can first read more about it <a href="https://realpython.com/primer-on-jinja-templating/">here</a>.</p><p>Install Jinja2 within your virtual environment using pipenv or pip:</p><pre>pipenv install jinja2</pre><p>To try Jinja2, create a folder inside your project root and call it templates. Now create a test.html inside templates and put the following code in it:</p><pre>&lt;!DOCTYPE html&gt;</pre><pre>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;<br>    &lt;title&gt;{{ post.title }}&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    <br>    &lt;h1&gt;{{ post.title }}&lt;/h1&gt;<br>    &lt;small&gt;{{ post.date }}&lt;/small&gt;<br>    &lt;p&gt;<br>        {{ post.content }}<br>    &lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Great! Now we have a template and we just have to extract our variables from the parsed markdown and hand them over to Jinja2.</p><p>In your main.py add the following code:</p><pre>from jinja2 import Environment, PackageLoader</pre><pre>env = Environment(loader=PackageLoader(&#39;main&#39;, &#39;templates&#39;))<br>test_template = env.get_template(&#39;test.html&#39;)</pre><pre>data = {<br>    &#39;content&#39;: parsed_md,<br>    &#39;title&#39;: parsed_md.metadata[&#39;title&#39;],<br>    &#39;date&#39;: parsed_md.metadata[&#39;date&#39;]<br>}</pre><pre>print(test_template.render(post=data))</pre><p>After importing the Jinja2, we create an environment to show Jinja2 where the templates folder is located. Make sure that the first argument for PackageLoader is the name of your python file, in my case it is main. Next we get the template we need and after extracting data from our parsed file we hand it over to Jinja2 while calling the render() function.</p><p>Your final code should look like this now:</p><pre>from markdown2 import markdown<br>from jinja2 import Environment, PackageLoader</pre><pre>with open(&#39;content/turkish-pide.md&#39;, &#39;r&#39;) as file:<br>    parsed_md = markdown(file.read(), extras=[&#39;metadata&#39;])</pre><pre>    env = Environment(loader=PackageLoader(&#39;main&#39;, &#39;templates&#39;))<br>    test_template = env.get_template(&#39;test.html&#39;)</pre><pre>    data = {<br>    &#39;content&#39;: parsed_md,<br>    &#39;title&#39;: parsed_md.metadata[&#39;title&#39;],<br>    &#39;date&#39;: parsed_md.metadata[&#39;date&#39;]<br>    }</pre><pre>    print(test_template.render(post=data))</pre><p>If you run your main.py now you should get all the code from your test.html file with the contents from your turkish-pide.md file inserted in suitable places.</p><p>Now that we know how to render HTML pages using Jinja2, in the <a href="https://blog.naveeraashraf.com/posts/make-static-site-generator-with-python-2/">next part</a> we will put all the pieces together and make our SSG.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=589009a83797" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Learn Django Part 2]]></title>
            <link>https://medium.com/@niqabicodermum/learn-django-part-2-19bdf24aaf3e?source=rss-45a65bf23d95------2</link>
            <guid isPermaLink="false">https://medium.com/p/19bdf24aaf3e</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[the niqabi coder mum]]></dc:creator>
            <pubDate>Sat, 24 Nov 2018 10:46:45 GMT</pubDate>
            <atom:updated>2018-11-24T10:46:45.982Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t8jUW9-HXedgSfsB.png" /></figure><p>I have <a href="https://blog.naveeraashraf.com/posts/learn-django/">previously written about resources to learn Django</a>. The web is an awesome place to learn anything new and I today I am sharing a few more resources to help you learn Django. So here goes!</p><h3>Free Resources</h3><h4>1. <a href="https://simpleisbetterthancomplex.com/series/2017/09/04/a-complete-beginners-guide-to-django-part-1.html">A Complete Beginner’s Guide to Django</a></h4><p>It is a series of well explained tutorials written by Vitor Freitas of <a href="https://simpleisbetterthancomplex.com/">Simple is better than complex</a>. As the name suggests it is targeted towards complete beginners.</p><h4>2. <a href="https://tutorial.djangogirls.org/en/">Django Girls Tutorial</a></h4><p>This is another beginner friendly resource. This tutorial is written not only for beginners to Django but beginners to we development in general. An excellent resources if you are still learning about how the web works.</p><h4>3. <a href="https://www.youtube.com/watch?v=qgGIqRFvFFk&amp;list=PL6gx4Cwl9DGBlmzzFcLgDhKTTfNLfX1IK">Django Tutorial for Beginners by Thenewboston</a></h4><p>A Youtube playlist by the wonderful channel The New Boston.</p><h4>4. <a href="https://www.youtube.com/watch?v=FNQxxpM1yOs&amp;list=PLQVvvaa0QuDeA05ZouE4OzDYLHY-XH-Nd">Django Web Development</a></h4><p>It is also a Youtube playlist where <a href="https://www.youtube.com/channel/UCfzlCWGWYyIQ0aLC5w48gBQ">Sentdex</a> take you through building a complete webapp from bottom up using Django and deploying it.</p><h4>5. <a href="https://books.agiliq.com/projects/django-orm-cookbook/en/latest/">Django ORM Cookbook</a></h4><p>Django ORM Cookbook is a book about doing things with Django ORM and Django models. Django is a “MTV” (Model-Template-View) framework — This book provides a deep dive into the M part. It has about 50 questions of the form ‘How to do X with Django ORM/Queryset/Models’</p><h3>Paid Resources</h3><h4>1. <a href="http://www.tangowithdjango.com/">Tango With Django</a></h4><p>The book provides a hands-on guide to designing and building web applications, explaining how all the technology fits together as you build a web app and then deploying the application on <a href="http://www.pythonanywhere.com/">PythonAnywhere</a>.</p><h4>2. <a href="https://www.twoscoopspress.com/collections/everything/products/two-scoops-of-django-1-11">Two Scoops of Django</a></h4><p>This book introduces you to various tips, tricks, patterns, code snippets and techniques for Django best practices.</p><p><em>I am Naveera Ashraf, an autodidact and polymath. I make chatbots for people at </em><a href="https://creativemelon.co.za/"><em>Creative Melon</em></a><em>. You can read about my other projects </em><a href="https://naveeraashraf.com/"><em>here</em></a><em> or follow me on </em><a href="https://twitter.com/niqabicodermum"><em>Twitter</em></a><em>. This post was originally posted on my blog </em><a href="https://blog.naveeraashraf.com/"><em>https://blog.naveeraashraf.com</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19bdf24aaf3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Building A Twitter Bot]]></title>
            <link>https://blog.chatbotslife.com/building-a-twitter-bot-8e57e19c8814?source=rss-45a65bf23d95------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e57e19c8814</guid>
            <category><![CDATA[twitter]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[chatbots]]></category>
            <dc:creator><![CDATA[the niqabi coder mum]]></dc:creator>
            <pubDate>Sat, 24 Nov 2018 10:40:36 GMT</pubDate>
            <atom:updated>2019-06-10T12:57:47.555Z</atom:updated>
            <content:encoded><![CDATA[<p>I built a Twitter <a href="https://chatbotslife.com/">bot</a> that tweets <a href="https://en.wikipedia.org/wiki/Tajwid">Tajweed</a> rules every eight hours using Python and AWS Lambda.</p><h3>TajweedBot on Twitter</h3><p>The best of you is he who learns the Quran and teaches it. ~ Prophet Muhammad SAW Today&#39;s #tajweed rule...</p><p>I have <a href="https://blog.naveeraashraf.com/posts/making-tajweed-bot/">previously written</a> about the writing and designing part of the project and in this part outlines the technical details on how the bot was made and works.</p><figure><a href="https://www.eventbrite.com/e/chatbot-conference-tickets-62945583936?aff=cbl"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0in_nxNUTYgyPIAOZXMKXg.png" /></a></figure><p>You can check out the completed code <a href="https://github.com/nqcm/tajweedbot">here</a></p><h3>Using S3</h3><p>I decided on using an Amazon S3 bucket to store the image cards as it has a nice free tier. Since I was planning on hosting the <a href="https://chatbotslife.com/">bot</a> on AWS Lambda, the integration between different AWS services is seamless.</p><p>S3 has a nice web based uploader to upload stuff but if you have huge amount of files to transfer, using their CLI would be the way to go. For my purpose however, I just used the website’s uploader.</p><h3>Top 4 Bot Tutorials</h3><blockquote><a href="https://chatbotslife.com/build-simple-chatbot-with-rasa-part-1-f4c6d5bb1aea">1. Build simple ChatBot in Python with RASA — Part 1</a></blockquote><blockquote><a href="https://chatbotslife.com/build-simple-chatbot-with-rasa-part-2-16726357b72c">2. Build a simple ChatBot in Python with RASA — Part 2</a></blockquote><blockquote><a href="https://chatbotslife.com/how-i-developed-my-own-learning-chatbot-in-python-from-scratch-and-deployed-it-on-facebook-88bc828be0a8">3. How I developed my own ‘learning’ chatbot in Python</a></blockquote><blockquote><a href="https://chatbotslife.com/chatbot-conference-a53999cf5adb?postPublishedType=initial&amp;fbclid=IwAR3LwmT_MxdqCYWj4tJ_6JbXvOTsjShpQRZ-Ci8Y0buN2htOaHUUMIhDDt0">4. Chatbot Conference in San Francisco</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/0*bVVuw-k2vAclOjRW.jpg" /></figure><h3>Testing Boto3</h3><p>My first step was to test the usage of Amazon’s SDK for Python, the <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/index.html">Boto3 library</a>. Strange name, I know. But it is <a href="https://github.com/boto/boto3/issues/1023">named after a dolphin</a> ‘Boto’ which navigates the Amazon rainforest’s eco system. Cool!</p><p>So after installing Boto3 in my virtual environment, I wrote a simple script to test if I could download a file using Boto3. Turned out I could!</p><pre>import boto3<br>import botocore</pre><pre>BUCKET_NAME = &#39;tajweedbot&#39;<br>KEY = &#39;round-zero.jpg&#39;</pre><pre>s3 = boto3.resource(&#39;s3&#39;)</pre><pre>try:<br>    s3.Bucket(BUCKET_NAME).download_file(KEY, &#39;local.jpg&#39;)<br>except botocore.exceptions.ClientError as e:<br>    if e.response[&#39;Error&#39;][&#39;Code&#39;] == &quot;404&quot;:<br>        print(&quot;The object does not exist.&quot;)<br>    else:<br>        raise</pre><h3>Choosing A Random Image</h3><p>My next step was to grab a random image from the bucket with every execution. Using the bucket.objects.all() method I could count all the objects in that bucket and feeding it to random.randint() function, I was able to get a random number between 1 and the total number of files in that bucket. Adding it with the ‘.png’ extension, I assigned it to the KEY variable replacing the hard-coded KEY.</p><pre>obj = str(random.randint(1, sum(1 for _ in bucket.objects.all())))<br>KEY = obj + &#39;.png&#39;</pre><p>But this is not an elegant solution. For one, my file names had to be numbers like ‘1.png’ etc. Secondly there must be a dedicated bucket for the images being used by this <a href="https://chatbotslife.com/">bot</a>.</p><p>An ideal solution would be to make a JSON file containing the names of the images and then I could get a random file name from the JSON document with a simple script like:</p><pre>s3 = boto3.resource(&#39;s3&#39;)<br>bucket= s3.Bucket(BUCKET_NAME)<br>obj = s3.Object(BUCKET_NAME, &quot;meta.json&quot;)<br>data = obj.get()<br>js = json.loads(data[&#39;Body&#39;].read().decode(&#39;utf-8&#39;))<br>pic = str(random.randint(1, len(js))) + &#39;.png&#39;</pre><p>So in my next iteration over the project, I may implement this method. But for now I am sticking with my not-so-elegant solution.</p><h3>Tweeting the Image</h3><p>Next step was to make my <a href="https://chatbotslife.com/">bot</a> tweet this downloaded image. That was easy using <a href="https://twython.readthedocs.io/en/latest/">Twython</a>. First I created a new Twitter account, then registered an application at <a href="https://apps.twitter.com/">https://apps.twitter.com</a>, and grabed my application’s Consumer Key and Consumer Secret. Sending a tweet can be easily done through the following lines of code.</p><pre>from twython import Twython<br>twitter = Twython(APP_KEY, APP_SECRET,<br>                OAUTH_TOKEN, OAUTH_TOKEN_SECRET)<br>twitter.update_status(status=&#39;See how easy using Twython is!&#39;)</pre><p>You can read more about the dynamic arguments of Twitter API <a href="https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update">here</a>.</p><p>Putting everything together my code looked like this:</p><pre>import boto3<br>import botocore<br>import os<br>import random<br>import tempfile<br>from twython import Twython, TwythonError</pre><pre>BUCKET_NAME = &#39;YOU-BUCKET-NAME&#39;<br>CONSUMER_KEY = &#39;TWITTER-APP-CONSUMER-KEY&#39;<br>CONSUMER_SECRET = &#39;TWITTER-APP-CONSUMER-SECRET&#39;<br>ACCESS_TOKEN = &#39;ACCESS-TOKEN&#39;<br>ACCESS_SECRET = &#39;ACCESS-SECRET&#39;<br></pre><pre>s3 = boto3.resource(&#39;s3&#39;)<br>bucket= s3.Bucket(BUCKET_NAME)</pre><pre>obj = str(random.randint(1, sum(1 for _ in bucket.objects.all())))<br>KEY = obj + &#39;.png&#39;</pre><pre>twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_SECRET)<br></pre><pre>tmp_dir = tempfile.gettempdir()<br>path = os.path.join(tmp_dir, KEY)<br>print(&quot;created directory at &quot; + path)<br>try:<br>    s3.Bucket(BUCKET_NAME).download_file(KEY, path)<br>    print(&#39;file moved to temp directory&#39;)<br>    with open(path, &#39;rb&#39;) as img:<br>        try:<br>            twit_resp = twitter.upload_media(media=img)<br>            twitter.update_status(status=&quot;The best of you is he who learns the Quran and teaches it. ~ Prophet Muhammad SAW&quot; , media_ids=twit_resp[&#39;media_id&#39;])<br>            print(&quot;image tweeted&quot;)<br>        except TwythonError as e:<br>            print(e)<br>except botocore.exceptions.ClientError as e:<br>    if e.response[&#39;Error&#39;][&#39;Code&#39;] == &quot;404&quot;:<br>        print(&quot;The object does not exist.&quot;)<br>    else:<br>        raise</pre><p>So at this point I had a working script that downloaded a random image from S3, and tweeted it with a status. Now to make this script into a bot, I needed some automation. Enter AWS Lambda!</p><h3>AWS Lambda</h3><p>Don’t confuse <a href="https://aws.amazon.com/lambda/?p=tile">AWS Lambda</a> with Python Lambda functions. If you have never heard about <a href="https://aws.amazon.com/lambda/?p=tile">AWS Lambda</a> before, this service allows you to upload some code in a zip format to Amazon servers, set some triggers which will execute this code and then forget about it until the end of month when Amazon bills you for the service. 😉 You don’t even need to know anything about the machine that runs them. No servers to maintain and comparatively cheaper.</p><p>This is what <a href="https://docs.aws.amazon.com/lambda/latest/dg/python-programming-model-handler-types.html">Lambdas look like in Python</a>:</p><pre>def handler_name(event, context): <br>    ...<br>    return some_value</pre><p>The event is what you decide to trigger the Lambda function. And the context sets up all the runtime information needed to interact with AWS and run the function. So now all I had to do was to put my script within the above function. Like so:</p><pre>import boto3<br>import botocore<br>import os<br>import random<br>import tempfile<br>from twython import Twython, TwythonError</pre><pre>BUCKET_NAME = &#39;YOU-BUCKET-NAME&#39;<br>CONSUMER_KEY = &#39;TWITTER-APP-CONSUMER-KEY&#39;<br>CONSUMER_SECRET = &#39;TWITTER-APP-CONSUMER-SECRET&#39;<br>ACCESS_TOKEN = &#39;ACCESS-TOKEN&#39;<br>ACCESS_SECRET = &#39;ACCESS-SECRET&#39;<br></pre><pre>s3 = boto3.resource(&#39;s3&#39;)<br>bucket= s3.Bucket(BUCKET_NAME)</pre><pre>def lambda_handler(event, context):</pre><pre>    obj = str(random.randint(1, sum(1 for _ in bucket.objects.all())))<br>    KEY = obj + &#39;.png&#39;</pre><pre>    twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_SECRET)<br></pre><pre>    tmp_dir = tempfile.gettempdir()<br>    path = os.path.join(tmp_dir, KEY)<br>    print(&quot;created directory at &quot; + path)<br>    try:<br>        s3.Bucket(BUCKET_NAME).download_file(KEY, path)<br>        print(&#39;file moved to temp directory&#39;)<br>        with open(path, &#39;rb&#39;) as img:<br>            try:<br>                twit_resp = twitter.upload_media(media=img)<br>                twitter.update_status(status=&quot;The best of you is he who learns the Quran and teaches it. ~ Prophet Muhammad SAW&quot; , media_ids=twit_resp[&#39;media_id&#39;])<br>                print(&quot;image tweeted&quot;)<br>            except TwythonError as e:<br>                print(e)<br>    except botocore.exceptions.ClientError as e:<br>        if e.response[&#39;Error&#39;][&#39;Code&#39;] == &quot;404&quot;:<br>            print(&quot;The object does not exist.&quot;)<br>        else:<br>            raise</pre><p>My code was already making use of a temporary directory so I didn’t need to make any changes for Lambda there, since it is <a href="https://stackoverflow.com/questions/35641994/accessing-local-filesystem-in-aws-lambda/35642189">possible to access the local filesystem in Lambda</a>. All I needed now was to <a href="https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html">package my code</a> in a zip format with all the dependencies.</p><p>I created a new Lambda function from my AWS console. It is fairly easy to setup a new Lambda. I will try to capture the procedure with images below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JbbKMxF_rNxyG82d.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_BajGdCpKPP9yPLn.jpg" /></figure><p>On my Lambda function’s page, I didn’t add any triggers. Scrolling down to the ‘function code’ section, I uploaded my zipped code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5ozPc6zr_MDsFwnk.jpg" /></figure><p>I tested my Lambda function from the top of the page. Once my code was executing successfully, I went to the <a href="https://aws.amazon.com/cloudwatch/">AWS Cloudwatch service</a> from within my console. And added a new cron job through the steps from the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kJNhgTFwl9cdjmJi.jpg" /></figure><p>And ta-da! My bot started tweeting.</p><h3>Conclusion</h3><p>So this is how I created a Twitter bot in Python and deployed it using AWS Lambda. Of course there are still many improvements, for example, tweaking the code so no image repeats more than once every few days etc. But for now I am happy with this bot and see this project as a <a href="https://en.wikipedia.org/wiki/Minimum_viable_product">MVP</a>.</p><p>This was a simple project and should take any sane human just a couple of hours to make and deploy. Note: For harassed homeschooling moms, it can take up to two weeks to make and deploy. 😬</p><p><em>I am Naveera Ashraf, an autodidact and polymath. I make chatbots for people at </em><a href="https://creativemelon.co.za/"><em>Creative Melon</em></a><em>. You can read about my other projects </em><a href="https://naveeraashraf.com/"><em>here</em></a><em> or follow me on </em><a href="https://twitter.com/niqabicodermum"><em>Twitter</em></a><em>. This post was originally posted on my blog </em><a href="https://blog.naveeraashraf.com/"><em>https://blog.naveeraashraf.com</em></a></p><h3>Don’t forget to give us your 👏 !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*XCnHxkP5NEdSQZID" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e59ef%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e59ef&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e59ef%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7078d8ad19192c4c53d3bf199468e4ab/href">https://medium.com/media/7078d8ad19192c4c53d3bf199468e4ab/href</a></iframe><figure><a href="https://chatbotslife.com/bot-communities-mastermind-group-d2dae9876709#.53x0py6ou"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*6XUspT9JOSq0w0Fi35HIaA.png" /></a></figure><figure><a href="https://m.me/ChatbotsLife"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*c1LDMH5vbnIz9rmAka8Hwg.png" /></a></figure><figure><a href="https://chatbotslife.com/chatbot-development-hire-top-ai-chatbot-developers-c8b45ef7f207"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*D0Jf3dI6ZThtqcfwDYY7mg.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e57e19c8814" width="1" height="1" alt=""><hr><p><a href="https://blog.chatbotslife.com/building-a-twitter-bot-8e57e19c8814">🤖 Building A Twitter Bot</a> was originally published in <a href="https://blog.chatbotslife.com/">Chatbots Life</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Building a Telegram Bot with AWS API Gateway and AWS Lambda]]></title>
            <link>https://blog.chatbotslife.com/building-a-telegram-bot-with-aws-api-gateway-and-aws-lambda-21ef3239a053?source=rss-45a65bf23d95------2</link>
            <guid isPermaLink="false">https://medium.com/p/21ef3239a053</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[telegram]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[bots]]></category>
            <dc:creator><![CDATA[the niqabi coder mum]]></dc:creator>
            <pubDate>Sat, 24 Nov 2018 10:30:23 GMT</pubDate>
            <atom:updated>2019-06-06T13:01:38.007Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*iSKHWwuzsr0roZCy.png" /></figure><p>Over the past year I have made my fair share of bots. I have made bots using services like Chatfuel and Flowxo, I have made bots from scratch in Python and Nodejs and I have used frameworks like Microsoft Bot Framework. I have also experimented with different deploying options for my coded-from-scratch bots including VPS, web servers, and serverless architecture.</p><p>Out of all of these options, I keep coming back to <a href="https://en.wikipedia.org/wiki/Serverless_computing">serverless</a> deployment. Not only can using a serverless computing architecture be extremely economical in many use cases, it is also very low maintanance. You don’t have to worry about maintaining a server at all. Just write your code, upload it to the cloud and then you can pretty much forget about it.</p><h3>Top 4 Bot Tutorials</h3><blockquote><a href="https://chatbotslife.com/best-chatbot-platforms-to-build-a-chatbot-13b846a59ddd">1. Best chatbot platforms to build a chatbot</a></blockquote><blockquote><a href="https://chatbotslife.com/build-simple-chatbot-with-rasa-part-1-f4c6d5bb1aea">2. Build simple ChatBot in Python with RASA — Part 1</a></blockquote><blockquote><a href="https://chatbotslife.com/build-simple-chatbot-with-rasa-part-2-16726357b72c">3. Build a simple ChatBot in Python with RASA — Part 2</a></blockquote><blockquote><a href="https://chatbotslife.com/how-i-developed-my-own-learning-chatbot-in-python-from-scratch-and-deployed-it-on-facebook-88bc828be0a8">4. How I developed my own ‘learning’ chatbot in Python</a></blockquote><h3>Echo Telegram bot with AWS API Gateway and AWS Lambda</h3><p>In this guide I will demonstrate making a simple serveless Telegram bot that echoes everything a user inputs, using AWS API Gateway and AWS Lambda. But first a little about the services we will use.</p><h3>What is API Gateway</h3><p>Amazon API Gateway is a publicly available endpoint for our code that runs on AWS Lambda, Amazon EC2, or other publicly addressable web services. It helps us deliver mobile and web application backends in a secure and scalable way.</p><h3>What is AWS Lambda</h3><p><a href="https://aws.amazon.com/lambda/">AWS Lambda</a> is a service that lets us create <a href="https://en.wikipedia.org/wiki/Stateless_protocol">stateless</a> functions (or blocks of code) in the cloud which can be invoked (or run) through a multitude of triggers. There are many other services beside AWS which let us create cloud functions, like <a href="https://cloud.google.com/functions/">Google Cloud Functions</a> and <a href="https://cloud.google.com/functions/">Azure Functions</a>.</p><p>Bots or <a href="https://chatbotslife.com/">chatbots</a> are an ideal candidate for this kind of computing service since in essence chatbots are just a piece of code which is triggered through a user interaction. Many popular chatbot making platforms are already using cloud functions as the backbone of their service.</p><p>With all that introduction out of the way, let’s get started!</p><h3>Registering a bot on Telegram</h3><p>To follow along this guide, you will need a Telegram bot. Registering a new bot in Telegram is really simple. Just send a “/newbot” command to Telegram’s own bot <a href="https://t.me/BotFather">BotFather</a> and follow the instructions. You will receive a bot token, copy this token and keep it handy.</p><p>You can customize the descriptions and about section of your bot, as well as change the profile picture for the bot through BotFather. Once you are happy with your bot’s settings, you are ready to proceed.</p><p>The way a Telegram bot works is that when a user sends a message to our bot’s account, Telegram sends that message to our code. Our code processes that message, and after doing whatever it needs to do, it sends back a message to Telegram servers which is then delivered to the user.</p><p>There are two ways we can get new updates from Telegram servers.</p><ol><li>Long polling in which our code keeps asking Telegram servers if there is a new update.</li><li>Setting webhooks in which we ask Telegram servers to send any new message/update received to us through a HTTP request.</li></ol><p>Setting webhooks is the most resource friendly and scalable way to receive new updates. And this is what we are going to do. But for that we will need a secure URL where Telegram servers can push all updates. Enter AWS API Gateway.</p><h3>Creating an API Gateway</h3><p>If you don’t have an Amazon account, sign up for one. You will need to provide your credit card details but Amazon has a very good free tier and to follow along this guide shouldn’t cost you anything.</p><p>Sign in to the <a href="https://aws.amazon.com/">AWS Console</a> and search API Gateway from the services.</p><p>Click on ‘Create API’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/0*Omp_uWhl7k-oQq8I.jpg" /></figure><p>Give your API a name and description and then click Create API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WjHq1KkDmG-LRXJJ.jpg" /></figure><p>Before defining any resources for this API, let’s first create our Lambda function.</p><h3>Creating a lambda function</h3><p>Sign in to the <a href="https://aws.amazon.com/">AWS Console</a> and choose Lambda from the services. Click ‘Create Function’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0rARyY7pDEzGEOe3.jpg" /></figure><p>Choose ‘Author from scratch’ option for now. Once you have followed this guide till the end, you can try exploring the different blueprints provided by Amazon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/0*GY8wgNjbHMAEPwuC.jpg" /></figure><p>Give you function a name, choose your favorite runtime (in the case of this guide choose Python3.6).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_sYVieyMVVJ5on2E.jpg" /></figure><p>Each Lambda function has an IAM role (execution role) associated with it. You specify the IAM role when you create your Lambda function. Permissions you grant to this role determine what AWS Lambda can do when it assumes the role. You can read more about managing permissions <a href="https://docs.aws.amazon.com/lambda/latest/dg/intro-permission-model.html#lambda-intro-execution-role">here</a>.</p><p>For the purpose of this guide, we will select ‘Create a new role from templates’ from the drop down menu. Give your role a name and then search ‘basic’ in the ‘Policy templates’ dropdown list. Select ‘Basic Lambda @ Edge permissions’. Then click ‘Create function’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/0*4lGw3OaZeYVH5t5D.jpg" /></figure><p>This will take you to your function. Scroll down and familiarize yourself with different options. You need to pay attention to a few options in particular:</p><ol><li>Environment variables — any environment variables that your code uses must be declared here.</li><li>Basic settings from where you can change the allocated memory and timeout. Please note that changing these settings may affect the costs. You can learn more about Lambda pricing <a href="https://aws.amazon.com/lambda/pricing/">here</a>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*cz9YBd4TvIVU6JEH.jpg" /></figure><p>Before we add any code to our function, let’s first add a trigger to it. We want that everytime someone sends a message to our <a href="https://chatbotslife.com/">bot</a> on Telegram, the Telegram servers should push it to our URL wher our code is hosted. In other words we want a HTTP GET/POST request to trigger our code and we will do this through our API gateway.</p><p>You can add the trigger to your Lambda function from Lambda’s own page as well but for now we will head over to API Gateway page to connect our Lambda function with the API and to configure the API.</p><h3>Connecting Lambda function to API Gateway</h3><p>Sign in to the <a href="https://aws.amazon.com/">AWS Console</a> and search API Gateway from the services.</p><p>Select the API which we created earlier. We will need to add some methods to this API. From the dropdown ‘Actions’ list select ‘Create Method’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1Upb0tkuKbYsxyMa.jpg" /></figure><p>You will see another dropdown list appear under “/”. From here you can add methods such as “GET” and “POST”. Since we are making a really simple bot, we don’t want a bunch of different methods. So for simplicity’s sake we will just choose “ANY” method. It means that no matter what kind of request is sent to this URL, it will always trigger the same code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/0*pl4iKXSPcUljqbrx.jpg" /></figure><p>Hit the small check sign next to “ANY” and it will take you to a new screen where you can choose what to do once this endpoint receives any kind of request. From here choose “Lambda Function” for integration type and the name of your Lambda function from the list. Also check the “Use Lambda Proxy Integration” option which will enable us to access the request details inside our Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DjLyr91Dhkme4_zP.jpg" /></figure><p>Click save. Test your API on the next screen to check if everything is working the way it should.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TlBC1DFY2UfKPTsw.jpg" /></figure><p>Then click “Deploy API” from the “Actions” list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/0*-5jhYN3rpua8UNTB.jpg" /></figure><p>Choose a stage name like “V1” or “beta” for the stage name. Once your API is deployed you will get an invoke URL. If you click on this URL, you should get a simple web page with “Hello from Lambda!”. Note down this URL.</p><h3>Setting Webhooks</h3><p>So now we have a secure URL which is connected to our code living in a cloud function. Cool! We can go ahead and tell Telegram to send any future messages received by our <a href="https://chatbotslife.com/">bot</a> to this address.</p><p>Setting a webhook is as simple as typing the following in your browser and hitting enter. (Make sure to substitute the place holder text)</p><pre>&quot;<a href="https://api.telegram.org/bot">https://api.telegram.org/bot</a>&lt;your-bot-token&gt;/setWebHook?url=&lt;your-API-invoke-URL&gt;&quot;</pre><p>You will get a confirmation message from Telegram and from now on any messages sent to your bot will be pushed to this URL.</p><h3>Adding code to Lambda function</h3><p>Go ahead and try sending a message from your own Telegram account to the bot.</p><p>So apparently nothing happens 🤔 and that is because our code is not yet doing anything. But if you want to make sure that your function was triggered by receiving the webhook, you can do so by checking the CloudWatch logs. Select “Monitoring” tab and then “View logs in CloudWatch” on the Lambda function’s page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AfQXs1HFHCjmUFDM.jpg" /></figure><p>We will write some very basic code which will just return the message sent by the user. Replace the code in your Lambda function’s visual editor with the following:</p><pre>import json<br>from botocore.vendored import requests</pre><pre>TELE_TOKEN=&#39;&lt;YOUR-BOT-TOKEN&gt;&#39;<br>URL = &quot;<a href="https://api.telegram.org/bot%7B%7D/">https://api.telegram.org/bot{}/</a>&quot;.format(TELE_TOKEN)</pre><pre>def send_message(text, chat_id):<br>    final_text = &quot;You said: &quot; + text<br>    url = URL + &quot;sendMessage?text={}&amp;chat_id={}&quot;.format(final_text, chat_id)<br>    requests.get(url)</pre><pre>def lambda_handler(event, context):<br>    message = json.loads(event[&#39;body&#39;])<br>    chat_id = message[&#39;message&#39;][&#39;chat&#39;][&#39;id&#39;]<br>    reply = message[&#39;message&#39;][&#39;text&#39;]<br>    send_message(reply, chat_id)<br>    return {<br>        &#39;statusCode&#39;: 200<br>    }</pre><p>This is a very simple piece of code as you can see. We are just extracting the message and chat id from the event object and sending it back as a query string along with the chat id in a HTTP GET request to <a href="https://api.telegram.org/">https://api.telegram.org</a> with our token. We also return a JSON object with “statusCode” as “200” so telegram servers can know that the request was received successfully.</p><p>You can read more about interacting with the Telegram API <a href="https://core.telegram.org/bots/api">here</a>.</p><p>Go ahead and send your bot some messages and it should return the same messages back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/0*jderft0uIJ0hAAiS.jpg" /></figure><p>Of course, for a production bot we will do a few things differently, for example adding the bot token as an environment variable and adding security layers. But that is beyond the scope of this simple tutorial.</p><h3>Conclusion</h3><p>This brings us to the end of this guide. We learned how to create a simple echo bot for Telegram but more than that we learned how to host it completely serverless in the cloud.</p><p>Traditionally to run this kind of bot, we would need to write our code not as a simple script but within a micro service framework like Flask. We would need basic scaffolding like a web server to serve the code, a SSL certificate to make our connection secure and so on. But thanks to the powerful Lambda functions and the API Gateway our task was made significantly simpler.</p><p><em>I am Naveera Ashraf, an autodidact and polymath. I make chatbots for people at </em><a href="https://creativemelon.co.za/"><em>Creative Melon</em></a><em>. You can read about my other projects </em><a href="https://naveeraashraf.com/"><em>here</em></a><em> or follow me on </em><a href="https://twitter.com/niqabicodermum"><em>Twitter</em></a><em>. This post was originally posted on my blog </em><a href="https://blog.naveeraashraf.com/"><em>https://blog.naveeraashraf.com</em></a></p><h3>Don’t forget to give us your 👏 !</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*Bu-bH34pTed5c0Hx" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e59ef%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e59ef&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e59ef%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/7078d8ad19192c4c53d3bf199468e4ab/href">https://medium.com/media/7078d8ad19192c4c53d3bf199468e4ab/href</a></iframe><figure><a href="https://chatbotslife.com/bot-communities-mastermind-group-d2dae9876709#.53x0py6ou"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*6XUspT9JOSq0w0Fi35HIaA.png" /></a></figure><figure><a href="https://m.me/ChatbotsLife"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*c1LDMH5vbnIz9rmAka8Hwg.png" /></a></figure><figure><a href="https://chatbotslife.com/chatbot-development-hire-top-ai-chatbot-developers-c8b45ef7f207"><img alt="" src="https://cdn-images-1.medium.com/max/255/1*D0Jf3dI6ZThtqcfwDYY7mg.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21ef3239a053" width="1" height="1" alt=""><hr><p><a href="https://blog.chatbotslife.com/building-a-telegram-bot-with-aws-api-gateway-and-aws-lambda-21ef3239a053">🚀 Building a Telegram Bot with AWS API Gateway and AWS Lambda</a> was originally published in <a href="https://blog.chatbotslife.com/">Chatbots Life</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn Django]]></title>
            <link>https://medium.com/@niqabicodermum/learn-django-ebc62b22c443?source=rss-45a65bf23d95------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebc62b22c443</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[life-learning]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[the niqabi coder mum]]></dc:creator>
            <pubDate>Sat, 15 Sep 2018 11:54:27 GMT</pubDate>
            <atom:updated>2018-09-15T11:54:27.743Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lX09TBQvOKzYDvDL3gCVDw.png" /></figure><p>Recently I have been focusing on learning <a href="https://www.djangoproject.com/">Django</a>. Django is a web development framework for Python. There are <a href="https://www.edureka.co/blog/django-tutorial/?utm_source=facebook&amp;utm_medium=crosspost&amp;utm_campaign=social-media-edureka-sep-aj#whydjango">many benefits of using Django</a>. It is a very high level framework which means it is quite easy to learn. You get lots of functionality out of box which means it is ideal when you want to make something good real quick.</p><p>Below I am sharing the best resources I have come across so far in learning Django. All of these resources are beginner friendly yet they take you through some advance level stuff as well.</p><h3>Free Resources</h3><p>1. <a href="https://www.youtube.com/watch?v=D6esTdOLXh4&amp;t=1416s">Django Crash Course by Traversy Media</a></p><p>I like Traversy Media’s videos as I learn the best by example. Seeing him code and make a project from scratch explains the concept better than theory alone. In this video Brad makes a simple blogging web app (blogging apps are Hello World of web frameworks I think :) )</p><p>2. <a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django">MDN Django Tutorial</a></p><p>Mozilla Developers’ Network has a hands-on tutorial for Django where you read the easy to follow tutorial and make your own Local Library website, an online catalog for a small local library, where users can browse available books and manage their accounts. After you follow the tutorial till the end try making another website like this with some variations and see if you can figure it out.</p><p>3. <a href="https://www.youtube.com/watch?list=PLhTjy8cBISEpXc-yjjSW90NgNyPYe7c9_&amp;v=ehCjpQXetgo">Build a Personal Website with Python</a></p><p>It is a Youtube playlist where they take you through building a complete personal website from bottom up using Django and deploying it on Heroku.</p><p>4. <a href="https://www.youtube.com/watch?v=uu98pqiUJU8&amp;list=PLEsfXFp6DpzTD1BD1aWNxS2Ep06vIkaeW">Try Django</a></p><p>Coding Entrepreneurs have some very good tutorials and courses on lots of different topics. Their Try Django series is a very thorough and detailed Django tutorial for beginners. They also have other paid resources for advance level Django. (See paid resources below)</p><p>5. <a href="https://www.youtube.com/watch?v=zu2PBUHMEew">Build a Video Subscription Website with Django</a></p><p>Learn to build a basic video subscription website with Django and Stripe payments.</p><h3>Paid Resources</h3><p>6. <a href="https://www.udemy.com/tweetme-django/?siteID=Fh5UMknfYAU-bYhu0D5r3JTUILsNdLIENA&amp;LSNPUBID=Fh5UMknfYAU">Tweetme</a></p><p>From the creators of famous Try Django series. This Udemy course teaches you to make a real service like Twitter with Bootstrap integration.</p><p>7. <a href="https://www.amazon.com/Django-Example-Antonio-Mele/dp/1784391913">Django by Example</a></p><p>A very thorough book on web development with Django. Learn Django by building four fully-functional, real-world web applications from scratch using the best coding practices. It also teaches you to integrate other technologies into your application with lots of example code. If you prefer videos to books, the author also teaches this book in <a href="https://www.udemy.com/django-by-example/">a Udemy course.</a></p><p>8. <a href="https://www.udemy.com/python-and-django-full-stack-web-developer-bootcamp/?siteID=jU79Zysihs4-SZQmxsM245blpA0ZPd2XKQ&amp;LSNPUBID=jU79Zysihs4">Python and Django Full Stack Web Developer Bootcamp</a></p><p>This is one of the best selling courses on Udemy and although I haven’t used this course personally I have heard good reviews of it.</p><p>Other Resources</p><p>1. <a href="https://www.reddit.com/r/django">Django Subreddit</a></p><p>2. <a href="https://www.agiliq.com/blog/2014/08/deploying-a-django-app-on-amazon-ec2-instance/">Deploying Django app on Amazon EC2</a></p><p>I am a Muslim, unschooling mother. Student of Quran. I am an autodidact. I taught myself Quranic Arabic, computer programming and web development. Currently I am learning Data Science and Blockchain development. When not bullying my brain into learning something new, I like to bake sourdough bread and grow vegetables. <br>https://naveeraashraf.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebc62b22c443" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s gather some Light]]></title>
            <link>https://medium.com/tadabbur-fil-quran/lets-gather-some-light-cace61e680cc?source=rss-45a65bf23d95------2</link>
            <guid isPermaLink="false">https://medium.com/p/cace61e680cc</guid>
            <category><![CDATA[islam]]></category>
            <category><![CDATA[al-hadid]]></category>
            <category><![CDATA[reflections]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[quran]]></category>
            <dc:creator><![CDATA[the niqabi coder mum]]></dc:creator>
            <pubDate>Sun, 24 Dec 2017 08:24:38 GMT</pubDate>
            <atom:updated>2017-12-24T09:12:49.852Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7c6Ctwradg97u9Gm3RPSKw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/OWO3ca8Y98k?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Michał Grosicki</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h4>بسم الله الرحمن الرحيم</h4><blockquote>“On the Day you shall see the believing men and the believing women their light running forward before them and by their right hands. Glad tidings for you this Day! Gardens under which rivers flow (Paradise), to dwell therein forever! Truly, this is the great success!” [Al-Hadid: 12]</blockquote><p>Each and every word of Allah in the Quran is powerful but there are some ayaat and suraahs which offer so much to reflect upon and so many lessons to draw from and sura al-Hadid is one of them. It is one of the most powerful and most beautiful of surahs, and one of my most favorite one. There is an intense beauty in these words which stir the soul. For example just take this ayaah and the expression that ‘their light running forward before them …’ It’s gut wrenching! <strong>I wish every Muslim could understand Allah’s words directly, without the human factor of translation getting involved. Then we would experience the true miracle of Quran.</strong></p><p>‘The day’ here refers to the ‘Day of Resurrection’. The fact of ‘light running before them’ will take place just prior to people’s passing over the bridge of sirat. There will come a stage on the day of Qiyamah when people — believers and non-believers — all will assemble on the Plane of Gathering. An intense darkness will prevail and nobody will be able to see anything. Thereafter this noor (light) will be distributed amongst muminoon (believers) according to their deeds.</p><p>There are lengthy discussions in the books of tafseer about this noor and you can read tafseer ibn Kathir or Maarif al Quran for a beautiful discussion on it. <strong>Here I am just mentioning a few ahadeeth which tell us how to earn this noor on the day of Qiyamah.</strong> (For references of these ahadeeth, refer to the tafseer of this ayaah in Maarif al Quran)</p><ol><li>“Give glad tidings to those who go to the mosque in the darkness of night that they will receive perfect light on the Day of Judgment.”</li><li>“He who takes care of his five daily prayers [that is, performs them regularly fulfilling all their essentials], it will serve as light, proof and salvation for him on the Day of Judgement. He who fails to take care of it, there will be no light, nor proof or salvation for him on the Day of Judgement. The latter will be in the company of Qarun, Haman and Fir’aun.”</li><li>“Whoever recites sura Al-Kahf, there will be so much of light for him on the Day of Judgement that it will spread from his place to Makkah.” In another narration, “Whoever recites Surah Al-Kahf on a Friday, light will extend from his feet to the heights of the heaven on the Day of Judgment.”</li><li>“Whoever recites just a single verse of the Quran, it will be a light for him on the Day of Judgement.”</li><li>“Whoever sends salah (durud) to me, it shall be the cause of light on the Bridge of Sirat.”</li><li>“The hair, that falls on the ground at the time of shaving it when coming out of the state of ihram, will be a light for him on the Day of Judgement.”</li><li>“Stoning the jamaraat in Mina will be a light on the Day of Judgement.”</li><li>“He whose hair turns grey in Islam, it will be a light for him on the Day of Judgement.” (i.e. he remains steadfast on Islam for his whole life)</li><li>“He who shoots even one arrow in Allah’s way while fighting in jihad, it will be a light for him on the Day of Judgement.”</li><li>“He who remembers Allah in the marketplace will receive light for every strand of hair on the Day of Judgement.” (markets being the places where the temptations of dunya manifest themselves)</li><li>“He who alleviates the calamity of a Muslim, Allah will create two compartments of light for him at the bridge which will brighten up a whole world. No one besides Allah knows its number.”</li></ol><p>May Allah grant us the light! Ameen</p><h4>سبحانك اللهم و بحمدك نشهد ان لااله الّا انت نستغفرك و نتوب اليك</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cace61e680cc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tadabbur-fil-quran/lets-gather-some-light-cace61e680cc">Let’s gather some Light</a> was originally published in <a href="https://medium.com/tadabbur-fil-quran">Tadabbur fil Quran</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimism and belief in al-akhirah]]></title>
            <link>https://medium.com/tadabbur-fil-quran/optimism-and-belief-in-al-akhirah-d328fc627750?source=rss-45a65bf23d95------2</link>
            <guid isPermaLink="false">https://medium.com/p/d328fc627750</guid>
            <category><![CDATA[quran]]></category>
            <category><![CDATA[reflections]]></category>
            <category><![CDATA[islam]]></category>
            <category><![CDATA[al-baqara]]></category>
            <category><![CDATA[muslim]]></category>
            <dc:creator><![CDATA[the niqabi coder mum]]></dc:creator>
            <pubDate>Fri, 22 Dec 2017 09:53:45 GMT</pubDate>
            <atom:updated>2017-12-22T09:53:45.417Z</atom:updated>
            <content:encoded><![CDATA[<h4>بسم الله الرحمن الرحيم</h4><p>The day was hot. The army was marching in the hot sun towards the battleground, dragging their feet, their lips parched with thirst and bodies drenched in sweat. They had been marching for days. What little water they could carry was coming to an end.</p><p>Suddenly their leader, Talut AS stopped them. He looked at his army and said:</p><blockquote>“Indeed, Allah will be testing you with a river. So whoever drinks from it is not of me, and whoever does not taste it is indeed of me, excepting one who takes [from it] in the hollow of his hand.” [Quran 2:249]</blockquote><p>Everyone looked up in surprise. They hardly paid attention to what Talut AS had said except that there was a river nearby. They rushed forward towards river. They jumped in it, they drank to their full, they bathed in it, they splashed water over each other and cried and laughed with joy!</p><p>Everyone but a few! Those few who were equally thirsty, but they believed with all their heart that they were going to meet their Lord and answer for their actions. Those few whose eyes shone with the determination of obeying their Master, come river or hell!</p><p>The army crossed the river, and from a high ground they saw the enemy’s battalion. Rows and rows of men and beasts. The enemy was, at least, thrice in number to Banu Israel whose king was Talut AS. They all cried out in unison:</p><blockquote>“There is no power for us today against Goliath and his soldiers.” [Quran 2:249]</blockquote><p><strong>Everyone but a few!</strong></p><blockquote>“But those who were certain that they would meet Allah said, “How many a small company has overcome a large company by permission of Allah. And Allah is with the patient.” [Quran 2:49]</blockquote><p>The story goes on, the battle was fought and Dawood AS killed Goliath (leader of the enemy) and banu Israel won this battle. But when reading these ayaat, I always pause and reflect on this scene before the battle. And the lesson I learn from this image is that <strong>the firm belief in aakhirah and meeting Allah is a source of power for those who believe. It not only gives us the ability to stop ourselves in the face of temptation (like the river for banu Israel), it also gives us a positive attitude in life. And hope. And courage and determination and everything which we need on a daily basis.</strong></p><p>When Allah mentions the positive attitude of these few in the face of army who said “How many a small company has overcome a large company by permission of Allah. And Allah is with the patient.” What is the characteristic Allah mentions them with? He mentions their firm belief in meeting their Lord.</p><p>A believer is not the one who will sit in a corner depressed or give up even before the battle starts. Our imaan gives us the confidence to look our enemy in the eye, no matter how big he is and say “Allah is with the patient!”</p><p>Our belief that we will go back to our Lord is the root of all positive attitude we need in this world.</p><p><em>(P.S. When I mention depression, I am talking about the attitude and mind frame. I am not dismissing clinical depression neither do I believe that those suffering from depression or anxiety do not have a strong Imaan.)</em></p><h4>سبحانك اللهم و بحمدك نشهد ان لااله الّا انت نستغفرك و نتوب اليك</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d328fc627750" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tadabbur-fil-quran/optimism-and-belief-in-al-akhirah-d328fc627750">Optimism and belief in al-akhirah</a> was originally published in <a href="https://medium.com/tadabbur-fil-quran">Tadabbur fil Quran</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Allah sets role-models for us]]></title>
            <link>https://medium.com/tadabbur-fil-quran/allah-sets-role-models-for-us-8c32d0246c9f?source=rss-45a65bf23d95------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c32d0246c9f</guid>
            <category><![CDATA[islam]]></category>
            <category><![CDATA[quran]]></category>
            <category><![CDATA[al-baqara]]></category>
            <dc:creator><![CDATA[the niqabi coder mum]]></dc:creator>
            <pubDate>Sun, 10 Sep 2017 11:20:05 GMT</pubDate>
            <atom:updated>2017-09-10T11:20:05.590Z</atom:updated>
            <content:encoded><![CDATA[<h3>بسم الله الرحمن الرحيم</h3><p>There are different levels when it comes to our relationship with Allah. First, there are those who try not to make Allah angry. Then there are those whose goal is to make Allah happy. Most of us fall somewhere in between these two stages.</p><p>But there is a third stage.</p><blockquote>“And among men there is one who sells his very soul to seek the pleasure of Allah, and Allah is Very-Kind to His servants.” [Al-Baqarah:207]</blockquote><p>This is the ultimate height of love for Allah. This is the level attained by the sahabah. They rose above their own likes and dislikes. They turned away from anything that clashed with the way of Allah. For them the needs of Allah’s slaves always came before their own needs. The riches of this world could not buy them neither the beauty of the world could lure them as they had already sold themselves to gain the pleasure of Allah. Radhi Allahu anhum wa radho anhu.</p><p><strong>And this is the role model Allah sets for us.</strong></p><p>Selling one’s self to please Allah is a very strong expression in itself. But coupled with the word “maradhaat” the meaning is intensified even further. It means that these slaves do not seek just the pleasure of Allah, they seek the extreme pleasure of Allah. They go above and beyond in their desire to please their Master. The will do anything and everything to please Him. The ultimate goal in their life is His pleasure and their eyes are always on His countenance.</p><p>But what is even more inspiring in this ayah is Allah’s side of relationship to these slaves. Allah chooses His majestic name “Ar-Raoof” here. <strong>Whenever Allah uses one of His majestic names in an ayah, there is a deep relationship between that sifah (characteristic) of Allah and the context of that ayaah.</strong></p><p>Raoof comes from the root raa-hamza-faa, which points to three main meanings. The first main meaning is to be gentle, kind, and forgiving and the second is to be merciful and compassionate. The third main meaning is to show pity mixed with deep affection and tenderness.</p><p>Al-Ghazali mentioned that Ar-Raoof has pity, and that pity is the intensification of mercy. It has the same meaning as Raheem though in a more intense form. Ar-Raoof is the One who bestows pity and mercy on us in many different forms, including warnings and withholding, for us to be guided to success in this world and the next!</p><p>An example was given about ra’fa and rahma; a parent warning their child to dress warm in winter so that they won’t suffer from the cold, is the concept of ra’fa. Whereas if the child gets ill and the parent’s heart that aches for the child and they do everything to find a medicine, that’s merciful (rahma).</p><p>So in this ayah after mentioning those people who do their utmost to please Him, Allah mentions His tender mercy and love towards these slaves. Allah is telling us that He knows what His slave is going through in the quest to please His master. He is aware of the heartaches, the trials, the troubles, the sadness and the grief.</p><p><strong>And He is assuring us that He is lovingly and mercifully watching and guiding these slaves towards Him.</strong> Almost like a mother who lovingly hovers while her baby takes the first steps.</p><p>May Allah makes us from amongst these slaves of His. Ameen.</p><h3>سبحانك اللهم و بحمدك نشهد ان لااله الّا انت نستغفرك و نتوب اليك</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c32d0246c9f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tadabbur-fil-quran/allah-sets-role-models-for-us-8c32d0246c9f">Allah sets role-models for us</a> was originally published in <a href="https://medium.com/tadabbur-fil-quran">Tadabbur fil Quran</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[بسم الله مجرها و مرسها]]></title>
            <link>https://medium.com/tadabbur-fil-quran/%D8%A8%D8%B3%D9%85-%D8%A7%D9%84%D9%84%D9%87-%D9%85%D8%AC%D8%B1%D9%87%D8%A7-%D9%88-%D9%85%D8%B1%D8%B3%D9%87%D8%A7-8fcc7d456d38?source=rss-45a65bf23d95------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fcc7d456d38</guid>
            <category><![CDATA[islam]]></category>
            <category><![CDATA[hud]]></category>
            <category><![CDATA[religion]]></category>
            <category><![CDATA[quran]]></category>
            <dc:creator><![CDATA[the niqabi coder mum]]></dc:creator>
            <pubDate>Mon, 17 Jul 2017 12:56:29 GMT</pubDate>
            <atom:updated>2017-07-17T13:02:34.778Z</atom:updated>
            <content:encoded><![CDATA[<h3>بسم الله الرحمن الرحيم</h3><p>The sun was high in the horizon, its light glinting at the top of the tress in a small wood. The birds were quiet, seeking the shelter of the trees against the heat of the day. And in the silence the only sound being heard was the banging of a hammer on wood.</p><p>The chiefs and their companions were returning from an errand when they passed the small wood. Their eyes lit up at the prospect of some fun to break the monotony of the day. They entered the clump of the trees from where came the sounds of hammering.</p><p>“Alright Nuh? Still busy with your ship?” One of the chiefs’ young son cried out at the old man in the clearing. His old face showed signs of tiredness but his hands were busy hammering a piece of wood. They were all used to the old man Nuh. He was there when their fathers were young and he was there when their grandfathers were young. They were used to the old man as a part of their lives but they didn’t take him seriously. After all he had been warning of a punishment coming to them for 950 years.</p><p>“Where is this ship going to sail? In the sand?” Another jest came.</p><p>The chief shook his head from side to side “We told you Nuh, if you will hang out with riff-raff like these, it’s going to rub on you.” He said pointing towards the old man’s handful of helpers who were all carpenters, black-smiths and such. “Here you are, an old man from a respectable family, deceiving yourself.”</p><p>The old man did not look up. Still intent on his work he replied:</p><blockquote>“If you ridicule us, then we will ridicule you just as you ridicule. And you are going to know who will get a punishment that will disgrace him (on earth) and upon whom will descend an enduring punishment (in the Hereafter).” [Hud:38–39]</blockquote><p>The chiefs and their men laughed. One of the youngsters said in a loud whisper “The old man has gone gaga. Why, even his own son and wife do not believe in him.” At these words pain shot through the old eyes. Satisfied with this parting shot, they retreated. Slowly the sounds of their laughing and jesting died away. The old man was still bent on his handiwork. In the silence the only sound that could be heard was a hammer banging away……</p><p>This is the scene my mind conjures up as I read the story of Nuh AS. And this is what Allah SWT wants all of us to do. When telling the story of previous nations and Messengers, Quran adopts a language of story-telling. So, for example, rather than saying “Nuh was making the boat and the chiefs came to jest at him.”, Allah says “And Nuh IS making the ship….” Allah wants us to enter the time and space of that event. He wants us to feel the emotions, to taste the fear, to rejoice at the joy of these Anbiyaa and their followers. Only then will we be able to relate to and follow the foot-prints of these great human beings.</p><p><strong>Then we will remember Nuh (AS) when people ridicule us, as we prepare for a day which, as yet, is nowhere in sight.</strong> When they call us a fool as we decline that shady business deal, as we lose our job because of the beard, as we lose the contract because we refused to shake hands with na-mahram person, as we lose money when we do not rent our property to the liquor store, as we choose to stay single until we find a pious spouse, as we lose our friends because we are not interested in gossip or celebrities.</p><p>And then we will learn that while jesters jest, we should carry on doing what Allah has commanded us to do like Nuh AS did.</p><p>And when calamities hit us and practicing upon the Deen is like a red hot coal in hand, we will remember Nuh (AS) and his ship, the rain pouring down on it in torrents, the waves under it as high as mountains and the darkness engulfing it only pierced by terrifying lightning. And we learn that no matter its slippery deck, that fragile vessel was the only place in the whole universe which offered refuge from Allah’s wrath and where Allah’s mercy for His servants materialized.</p><p>And when we think we can no longer face the storm, we will remember Nuh’s (AS) ark, safely resting on mount Judi, the sun spilling through its battered windows, the birds once again chirping around it, flowers blossoming and animals singing the praises of Allah while Nuh (AS) and his followers prostrated in gratitude.</p><p><strong>So until I find my Judi, I sail in the fragile vessel of my Imaan, in a world full of darkness and confusion, putting all my trust in Allah and saying as Nuh (AS) said:</strong></p><blockquote>“In the Name of Allah will be its (moving) course and its (resting) anchorage.”[Hud: 41]</blockquote><p>سبحانك اللهم و بحمدك نشهد ان لااله الّا انت نستغفرك و نتوب اليك</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fcc7d456d38" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tadabbur-fil-quran/%D8%A8%D8%B3%D9%85-%D8%A7%D9%84%D9%84%D9%87-%D9%85%D8%AC%D8%B1%D9%87%D8%A7-%D9%88-%D9%85%D8%B1%D8%B3%D9%87%D8%A7-8fcc7d456d38">بسم الله مجرها و مرسها</a> was originally published in <a href="https://medium.com/tadabbur-fil-quran">Tadabbur fil Quran</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>