<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Yasoob Khalid</title>
		<link>https://yasoob.me/</link>
		<description>Yasoob Khalid, author of Intermediate Python &amp; Practical Python Projects, writes in-depth guides on Python, reverse engineering, and hardware hacking.</description>
		<generator>Hugo</generator>
		<language>en-US</language>
		<copyright>CC-by-NA</copyright>
		<image>
			<url>https://yasoob.me/images/profile.jpg</url>
			<title>Yasoob Khalid</title>
			<link>https://yasoob.me/</link>
		</image>
		<lastBuildDate>Mon, 02 Nov 2026 17:14:34 -0800</lastBuildDate>
		<atom:link href="https://yasoob.me/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Dark Mode for Websites - Privacy Policy</title>
				<link>https://yasoob.me/privacy/dark-mode/</link>
				<pubDate>Mon, 02 Nov 2026 17:00:00 -0800</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/privacy/dark-mode/</guid>
				<description>Effective Date: November 2, 2026 Dark Mode for Websites (“Dark Mode”, “the app”) is an app and Safari extension for iPhone and iPad that makes websites dark. Dark Mode works on your iPhone or iPad alone. It never collects or sends the pages you visit. The Short Version Dark Mode has no accounts, no analytics and no ads. The developer receives no data about you or the websites you visit. Everything Dark Mode knows stays on your device. The exception is iCloud sync, which you turn on yourself and which stores your settings in your own iCloud account. Web Pages To make pages dark, the extension reads each page inside Safari, on your device. Nothing it reads leaves your device.</description>
				<content:encoded>&lt;p&gt;Effective Date: November 2, 2026&lt;/p&gt;&#xA;&lt;p&gt;Dark Mode for Websites (&amp;ldquo;Dark Mode&amp;rdquo;, &amp;ldquo;the app&amp;rdquo;) is an app and Safari extension for iPhone and iPad that makes websites dark. Dark Mode works on your iPhone or iPad alone. It never collects or sends the pages you visit.&lt;/p&gt;&#xA;&lt;h2 id=&#34;the-short-version&#34;&gt;The Short Version&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Dark Mode has no accounts, no analytics and no ads.&lt;/li&gt;&#xA;&lt;li&gt;The developer receives no data about you or the websites you visit.&lt;/li&gt;&#xA;&lt;li&gt;Everything Dark Mode knows stays on your device. The exception is iCloud sync, which you turn on yourself and which stores your settings in your own iCloud account.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;web-pages&#34;&gt;Web Pages&lt;/h2&gt;&#xA;&lt;p&gt;To make pages dark, the extension reads each page inside Safari, on your device. Nothing it reads leaves your device.&lt;/p&gt;&#xA;&lt;p&gt;Some pages use stylesheets from other servers. To darken those, the extension downloads the same stylesheets again from the servers the page already uses, without your cookies. Nothing about you is added to those requests.&lt;/p&gt;&#xA;&lt;h2 id=&#34;site-rules-from-github&#34;&gt;Site Rules from GitHub&lt;/h2&gt;&#xA;&lt;p&gt;Once a day at most, Dark Mode downloads site rules from GitHub. These are public files with fixes for individual websites. That download carries nothing about you or the sites you visit. Like any web request, it reaches GitHub from your device&amp;rsquo;s internet connection. You can turn automatic updates off in Safari&amp;rsquo;s Dark Mode menu, under Settings › Site rules.&lt;/p&gt;&#xA;&lt;h2 id=&#34;your-settings&#34;&gt;Your Settings&lt;/h2&gt;&#xA;&lt;p&gt;Your theme, schedule and website rules are stored on your device, shared between the app and the Safari extension. Website rules are the websites you&amp;rsquo;ve given their own theme, kept dark, or excluded.&lt;/p&gt;&#xA;&lt;p&gt;When Sync with iCloud is on, your settings, including the websites you&amp;rsquo;ve set rules for, are stored in your iCloud account by Apple, so your other devices can use them. The developer can&amp;rsquo;t see them. You can turn it off at any time in the app.&lt;/p&gt;&#xA;&lt;p&gt;You can export your settings to a file. That file goes only where you send it.&lt;/p&gt;&#xA;&lt;h2 id=&#34;website-icons&#34;&gt;Website Icons&lt;/h2&gt;&#xA;&lt;p&gt;The Websites list in the app shows each site&amp;rsquo;s icon, loaded from that site. When it does, that website receives an ordinary request for its icon from your device.&lt;/p&gt;&#xA;&lt;h2 id=&#34;location&#34;&gt;Location&lt;/h2&gt;&#xA;&lt;p&gt;Sunset to sunrise can use your location, rounded to about a kilometre, to work out sunset. It&amp;rsquo;s stored only in your settings. With Sync with iCloud on, it&amp;rsquo;s in your iCloud account along with the rest of your settings. Dark Mode asks for location only when you choose Sunset to sunrise. If you don&amp;rsquo;t allow it, sunset is estimated from your time zone instead. You can turn location access off at any time in your device&amp;rsquo;s Settings.&lt;/p&gt;&#xA;&lt;h2 id=&#34;children&#34;&gt;Children&lt;/h2&gt;&#xA;&lt;p&gt;Dark Mode collects no personal information from anyone, including children.&lt;/p&gt;&#xA;&lt;h2 id=&#34;changes-to-this-privacy-policy&#34;&gt;Changes to This Privacy Policy&lt;/h2&gt;&#xA;&lt;p&gt;If this policy changes, the new version will be posted on this page with a new effective date.&lt;/p&gt;&#xA;&lt;h2 id=&#34;contact-us&#34;&gt;Contact Us&lt;/h2&gt;&#xA;&lt;p&gt;If you have any questions about this Privacy Policy or the app, email:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Email:&lt;/strong&gt; &lt;a href=&#34;mailto:bugs@yasoob.me&#34;&gt;bugs@yasoob.me&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Dark Mode for Websites - Support Page</title>
				<link>https://yasoob.me/support/dark-mode/</link>
				<pubDate>Mon, 02 Nov 2026 17:00:00 -0800</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/support/dark-mode/</guid>
				<description>Welcome to the support page for Dark Mode for Websites, the Safari extension that makes websites dark on iPhone and iPad. Below you’ll find how to set it up, how to use it, and what to try when something doesn’t look right. If you need more help, email bugs@yasoob.me. Table of Contents Getting Started On, Auto and Off Themes Changing One Website Syncing and Backups Troubleshooting Contact Support Getting Started Turning On Dark Mode in Safari Dark Mode works inside Safari, so Safari needs to be allowed to use it. The Safari Setup Guide in the app walks you through these steps.</description>
				<content:encoded>&lt;p&gt;Welcome to the support page for Dark Mode for Websites, the Safari extension that makes websites dark on iPhone and iPad. Below you&amp;rsquo;ll find how to set it up, how to use it, and what to try when something doesn&amp;rsquo;t look right. If you need more help, email &lt;a href=&#34;mailto:bugs@yasoob.me&#34;&gt;bugs@yasoob.me&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;table-of-contents&#34;&gt;Table of Contents&lt;/h2&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/dark-mode/#getting-started&#34;&gt;Getting Started&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/dark-mode/#on-auto-and-off&#34;&gt;On, Auto and Off&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/dark-mode/#themes&#34;&gt;Themes&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/dark-mode/#changing-one-website&#34;&gt;Changing One Website&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/dark-mode/#syncing-and-backups&#34;&gt;Syncing and Backups&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/dark-mode/#troubleshooting&#34;&gt;Troubleshooting&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/dark-mode/#contact-support&#34;&gt;Contact Support&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;getting-started&#34;&gt;Getting Started&lt;/h2&gt;&#xA;&lt;h3 id=&#34;turning-on-dark-mode-in-safari&#34;&gt;Turning On Dark Mode in Safari&lt;/h3&gt;&#xA;&lt;p&gt;Dark Mode works inside Safari, so Safari needs to be allowed to use it. The &lt;strong&gt;Safari Setup Guide&lt;/strong&gt; in the app walks you through these steps.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Open &lt;strong&gt;Settings › Apps › Safari › Extensions&lt;/strong&gt;. On iOS 17, it&amp;rsquo;s &lt;strong&gt;Settings › Safari › Extensions&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Tap &lt;strong&gt;Dark Mode&lt;/strong&gt; and turn on &lt;strong&gt;Allow Extension&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Under &lt;strong&gt;Permissions&lt;/strong&gt;, set &lt;strong&gt;All Websites&lt;/strong&gt; to &lt;strong&gt;Allow&lt;/strong&gt;, so Dark Mode can reach every page.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;You can also do this from Safari itself: tap the puzzle icon in the address bar, then &lt;strong&gt;Manage Extensions&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;opening-dark-mode-in-safari&#34;&gt;Opening Dark Mode in Safari&lt;/h3&gt;&#xA;&lt;p&gt;On any website, tap the puzzle icon in Safari&amp;rsquo;s address bar, then &lt;strong&gt;Dark Mode&lt;/strong&gt;. This opens Safari&amp;rsquo;s Dark Mode menu, where you can change the theme for every website or just the one you&amp;rsquo;re on. Settings you change there show up in the app too.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;on-auto-and-off&#34;&gt;On, Auto and Off&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;On&lt;/strong&gt; makes every website dark.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Auto&lt;/strong&gt; turns dark mode on following a schedule.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Off&lt;/strong&gt; leaves websites as they are.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;choosing-what-auto-follows&#34;&gt;Choosing What Auto Follows&lt;/h3&gt;&#xA;&lt;p&gt;In the app, open &lt;strong&gt;Schedule&lt;/strong&gt;:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;System appearance&lt;/strong&gt; follows your iPhone or iPad&amp;rsquo;s own light and dark appearance.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Sunset to sunrise&lt;/strong&gt; turns dark mode on after sunset. If you allow location, sunset is worked out from where you are, rounded to about a kilometre. If you don&amp;rsquo;t, it&amp;rsquo;s estimated from your time zone, which is usually within an hour of the real time.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Custom schedule&lt;/strong&gt; turns dark mode on and off at times you choose.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;themes&#34;&gt;Themes&lt;/h2&gt;&#xA;&lt;p&gt;Open &lt;strong&gt;Theme&lt;/strong&gt; in the app to pick one of four presets: &lt;strong&gt;Default&lt;/strong&gt;, &lt;strong&gt;Midnight&lt;/strong&gt;, &lt;strong&gt;Warm&lt;/strong&gt; and &lt;strong&gt;OLED&lt;/strong&gt; (pure black). The sliders below them change brightness, contrast, sepia and grayscale. The preview at the top shows a page in your theme as you change it.&lt;/p&gt;&#xA;&lt;p&gt;Safari&amp;rsquo;s Dark Mode menu has more options, such as the background and text colors, the font, and the Dynamic or Filter mode.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;changing-one-website&#34;&gt;Changing One Website&lt;/h2&gt;&#xA;&lt;p&gt;In Safari&amp;rsquo;s Dark Mode menu, while you&amp;rsquo;re on the website:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Turn off the switch&lt;/strong&gt; next to the website&amp;rsquo;s name to leave that site as it is.&lt;/li&gt;&#xA;&lt;li&gt;Choose &lt;strong&gt;Apply to › This website&lt;/strong&gt;, then change the theme. Your changes stay on that site only.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The &lt;strong&gt;Websites&lt;/strong&gt; screen in the app lists every website you&amp;rsquo;ve changed. Swipe left on one, or tap &lt;strong&gt;Edit&lt;/strong&gt;, to remove it.&lt;/p&gt;&#xA;&lt;h3 id=&#34;websites-that-already-have-a-dark-theme&#34;&gt;Websites That Already Have a Dark Theme&lt;/h3&gt;&#xA;&lt;p&gt;Dark Mode leaves websites that already have their own dark theme as they are. To use Dark Mode&amp;rsquo;s theme on one instead, open Safari&amp;rsquo;s Dark Mode menu on that site and turn it on.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;syncing-and-backups&#34;&gt;Syncing and Backups&lt;/h2&gt;&#xA;&lt;p&gt;The app and Safari&amp;rsquo;s Dark Mode menu share one set of settings: a change in either shows in the other.&lt;/p&gt;&#xA;&lt;p&gt;Turn on &lt;strong&gt;Sync with iCloud&lt;/strong&gt; in the app to use the same settings on every iPhone and iPad signed in to your Apple Account.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Backup &amp;amp; Restore&lt;/strong&gt; in the app exports your settings to a file and imports them again. Importing a backup replaces your current settings. &lt;strong&gt;Reset All Settings&lt;/strong&gt; puts everything back the way it was when you installed the app.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;troubleshooting&#34;&gt;Troubleshooting&lt;/h2&gt;&#xA;&lt;h3 id=&#34;websites-arent-turning-dark&#34;&gt;Websites Aren&amp;rsquo;t Turning Dark&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Check that Dark Mode is set to &lt;strong&gt;On&lt;/strong&gt;, or to &lt;strong&gt;Auto&lt;/strong&gt; during its scheduled hours.&lt;/li&gt;&#xA;&lt;li&gt;Check that the extension is turned on and allowed on &lt;strong&gt;All Websites&lt;/strong&gt; (see &lt;a href=&#34;https://yasoob.me/support/dark-mode/#getting-started&#34;&gt;Getting Started&lt;/a&gt;).&lt;/li&gt;&#xA;&lt;li&gt;Check that the website isn&amp;rsquo;t switched off in Safari&amp;rsquo;s Dark Mode menu.&lt;/li&gt;&#xA;&lt;li&gt;Reload the page.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;a-page-looks-wrong&#34;&gt;A Page Looks Wrong&lt;/h3&gt;&#xA;&lt;p&gt;Some pages draw in ways the default Dynamic mode can&amp;rsquo;t read. In Safari&amp;rsquo;s Dark Mode menu, choose &lt;strong&gt;Apply to › This website&lt;/strong&gt;, then set &lt;strong&gt;Mode&lt;/strong&gt; to &lt;strong&gt;Filter&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Fixes for many websites arrive with the site rules, which update by themselves about once a day. To check for new ones now, open Safari&amp;rsquo;s Dark Mode menu, then &lt;strong&gt;Settings › Site rules › Update now&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;dark-mode-isnt-in-safaris-menu&#34;&gt;Dark Mode Isn&amp;rsquo;t in Safari&amp;rsquo;s Menu&lt;/h3&gt;&#xA;&lt;p&gt;Turn the extension on in &lt;strong&gt;Settings › Apps › Safari › Extensions&lt;/strong&gt;. If it&amp;rsquo;s already on, turn it off and on again, then reload the page.&lt;/p&gt;&#xA;&lt;h3 id=&#34;my-settings-dont-match-on-my-other-device&#34;&gt;My Settings Don&amp;rsquo;t Match on My Other Device&lt;/h3&gt;&#xA;&lt;p&gt;Make sure &lt;strong&gt;Sync with iCloud&lt;/strong&gt; is on in the app on both devices, and that both are signed in to the same Apple Account. Changes can take a little while to arrive.&lt;/p&gt;&#xA;&lt;h3 id=&#34;sunset-to-sunrise-isnt-using-my-location&#34;&gt;Sunset to Sunrise Isn&amp;rsquo;t Using My Location&lt;/h3&gt;&#xA;&lt;p&gt;Dark Mode asks for location only once. If you chose not to allow it, sunset is estimated from your time zone. To allow it later, open &lt;strong&gt;Settings › Apps › Dark Mode › Location&lt;/strong&gt; and choose &lt;strong&gt;While Using the App&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;contact-support&#34;&gt;Contact Support&lt;/h2&gt;&#xA;&lt;p&gt;If you need more help, or you&amp;rsquo;ve found a website that still looks wrong, email:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Email:&lt;/strong&gt; &lt;a href=&#34;mailto:bugs@yasoob.me&#34;&gt;bugs@yasoob.me&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Please include the website&amp;rsquo;s address and a screenshot if you can.&lt;/p&gt;&#xA;&lt;p&gt;Thank you for using Dark Mode for Websites!&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Debugging ETW Event Drops in High-Throughput Applications</title>
				<link>https://yasoob.me/posts/recording-raw-etw-events/</link>
				<pubDate>Sat, 27 Dec 2025 13:44:17 -0800</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/recording-raw-etw-events/</guid>
				<category>debugging</category>
				<category>csharp</category>
				<description>We were losing millions of diagnostic events in production, but I couldn&amp;#39;t touch the active monitoring agent. How do you fix a system you can&amp;#39;t pause? In this post, I share a technique for running parallel ETW sessions to &amp;#34;spy&amp;#34; on your application&amp;#39;s telemetry and diagnose high-frequency event drops without breaking the existing pipeline.</description>
				<content:encoded>&lt;p&gt;I was working on a production application recently where we rely heavily on ETW (Event Tracing for Windows) to emit high-frequency events. We are talking about millions of events every few seconds. We started noticing gaps in our telemetry—we were running into event drops.&lt;/p&gt;&#xA;&lt;p&gt;This was a critical issue. If you are losing events, you are flying blind. I had to figure out which provider was producing the most events and where the bottleneck was. The challenge was that we already had an existing telemetry agent listening to these events, and I didn&amp;rsquo;t want to disrupt its operation.&lt;/p&gt;&#xA;&lt;p&gt;How do you debug a system that is already struggling under load without making it worse? It was hard to find a straightforward guide on &amp;ldquo;spying&amp;rdquo; on existing sessions without breaking them. Most of my research led me to generic documentation, so I decided to document the method I used to isolate the noisy provider and measure the drops.&lt;/p&gt;&#xA;&lt;p&gt;There were a few things I needed to figure out:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;How to identify the existing session and providers&lt;/li&gt;&#xA;&lt;li&gt;How to run a parallel &amp;ldquo;spy&amp;rdquo; session&lt;/li&gt;&#xA;&lt;li&gt;How to analyze the dropped event data&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Let’s go through them one by one.&lt;/p&gt;&#xA;&lt;h2 id=&#34;what-is-etw-anyway&#34;&gt;What is ETW anyway?&lt;/h2&gt;&#xA;&lt;p&gt;Before we fix it, let&amp;rsquo;s briefly touch on what ETW is for the uninitiated. If you have a few minutes, this video does a very good job of explaining what ETW is and how it works:&lt;/p&gt;&#xA;&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;&#xA;&#x9;&#x9;&#x9;&lt;iframe allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen&#34; loading=&#34;eager&#34; referrerpolicy=&#34;strict-origin-when-cross-origin&#34; src=&#34;https://www.youtube.com/embed/s213p-zB7G4?autoplay=0&amp;amp;controls=1&amp;amp;end=0&amp;amp;loop=0&amp;amp;mute=0&amp;amp;start=0&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; title=&#34;YouTube video&#34;&gt;&lt;/iframe&gt;&#xA;&#x9;&#x9;&lt;/div&gt;&#xA;&#xA;&lt;br /&gt;&#xA;&lt;p&gt;Here is a diagram from Microsoft&amp;rsquo;s blog that highlights the main components of ETW:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/etw/etw-architecture.png&#34; alt=&#34;High-level architecture of ETW (Source: Microsoft)&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;As illustrated in the diagram above, ETW relies on a few distinct components working in unison:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Controllers (Top Left):&lt;/strong&gt; These are tools like &lt;code&gt;logman&lt;/code&gt; or the &lt;code&gt;wpr&lt;/code&gt; command. They tell the system, &amp;ldquo;Hey, create &lt;strong&gt;Session 1&lt;/strong&gt; and start listening.&amp;rdquo;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Providers (Bottom Left):&lt;/strong&gt; This is your application code. It fires events into the void (&amp;ldquo;Something happened!&amp;rdquo;), usually without knowing who is listening.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;The Kernel Session (Green Box):&lt;/strong&gt; This is the critical piece for debugging drops. When a session is active, the Kernel allocates &lt;strong&gt;Buffers&lt;/strong&gt; (the blue file icons) in non-paged memory. This is where events sit before they are written to a file or read by a consumer.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Consumers (Bottom Right):&lt;/strong&gt; These are your monitoring agents. They request data from the buffers.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The problem of &amp;ldquo;Event Drops&amp;rdquo; is essentially a traffic jam in the green box. As shown in the diagram, data flows from &lt;strong&gt;Provider → Buffer → Consumer&lt;/strong&gt;. If your Provider fills those blue Buffers faster than the Consumer can empty them, the Kernel has no choice but to discard the newest events.&lt;/p&gt;&#xA;&lt;p&gt;It is designed to be incredibly fast, but physics still applies: if you pour water into a funnel faster than it drains, it spills.&lt;/p&gt;&#xA;&lt;h2 id=&#34;1-how-to-identify-the-existing-session-and-providers&#34;&gt;1. How to identify the existing session and providers&lt;/h2&gt;&#xA;&lt;p&gt;The first step was figuring out exactly what the existing monitoring agent was doing. I couldn&amp;rsquo;t just guess the Provider IDs. Windows has a built-in command-line tool called &lt;code&gt;logman&lt;/code&gt; that is perfect for this.&lt;/p&gt;&#xA;&lt;p&gt;I ran the following command to list all currently running event tracing sessions:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-powershell&#34; data-lang=&#34;powershell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;logman query -ets&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This produces an output similar to this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Data Collector Set                      Type                          Status&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;-------------------------------------------------------------------------------&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;EventLog-Application                    Trace                         Running&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;EventLog-System                         Trace                         Running&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;NtfsLog                                 Trace                         Running&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Circular Kernel Context Logger          Trace                         Running&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;MyDebugSession                          Trace                         Running&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This gave me a list of active sessions. I found the session corresponding to our telemetry agent (&lt;code&gt;MyDebugSession&lt;/code&gt; in the example above). By querying that specific session, I could see exactly which &lt;strong&gt;Providers&lt;/strong&gt; (by GUID or name) it was listening to.&lt;/p&gt;&#xA;&lt;p&gt;Run the following command to find all the provider GUIDs a session is listening to:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-powershell&#34; data-lang=&#34;powershell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;logman query &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;MyDebugSession&amp;#34;&lt;/span&gt; -ets&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This command will produce a verbose output, but look for the &lt;code&gt;Provider:&lt;/code&gt; sections:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Name:                 MyDebugSession&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Status:               Running&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;...&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Provider:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Name:                 {1AACEA33-2593-5BEE-5746-BCEDB745CD07}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Provider Guid:        {1AACEA33-2593-5BEE-5746-BCEDB745CD07}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;...&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Provider:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Name:                 {6A03660A-10F6-51E1-DAB5-343DA7A7680F}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Provider Guid:        {6A03660A-10F6-51E1-DAB5-343DA7A7680F}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;...&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Next, I grabbed all the provider GUIDs and put them in a &lt;code&gt;providers.txt&lt;/code&gt; file:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{1AACEA33-2593-5BEE-5746-BCEDB745CD07}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{6A03660A-10F6-51E1-DAB5-343DA7A7680F}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;{B39F4EF0-34CB-5F8E-578D-183AAEA6CB31}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;2-how-to-run-a-parallel-spy-session&#34;&gt;2. How to run a parallel spy session&lt;/h2&gt;&#xA;&lt;p&gt;Here is the tricky part. I couldn&amp;rsquo;t stop the existing agent to run my tests. I needed to run a &lt;strong&gt;parallel spy session&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;ETW allows multiple sessions to subscribe to the same provider. This means I could spin up a &lt;em&gt;new&lt;/em&gt; session, subscribe to the &lt;em&gt;same&lt;/em&gt; providers found in Step 1, and record the data to a file for analysis, all while the production agent kept running.&lt;/p&gt;&#xA;&lt;p&gt;I used &lt;code&gt;logman&lt;/code&gt; again to create this spy session:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-powershell&#34; data-lang=&#34;powershell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;logman create trace &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;SpySession&amp;#34;&lt;/span&gt; -pf &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;providers.txt&amp;#34;&lt;/span&gt; -o &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;C:\temp\spy_events.etl&amp;#34;&lt;/span&gt; -ets&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I let this run for a few seconds—just enough to capture the high-throughput burst—and then stopped it using this command:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-powershell&#34; data-lang=&#34;powershell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;logman stop &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;SpySession&amp;#34;&lt;/span&gt; -ets&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The resulting &lt;code&gt;spy_events.etl&lt;/code&gt; file turned out to be around 2GB while capturing events for only a few seconds. That was my first clue that the volume was massive.&lt;/p&gt;&#xA;&lt;h2 id=&#34;3-how-to-analyze-the-dropped-event-data&#34;&gt;3. How to analyze the dropped event data&lt;/h2&gt;&#xA;&lt;p&gt;Once I had the &lt;code&gt;.etl&lt;/code&gt; file (the standard format for ETW logs), I ran an analysis on it. You can use tools like &lt;strong&gt;Windows Performance Analyzer (WPA)&lt;/strong&gt; or &lt;code&gt;tracerpt&lt;/code&gt; to parse these files. I ended up using &lt;code&gt;tracerpt&lt;/code&gt; as it is available by default whereas WPA requires a separate install.&lt;/p&gt;&#xA;&lt;p&gt;You can run an analysis using this command:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-powershell&#34; data-lang=&#34;powershell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;tracerpt spy_events.etl -y -summary summary.txt&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The analysis provided exactly what I was looking for: a breakdown of event counts and, crucially, the &amp;ldquo;Total Events Lost&amp;rdquo; counter.&lt;/p&gt;&#xA;&lt;p&gt;Here is what the data looked like (truncated):&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Files Processed:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    spy_events.etl&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Total Buffers Processed 248423&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Total Events  Processed 6110264&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Total Events  Lost      5580908&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Start Time              Tuesday, December 23, 2025&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;...&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;+---------------------------------------------------------------------------------------------------------+&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|Event Count   Event Name           Event ID        Version         Guid                                  |&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;+---------------------------------------------------------------------------------------------------------+&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|          2   EventTrace           0               2               {68fdd900-4a3e-11d1-84f4-0000f80464e3}|&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|     143003                        1               5               {c4859ff3-8549-54e3-adc3-dfcb805b4146}|&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|      63916                        6               2               {c4859ff3-8549-54e3-adc3-dfcb805b4146}|&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|    1040793                        9               2               {c4859ff3-8549-54e3-adc3-dfcb805b4146}|&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;|    1308511                        11              2               {c4859ff3-8549-54e3-adc3-dfcb805b4146}|&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;| ...&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;+---------------------------------------------------------------------------------------------------------+&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It was immediately obvious. &lt;strong&gt;Event ID 9&lt;/strong&gt; and &lt;strong&gt;11&lt;/strong&gt; were spamming the system with over a million events each in that short window. The kernel buffers simply couldn&amp;rsquo;t keep up, resulting in over 5 million &amp;ldquo;Total Events Lost.&amp;rdquo;&lt;/p&gt;&#xA;&lt;p&gt;These Event IDs are specified in the code while creating a new ETW event, so a simple GREP took me straight to the source. The fix was clear: I had to either throttle the events, batch multiple events into one, or reduce the collection verbosity level in our monitoring agent so that we don&amp;rsquo;t listen to all events in production.&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;I had fun digging into the lower levels of Windows tracing and figuring out that you can essentially &amp;ldquo;wiretap&amp;rdquo; your own applications without bringing them down. Debugging high-frequency systems can feel like trying to fix a jet engine while flying, but with tools like &lt;code&gt;logman&lt;/code&gt; and the ability to run parallel ETW sessions, you can peek under the hood safely.&lt;/p&gt;&#xA;&lt;p&gt;I am pretty sure there are more advanced ways to do this with WPA (Windows Performance Analyzer), but for a quick diagnosis on a production machine where you can&amp;rsquo;t install new tools, &lt;code&gt;logman&lt;/code&gt; and &lt;code&gt;tracerpt&lt;/code&gt; are perfect solutions.&lt;/p&gt;&#xA;&lt;p&gt;If you are dealing with mysterious data gaps in Windows, I highly recommend getting comfortable with &lt;code&gt;logman&lt;/code&gt;. It might save you days of guessing.&lt;/p&gt;&#xA;&lt;p&gt;I hope this article helps those who are trying to debug similar high-throughput issues! 😄&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Converting Sourcemaps to Original JavaScript/TypeScript Sourcecode</title>
				<link>https://yasoob.me/posts/converting-sourcemap-to-original-sourcecode/</link>
				<pubDate>Sun, 22 Jun 2025 05:54:24 -0700</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/converting-sourcemap-to-original-sourcecode/</guid>
				<category>reverse engineering</category>
				<category>javascript</category>
				<description>In this tutorial, you will learn how to convert the sourcemap files to original JavaScript/TypeScript sourcecode using open source tools. You will use mitmproxy and Sourcemapper to achieve this goal.</description>
				<content:encoded>&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;&#xA;&lt;p&gt;Hi everyone! This is going to be a short and quick tutorial on how to download sourcemap files and convert them into the original JavaScript source code. Here’s an example of minified code from a Next.js website:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/sourcemaps/minified-code.png&#34; alt=&#34;Minified code&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;And here is the same code after the browser has done its magic and reconstructed the original code using sourcemaps:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/sourcemaps/original-code.png&#34; alt=&#34;Original code&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Take a look at the bottom toolbar — it shows whether the displayed code is a bundled file or the original source file.&lt;/p&gt;&#xA;&lt;p&gt;Our goal is to download this original file to our local system. Currently, you can view the original code in browsers for websites that publicly publish their sourcemaps, but browsers don’t let you download the original code in bulk. This means you can individually download each file from the developer tools, but you can’t download an entire directory at once. This is a problem because websites usually contain hundreds (if not thousands) of source files.&lt;/p&gt;&#xA;&lt;p&gt;I’m not aware of any way to do this using browser extensions. There is one prominent Chrome extension that mostly works: &lt;a href=&#34;https://github.com/up209d/ResourcesSaverExt&#34;&gt;ResourcesSaverExt&lt;/a&gt;, but it’s currently experiencing issues with Webpack. My understanding is that this is a Google Chrome limitation, as described in &lt;a href=&#34;https://github.com/up209d/ResourcesSaverExt/issues/72&#34;&gt;this issue&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Instead, we’ll use &lt;a href=&#34;https://mitmproxy.org/&#34;&gt;Mitmproxy&lt;/a&gt; to intercept all web requests and log the sourcemap URLs, and then use &lt;a href=&#34;https://github.com/denandz/sourcemapper&#34;&gt;Sourcemapper&lt;/a&gt; to download and reconstruct the original code using those sourcemaps.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;step-1-install-and-run-mitmproxy&#34;&gt;Step 1: Install and Run Mitmproxy&lt;/h2&gt;&#xA;&lt;p&gt;Mitmproxy is a free and open-source proxy that you can use to route all your network requests through. It’s extremely powerful and provides a very flexible scripting environment. You can follow the instructions on the &lt;a href=&#34;https://mitmproxy.org/&#34;&gt;official website&lt;/a&gt; to install it.&lt;/p&gt;&#xA;&lt;p&gt;Once installation is complete, run the proxy from your terminal and set your system proxy to route all requests through it. After that, open any website in your browser. You should see all the requests being logged in the terminal:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/sourcemaps/mitmproxy-working.png&#34; alt=&#34;Mitmproxy working&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Perfect! Now clear the list of flows by pressing &lt;code&gt;z&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;step-2-open-the-target-website&#34;&gt;Step 2: Open the Target Website&lt;/h2&gt;&#xA;&lt;p&gt;Next, open the target website in your browser. This won’t automatically trigger the loading of sourcemap files. You need to open the developer tools and go to the &lt;code&gt;Sources&lt;/code&gt; tab in Chrome or the &lt;code&gt;Debugger&lt;/code&gt; tab in Firefox. Once you do that, you’ll see a bunch of new requests in Mitmproxy ending with &lt;code&gt;.js.map&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/sourcemaps/mitmproxy-sourcemaps.png&#34; alt=&#34;Mitmproxy sourcemaps&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;At this point, press &lt;code&gt;w&lt;/code&gt; in Mitmproxy and enter a name for the dump file where these intercepted flows will be stored. I’ll assume you named it &lt;code&gt;dump&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;step-3-extract-sourcemap-urls&#34;&gt;Step 3: Extract Sourcemap URLs&lt;/h2&gt;&#xA;&lt;p&gt;Create a &lt;code&gt;script.py&lt;/code&gt; file containing a bit of code to filter the dump file you just created. In my case, this is what it looked like:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;request&lt;/span&gt;(flow):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;targetdomain&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; flow&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;request&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;url &lt;span style=&#34;color:#f92672&#34;&gt;and&lt;/span&gt; flow&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;request&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;url&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;endswith(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;.map&amp;#34;&lt;/span&gt;):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        print(flow&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;request&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;url)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Replace &lt;code&gt;&amp;quot;targetdomain&amp;quot;&lt;/code&gt; with the domain you&amp;rsquo;re targeting. This filters out any intercepted requests from other domains you&amp;rsquo;re not interested in. We’re also filtering for &lt;code&gt;.map&lt;/code&gt; since sourcemap files always end with that extension.&lt;/p&gt;&#xA;&lt;p&gt;Now, run this command to process the dump file using your script:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mitmdump -q -s script.py -r dump&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will print each sourcemap URL on a new line in the terminal, like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;https://example.com/a.js.map  &#xA;https://example.com/b.js.map&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;hr&gt;&#xA;&lt;h2 id=&#34;step-4-pipe-sourcemap-urls-to-sourcemapper&#34;&gt;Step 4: Pipe Sourcemap URLs to Sourcemapper&lt;/h2&gt;&#xA;&lt;p&gt;This is the final step. You’ll now pipe these URLs into Sourcemapper. This tool downloads each sourcemap and reconstructs the original source code. A typical Sourcemapper command looks like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;sourcemapper -output outputdirectory -url https://sampleurl.com&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Instead of running this manually for each URL, you can use:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;mitmdump -q -s script.py -r dump | xargs -n &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt; sourcemapper -output output -url&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Once the command finishes, the original source code will be saved in the &lt;code&gt;output&lt;/code&gt; directory.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;issues-with-sourcemapper&#34;&gt;Issues with Sourcemapper&lt;/h2&gt;&#xA;&lt;p&gt;I did run into a few issues with Sourcemapper. For instance, the file structure it produces doesn’t exactly match what you see in the browser. All the files are recreated, but the nesting might be off. This was acceptable in my case, but you may want to investigate further depending on your use case.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;I’m glad I can view the original JS/TS code of most websites. However, if you want to keep your code private, make sure you’re not publicly publishing your sourcemaps. Almost all major build tools support removing sourcemaps from public directories.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;P.S.&lt;/strong&gt;: At one point, I considered patching Firefox’s source code to dump all the generated sourcemaps to the local file system. That’s probably the best way to get the most accurate source code. However, Firefox&amp;rsquo;s build process is slow, and the method I’ve shared here worked well enough for my needs.&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Salam - Privacy Policy</title>
				<link>https://yasoob.me/privacy/salam/</link>
				<pubDate>Sun, 09 Mar 2025 00:50:04 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/privacy/salam/</guid>
				<description>Effective Date: March 9, 2025 Salam (“we”, “our”, or “the app”) values your privacy and is committed to protecting your personal information. This Privacy Policy explains how we collect, use, and share information when you use the Salam app. By using the app, you agree to the collection and use of information as described in this policy. 1. Data Collection No Personal Data Collected: Salam does not collect, store, or share any personal information about you. We do not request any personal details such as your name, email address, or location for any purpose.</description>
				<content:encoded>&lt;p&gt;Effective Date: March 9, 2025&lt;/p&gt;&#xA;&lt;p&gt;Salam (&amp;ldquo;we&amp;rdquo;, &amp;ldquo;our&amp;rdquo;, or &amp;ldquo;the app&amp;rdquo;) values your privacy and is committed to protecting your personal information. This Privacy Policy explains how we collect, use, and share information when you use the Salam app. By using the app, you agree to the collection and use of information as described in this policy.&lt;/p&gt;&#xA;&lt;h2 id=&#34;1-data-collection&#34;&gt;1. Data Collection&lt;/h2&gt;&#xA;&lt;p&gt;&lt;strong&gt;No Personal Data Collected:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Salam does not collect, store, or share any personal information about you. We do not request any personal details such as your name, email address, or location for any purpose.&lt;/p&gt;&#xA;&lt;h2 id=&#34;2-third-party-services&#34;&gt;2. Third-Party Services&lt;/h2&gt;&#xA;&lt;p&gt;While we do not collect personal data, the app integrates with third-party services for certain features:&lt;/p&gt;&#xA;&lt;h3 id=&#34;21-aladhan-api&#34;&gt;2.1 Aladhan API&lt;/h3&gt;&#xA;&lt;p&gt;Salam uses the &lt;strong&gt;Aladhan API&lt;/strong&gt; for prayer time calculation based on your location. The Aladhan API provides accurate prayer times for various locations worldwide. For more information about Aladhan’s privacy practices, you can visit their website at &lt;a href=&#34;https://aladhan.com/credits-and-terms&#34;&gt;https://aladhan.com/credits-and-terms&lt;/a&gt;. The Aladhan API may collect and store location data as part of its service.&lt;/p&gt;&#xA;&lt;h3 id=&#34;22-quran-cloud&#34;&gt;2.2 Quran Cloud&lt;/h3&gt;&#xA;&lt;p&gt;Salam uses &lt;strong&gt;&lt;a href=&#34;https://alquran.cloud/&#34;&gt;https://alquran.cloud/&lt;/a&gt;&lt;/strong&gt; for Quranic audio playback and translation. This service allows us to provide high-quality recitations and translations of the Quran. For information on how Alquran Cloud handles user data, please refer to their terms and conditions at &lt;a href=&#34;https://alquran.cloud/terms-and-conditions&#34;&gt;https://alquran.cloud/terms-and-conditions&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Please note that &lt;strong&gt;Alquran Cloud&lt;/strong&gt; may collect and store information related to audio playback and translations, such as IP addresses or usage statistics, as part of their service.&lt;/p&gt;&#xA;&lt;h2 id=&#34;3-data-security&#34;&gt;3. Data Security&lt;/h2&gt;&#xA;&lt;p&gt;Salam does not collect or store any personal information, so there are no security risks associated with personal data within the app. However, the third-party services we use (Aladhan API and Alquran Cloud) may store certain data in accordance with their own privacy policies and data protection practices.&lt;/p&gt;&#xA;&lt;h2 id=&#34;4-your-rights&#34;&gt;4. Your Rights&lt;/h2&gt;&#xA;&lt;p&gt;Since Salam does not collect personal data, there are no specific rights for you to exercise in relation to the data we collect. However, for any concerns about the data collection practices of the third-party services we use, you can contact them directly through their provided privacy policies.&lt;/p&gt;&#xA;&lt;h2 id=&#34;5-changes-to-this-privacy-policy&#34;&gt;5. Changes to This Privacy Policy&lt;/h2&gt;&#xA;&lt;p&gt;We may update this Privacy Policy from time to time to reflect changes in the app or third-party services. We will notify users of any significant changes by updating the effective date at the top of this page. Please review this policy periodically to stay informed about how your data is protected.&lt;/p&gt;&#xA;&lt;h2 id=&#34;6-contact-us&#34;&gt;6. Contact Us&lt;/h2&gt;&#xA;&lt;p&gt;If you have any questions about this Privacy Policy or need further information, feel free to contact us at:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Email:&lt;/strong&gt; &lt;a href=&#34;mailto:hi@yasoob.me&#34;&gt;hi@yasoob.me&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Thank you for using Salam – your trusted companion for prayer times, Quran recitation, and more. Your privacy is important to us, and we strive to provide a secure and transparent experience.&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Salam - Support Page</title>
				<link>https://yasoob.me/support/salam/</link>
				<pubDate>Sun, 09 Mar 2025 00:50:04 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/support/salam/</guid>
				<description>Welcome to the Salam app support page! Below you’ll find detailed information about how to get the most out of the Salam app and troubleshoot any issues you may encounter. If you need further assistance, don’t hesitate to reach out to our support team. Table of Contents Getting Started Prayer Times Widgets Qibla Direction Finder Quran Reading Audio Recitations Asma-ul-Husna Notifications Troubleshooting Contact Support Getting Started How to Set Up Salam Download the app from the App Store. Launch the app and grant location access for accurate prayer times based on your location. Configure the app by adjusting settings such as prayer time calculation method, location, and other preferences from the settings menu (gear icon). Prayer Times How are Prayer Times Calculated? Salam uses the Aladhan API to provide accurate prayer times based on your location. The app automatically detects your current location and retrieves the prayer schedule accordingly. You can also manually adjust prayer times to match your local mosque.</description>
				<content:encoded>&lt;p&gt;Welcome to the Salam app support page! Below you&amp;rsquo;ll find detailed information about how to get the most out of the Salam app and troubleshoot any issues you may encounter. If you need further assistance, don&amp;rsquo;t hesitate to reach out to our support team.&lt;/p&gt;&#xA;&lt;h2 id=&#34;table-of-contents&#34;&gt;Table of Contents&lt;/h2&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/salam/#getting-started&#34;&gt;Getting Started&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/salam/#prayer-times&#34;&gt;Prayer Times&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/salam/#widgets&#34;&gt;Widgets&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/salam/#qibla-direction-finder&#34;&gt;Qibla Direction Finder&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/salam/#quran-reading&#34;&gt;Quran Reading&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/salam/#audio-recitations&#34;&gt;Audio Recitations&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/salam/#asma-ul-husna&#34;&gt;Asma-ul-Husna&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/salam/#notifications&#34;&gt;Notifications&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/salam/#troubleshooting&#34;&gt;Troubleshooting&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://yasoob.me/support/salam/#contact-support&#34;&gt;Contact Support&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;getting-started&#34;&gt;Getting Started&lt;/h2&gt;&#xA;&lt;h3 id=&#34;how-to-set-up-salam&#34;&gt;How to Set Up Salam&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Download the app&lt;/strong&gt; from the App Store.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Launch the app&lt;/strong&gt; and grant location access for accurate prayer times based on your location.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Configure the app&lt;/strong&gt; by adjusting settings such as prayer time calculation method, location, and other preferences from the settings menu (gear icon).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;prayer-times&#34;&gt;Prayer Times&lt;/h2&gt;&#xA;&lt;h3 id=&#34;how-are-prayer-times-calculated&#34;&gt;How are Prayer Times Calculated?&lt;/h3&gt;&#xA;&lt;p&gt;Salam uses the &lt;strong&gt;Aladhan API&lt;/strong&gt; to provide accurate prayer times based on your location. The app automatically detects your current location and retrieves the prayer schedule accordingly. You can also manually adjust prayer times to match your local mosque.&lt;/p&gt;&#xA;&lt;h3 id=&#34;how-to-adjust-prayer-times-manually&#34;&gt;How to Adjust Prayer Times Manually&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Go to the &lt;strong&gt;Settings&lt;/strong&gt; by tapping the gear icon.&lt;/li&gt;&#xA;&lt;li&gt;Under &lt;strong&gt;Prayer Times&lt;/strong&gt;, click on the &lt;strong&gt;Manual Adjustments&lt;/strong&gt; link.&lt;/li&gt;&#xA;&lt;li&gt;Adjust each prayer time using the +/- buttons or manual entry to match your local mosque timings.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;changing-the-location&#34;&gt;Changing the Location&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Go to the &lt;strong&gt;Settings&lt;/strong&gt; by tapping the gear icon.&lt;/li&gt;&#xA;&lt;li&gt;Check/Uncheck the &lt;strong&gt;Automatic Location&lt;/strong&gt; toggle&lt;/li&gt;&#xA;&lt;li&gt;If you prefer manual location selection, tap the &lt;strong&gt;Location&lt;/strong&gt; name to choose a city.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;widgets&#34;&gt;Widgets&lt;/h2&gt;&#xA;&lt;h3 id=&#34;adding-prayer-time-widgets-to-your-home-screen&#34;&gt;Adding Prayer Time Widgets to Your Home Screen&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Press and hold an empty space on your iPhone&amp;rsquo;s home screen.&lt;/li&gt;&#xA;&lt;li&gt;Tap the &lt;strong&gt;+&lt;/strong&gt; icon in the top-left corner.&lt;/li&gt;&#xA;&lt;li&gt;Search for &lt;strong&gt;Salam&lt;/strong&gt; and select the prayer time widget.&lt;/li&gt;&#xA;&lt;li&gt;Choose your preferred widget size and tap &lt;strong&gt;Add Widget&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The widget will display real-time prayer times on your home screen.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;qibla-direction-finder&#34;&gt;Qibla Direction Finder&lt;/h2&gt;&#xA;&lt;h3 id=&#34;using-the-qibla-compass&#34;&gt;Using the Qibla Compass&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Open the &lt;strong&gt;Qibla Finder&lt;/strong&gt; from the app&amp;rsquo;s main screen.&lt;/li&gt;&#xA;&lt;li&gt;Allow the app to access your device&amp;rsquo;s compass and location.&lt;/li&gt;&#xA;&lt;li&gt;The app will show you the direction of the Kaaba. Rotate your phone until the arrow aligns with the direction of Qibla.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;quran-reading&#34;&gt;Quran Reading&lt;/h2&gt;&#xA;&lt;h3 id=&#34;reading-the-quran&#34;&gt;Reading the Quran&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Open the &lt;strong&gt;Quran&lt;/strong&gt; section from the main screen.&lt;/li&gt;&#xA;&lt;li&gt;Open whichever Surah you want and touch the gear icon to adjust settings.&lt;/li&gt;&#xA;&lt;li&gt;Choose between &lt;strong&gt;Uthmani&lt;/strong&gt; or &lt;strong&gt;IndoPak&lt;/strong&gt; font styles.&lt;/li&gt;&#xA;&lt;li&gt;Select your preferred translation from the available list.&lt;/li&gt;&#xA;&lt;li&gt;Adjust the font size and spacing to your preference for a comfortable reading experience.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;navigating-through-the-quran&#34;&gt;Navigating Through the Quran&lt;/h3&gt;&#xA;&lt;p&gt;Swipe left or right to move between surahs.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;audio-recitations&#34;&gt;Audio Recitations&lt;/h2&gt;&#xA;&lt;h3 id=&#34;listening-to-quranic-recitations&#34;&gt;Listening to Quranic Recitations&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;In the Quran reading screen, tap the &lt;strong&gt;Play Button&lt;/strong&gt; next to the verse to hear the recitation.&lt;/li&gt;&#xA;&lt;li&gt;By default the recitation will stop at the end of the surah.&lt;/li&gt;&#xA;&lt;li&gt;You can choose your preferred Qari by tapping on the Qari name in the bottom tabbar&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;asma-ul-husna&#34;&gt;Asma-ul-Husna&lt;/h2&gt;&#xA;&lt;h3 id=&#34;listening-to-the-99-names-of-allah&#34;&gt;Listening to the 99 Names of Allah&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Go to the &lt;strong&gt;Asma-ul-Husna&lt;/strong&gt; section in the app.&lt;/li&gt;&#xA;&lt;li&gt;Tap &lt;strong&gt;Play&lt;/strong&gt; to listen to the beautiful names of Allah with high-quality audio that auto sync the display to the current name being played.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;notifications&#34;&gt;Notifications&lt;/h2&gt;&#xA;&lt;h3 id=&#34;enabling-prayer-time-notifications&#34;&gt;Enabling Prayer Time Notifications&lt;/h3&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Each prayer time row in the main screen has a &lt;strong&gt;Bell Icon&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Tap the bell to toggle notifications for a specific prayer on or off. When notifications are enabled, the bell will appear filled; when disabled, it will be grayed out.&lt;/li&gt;&#xA;&lt;li&gt;You will receive notifications at the start of each prayer time.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;customizing-notification-preferences&#34;&gt;Customizing Notification Preferences&lt;/h3&gt;&#xA;&lt;p&gt;Notification preferences for each prayer can be toggled individually, and are stored locally. You can adjust these preferences through the bell icons in the prayer list.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;troubleshooting&#34;&gt;Troubleshooting&lt;/h2&gt;&#xA;&lt;h3 id=&#34;the-app-is-not-detecting-my-location&#34;&gt;The App Is Not Detecting My Location&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Ensure that &lt;strong&gt;Location Services&lt;/strong&gt; are enabled on your device.&lt;/li&gt;&#xA;&lt;li&gt;Go to &lt;strong&gt;Settings &amp;gt; Privacy &amp;gt; Location Services&lt;/strong&gt;, and ensure that &lt;strong&gt;Salam&lt;/strong&gt; has permission to access your location.&lt;/li&gt;&#xA;&lt;li&gt;If you&amp;rsquo;re indoors, try moving to an open area to improve GPS accuracy.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;prayer-times-are-incorrect&#34;&gt;Prayer Times Are Incorrect&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Check your location settings. If you&amp;rsquo;re in a new location, make sure &lt;strong&gt;Auto Location&lt;/strong&gt; is enabled or manually select the correct city.&lt;/li&gt;&#xA;&lt;li&gt;Verify your &lt;strong&gt;Prayer Time Calculation Method&lt;/strong&gt; under the settings to ensure it matches the method used by your local mosque.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;the-app-is-crashing-or-freezing&#34;&gt;The App Is Crashing or Freezing&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Ensure your app is up-to-date by checking the App Store for the latest version.&lt;/li&gt;&#xA;&lt;li&gt;Restart the app and try again.&lt;/li&gt;&#xA;&lt;li&gt;If the issue persists, try reinstalling the app.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;im-not-receiving-notifications&#34;&gt;I’m Not Receiving Notifications&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Ensure that &lt;strong&gt;Notification Permissions&lt;/strong&gt; are enabled for Salam in &lt;strong&gt;Settings &amp;gt; Notifications &amp;gt; Salam&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Verify that you&amp;rsquo;ve enabled notifications for each prayer in the app by tapping the bell icon.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr&gt;&#xA;&lt;h2 id=&#34;contact-support&#34;&gt;Contact Support&lt;/h2&gt;&#xA;&lt;p&gt;If you need further assistance, feel free to reach out to our support team:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Email:&lt;/strong&gt; &lt;a href=&#34;mailto:hi@yasoob.me&#34;&gt;hi@yasoob.me&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;We&amp;rsquo;re here to assist you and ensure you have the best experience with Salam!&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;Thank you for using Salam – your trusted companion for prayer times, Quran recitation, and more! May your spiritual journey be enriched.&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Breaking Kakasoft USB Copy Protection</title>
				<link>https://yasoob.me/posts/breaking-kakasoft-usb-copy-protection/</link>
				<pubDate>Mon, 05 Aug 2024 15:37:31 -0700</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/breaking-kakasoft-usb-copy-protection/</guid>
				<category>hacking</category>
				<category>security</category>
				<description>I stumbled upon a USB drive locked down with Kakasoft&amp;#39;s USB Copy Protection software. Challenge accepted! I decided to crack this DRM protection wide open. In this article, I&amp;#39;ll take you through every step of the process, sharing my strategies and thought process so you can break free from such flimsy defenses too.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/breaking-kakasoft-protection/header.png&#34; alt=&#34;Breaking Kakasoft USB Copy Protection&#34;&gt;&lt;/p&gt;&lt;p&gt;I recently got my hands on a USB drive with Kakasoft USB Copy Protection (DRM protection). This software promises to let you share data without the fear of it being copied by the end user. However, the pseudo-hacker in me couldn’t resist the challenge. After all, &amp;ldquo;If it can be read, it can be copied.&amp;rdquo; In this article, I’ll walk you through the entire process I used to crack this protection, sharing my thought process and detailed steps along the way. Don’t worry—I’ve pixelated any sensitive information, but you’ll still get a clear picture of how to bypass such weak defenses.&lt;/p&gt;&#xA;&lt;h2 id=&#34;how-the-copy-protection-works&#34;&gt;How the Copy Protection Works&lt;/h2&gt;&#xA;&lt;p&gt;Kakasoft’s method involves placing an executable file on the USB that acts as a virtual file explorer, disabling the usual copy/paste operations. You can open files from this explorer, but you can’t move them outside of the USB. Here’s a peek at the UI:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/breaking-kakasoft-protection/virtual-browser.png&#34; alt=&#34;Virtual browser&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;As you can see, the copy icon is grayed out, and right-clicking on any file or directory won’t help either—the copy option is disabled.&lt;/p&gt;&#xA;&lt;h2 id=&#34;initial-attempts-to-break-the-protection&#34;&gt;Initial Attempts to Break the Protection&lt;/h2&gt;&#xA;&lt;p&gt;I had a few theories on how this software might work, and I set out to test each one.&lt;/p&gt;&#xA;&lt;h3 id=&#34;hidden-directories&#34;&gt;Hidden Directories&lt;/h3&gt;&#xA;&lt;p&gt;First, I thought the data might be in a hidden directory on the USB, displayed by the virtual explorer. While the USB did have hidden directories, none contained meaningful data.&lt;/p&gt;&#xA;&lt;h3 id=&#34;self-extracting-archive&#34;&gt;Self-Extracting Archive&lt;/h3&gt;&#xA;&lt;p&gt;Next, I wondered if the exe was a self-extracting archive. I tried using 7-zip to extract it, but it was no use—7-zip reported a broken archive.&lt;/p&gt;&#xA;&lt;h3 id=&#34;online-search&#34;&gt;Online Search&lt;/h3&gt;&#xA;&lt;p&gt;Turning to the internet, I searched for ideas using the hidden directory name, &lt;code&gt;HPSafeBox&lt;/code&gt;. This led me to a &lt;a href=&#34;https://www.reddit.com/r/Xenoblade_Chronicles/comments/3vikin/warning_the_xenoblade_chronicles_x_ost_has_a/&#34;&gt;Reddit post&lt;/a&gt; discussing the same copy protection. The post suggested that data was stored in the HPSafeBox directory or a hidden &lt;code&gt;Y&lt;/code&gt; drive. Checking and modifying local registry settings didn’t help.&lt;/p&gt;&#xA;&lt;h3 id=&#34;partition-editor&#34;&gt;Partition Editor&lt;/h3&gt;&#xA;&lt;p&gt;I ran various offline tools, including a partition editor, hoping to uncover hidden drives. &lt;a href=&#34;https://www.jam-software.com/treesize_free&#34;&gt;TreeSize&lt;/a&gt; only showed the &lt;code&gt;C&lt;/code&gt; drive and the USB&amp;rsquo;s &lt;code&gt;F&lt;/code&gt; drive:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/breaking-kakasoft-protection/treesize-ui.png&#34; alt=&#34;TreeSize UI&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;I used TreeSize as someone was able to uncover the hidden drive using it in a YouTube video&lt;/em&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;finding-the-exe-location&#34;&gt;Finding the exe Location&lt;/h2&gt;&#xA;&lt;p&gt;In my case, the USB came with an executable software hidden behind the virtual file browser. I decided to try and trace where the executable might be running from, hoping that it might give me some clues about the hidden data&amp;rsquo;s location. My thought process was that if the exe file is able to run on the system then it must be stored in an accessible location. I tried using Task Manager to figure out the file location but clicking on &amp;ldquo;Open file location&amp;rdquo; did nothing:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/breaking-kakasoft-protection/task-manager.png&#34; alt=&#34;Task Manager&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Next, I used a very old tool called &lt;a href=&#34;http://www.rohitab.com/apimonitor&#34;&gt;&lt;code&gt;Api Monitor&lt;/code&gt;&lt;/a&gt;. It allows you to monitor a program and shows which DLL calls that program is making. This gave me my next clue—the path of the executable running from the F drive, but with a command line reference to a hidden Z drive:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/breaking-kakasoft-protection/api-monitor.png&#34; alt=&#34;API Monitor&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Accessing the &lt;code&gt;F&lt;/code&gt; drive path was blocked:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/breaking-kakasoft-protection/explorer-error.png&#34; alt=&#34;Explorer Error&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;And the &lt;code&gt;Z&lt;/code&gt; drive also returned an error:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/breaking-kakasoft-protection/explorer-error-2.png&#34; alt=&#34;Explorer error&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;h2 id=&#34;disabling-group-policy-changes&#34;&gt;Disabling Group Policy Changes&lt;/h2&gt;&#xA;&lt;p&gt;The &lt;code&gt;Z&lt;/code&gt; drive error intrigued me. I was accessing this drive on my personal computer and I don&amp;rsquo;t remember putting any restrictions in place. &lt;a href=&#34;https://superuser.com/questions/1184157/windows-this-operation-has-been-cancelled-due-to-restrictions-in-effect-on-thi&#34;&gt;This SuperUser post&lt;/a&gt; mentioned some Group Policy changes to disable this restriction. I went ahead and disabled the &amp;ldquo;Prevent access to drives from My Computer&amp;rdquo; setting:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/breaking-kakasoft-protection/policy-editor.png&#34; alt=&#34;Group Policy Editor&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;With this restriction lifted, I accessed the Z drive, uncovering the &lt;code&gt;NLLastF&lt;/code&gt; directory containing all the files I needed:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/breaking-kakasoft-protection/file-browser.png&#34; alt=&#34;File Browser&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Let this be a reminder: if something is accessible offline, it’s only a matter of time before the security measures or DRM protections are bypassed.&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Running Go code from Elixir Using Web Assembly</title>
				<link>https://yasoob.me/posts/running-go-web-assembly-from-elixir/</link>
				<pubDate>Fri, 23 Feb 2024 00:39:55 -0800</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/running-go-web-assembly-from-elixir/</guid>
				<category>elixir</category>
				<category>programming</category>
				<description>In this article, I will show you how to compile Go code to target WASI and run it from an Elixir host. You will also learn how to pass data to Go and get a response back using pipes.</description>
				<content:encoded>&lt;p&gt;I was working on an Elixir project recently and one particular open source package that I wanted to make use of was written in Go. I searched for different ways to interface with Go code from Elixir. I know that it is fairly trivial to interface Rust code from Elixir using a NIF but there isn&amp;rsquo;t anything similar for Go that I came across. Most of my research led me towards using Ports and I was about to give in before realizing that WASI (WebAssembly System Interface) is also an option. I had been hearing about Web Assembly for a while now and this was as good of a moment as any to give it a try. I also came across &lt;a href=&#34;https://github.com/tessi/wasmex&#34;&gt;Wasmex&lt;/a&gt; which seemed like a good option to run WASI binaries in Elixir. &lt;a href=&#34;https://github.com/tessi&#34;&gt;Philipp Tessenow&lt;/a&gt; (creator of wasmex) was instrumental in getting this whole thing to work and guiding me to the final working solution so thanks tessi!&lt;/p&gt;&#xA;&lt;p&gt;There were a few things I needed to figure out:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;How to compile Go code to WASI&lt;/li&gt;&#xA;&lt;li&gt;How to run a WASI binary in an Elixir host&lt;/li&gt;&#xA;&lt;li&gt;How to pass data into the WASI binary&lt;/li&gt;&#xA;&lt;li&gt;How to get data out of the WASI binary&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s go through them one by one.&lt;/p&gt;&#xA;&lt;h2 id=&#34;1-how-to-compile-go-code-to-wasi&#34;&gt;1. How to compile Go code to WASI&lt;/h2&gt;&#xA;&lt;p&gt;This one was easy. Some quick Google-fu informed me that I need to use &lt;code&gt;tinygo&lt;/code&gt; as it supports WASI as an output target. The main Go compiler also added WASM support but as far as I know, it doesn&amp;rsquo;t currently compile to the WASI target.&lt;/p&gt;&#xA;&lt;p&gt;This is the sample Go code that I used for testing this whole setup:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;package main&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;import &amp;#34;fmt&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;func main() {}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;//export greet&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;func greet() {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  fmt.Println(&amp;#34;Hello world&amp;#34;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And I used the following command to compile the code to WASI:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ tinygo build -o main.wasm -scheduler&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;none --no-debug -target wasi main.go&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Tinygo uses comments to guide the compiler regarding which functions need to be exported to a WASI host. One such comment is &lt;code&gt;// export greet&lt;/code&gt; in the code above. This will export the &lt;code&gt;greet&lt;/code&gt; function and we can call it from the WASI host (Elixir/Wasmex). There are also some annotations you can add to tell tinygo to import a function from the WASI host but I am not going to be using that here. We also need to add an empty &lt;code&gt;main&lt;/code&gt; function for the code to work.&lt;/p&gt;&#xA;&lt;p&gt;You can play around with the &lt;code&gt;tinygo&lt;/code&gt; flags in the &lt;code&gt;build&lt;/code&gt; command I shared above. I found this combination of flags to generate the smallest WASI/WASM binary.&lt;/p&gt;&#xA;&lt;h2 id=&#34;2-how-to-run-a-wasi-binary-in-an-elixir-host&#34;&gt;2. How to run a WASI binary in an Elixir host&lt;/h2&gt;&#xA;&lt;p&gt;This one was also fairly easy to figure out. Once you have &lt;code&gt;wasmex&lt;/code&gt; installed as a mix dependency, you can run a WASI binary like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;binary = File.read!(&amp;#34;./native/main.wasm&amp;#34;)&#xA;{:ok, pid} = Wasmex.start_link(%{bytes: binary, wasi: true}) &#xA;Wasmex.call_function(pid, &amp;#34;greet&amp;#34;, [])&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;3-how-to-pass-data-into-the-wasi-binary&#34;&gt;3. How to pass data into the WASI binary&lt;/h2&gt;&#xA;&lt;p&gt;Now I had to figure out how to pass data into the WASI binary. This one was a bit tricky as there are a couple of ways to go about this. The two most famous ones are passing data in via &lt;code&gt;stdin&lt;/code&gt; or copying data to some shared WASI memory. You can also parametrize your functions and take direct arguments like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;func add(a, b int32) int32 {&#xA;&#x9;return a + b&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;However, this doesn&amp;rsquo;t work with strings. WASI specification currently does not support string inputs. Because I wanted to pass some strings as input, I couldn&amp;rsquo;t simply parametrize my function like this.&lt;/p&gt;&#xA;&lt;p&gt;I tried to make use of WASI memory and pass input through that method using a bunch of &lt;a href=&#34;https://k33g.hashnode.dev/wasi-communication-between-nodejs-and-wasm-modules-with-the-wasm-buffer-memory&#34;&gt;different tutorials&lt;/a&gt; but wasn&amp;rsquo;t able to get anywhere. I was getting &lt;a href=&#34;https://github.com/tessi/wasmex/issues/521&#34;&gt;all sorts of errors&lt;/a&gt; and because I was new to the world of Web Assembly I decided to opt for the path of least resistance and ended up using pipes.&lt;/p&gt;&#xA;&lt;p&gt;Here is how you can pass binary input to Go using pipes:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;binary = File.read!(&amp;#34;./native/main.wasm&amp;#34;)&#xA;{:ok, stdin_pipe} = Wasmex.Pipe.new()&#xA;wasi = %Wasmex.Wasi.WasiOptions{args: [], stdin: stdin_pipe}&#xA;{:ok, pid} = Wasmex.start_link(%{bytes: binary, wasi: wasi})&#xA;&#xA;Wasmex.Pipe.write(stdin_pipe, &amp;#34;Hello world!&amp;#34;)&#xA;Wasmex.Pipe.seek(stdin_pipe, 0)&#xA;{:ok, []} = Wasmex.call_function(pid, :greet, [])&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This code will put &lt;code&gt;&amp;quot;Hello world&amp;quot;&lt;/code&gt; in the &lt;code&gt;stdin&lt;/code&gt; pipe that you can read from the Go side in your &lt;code&gt;greet&lt;/code&gt; function like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;func greet() {&#xA;    // Here data will contain &amp;#34;Hello world&amp;#34;&#xA;    data, _ := io.ReadAll(os.Stdin)&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;4-how-to-get-data-out-of-the-wasi-binary&#34;&gt;4. How to get data out of the WASI binary&lt;/h2&gt;&#xA;&lt;p&gt;Similar to how you use a &lt;code&gt;stdin&lt;/code&gt; pipe, you can make use of a &lt;code&gt;stdout&lt;/code&gt; pipe. Let&amp;rsquo;s first modify the Go code to output the greeting to &lt;code&gt;stdout&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;import &amp;#34;fmt&amp;#34;&#xA;&#xA;func greet() {&#xA;    data, _ := io.ReadAll(os.Stdin)&#xA;    fmt.Println(&amp;#34;👋 Data from Elixir:&amp;#34;, string(data))&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now, let&amp;rsquo;s make use of the &lt;code&gt;stdout&lt;/code&gt; pipe:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;binary = File.read!(&amp;#34;./native/main.wasm&amp;#34;)&#xA;{:ok, stdout_pipe} = Wasmex.Pipe.new()&#xA;{:ok, stdin_pipe} = Wasmex.Pipe.new()&#xA;wasi = %Wasmex.Wasi.WasiOptions{args: [], stdout: stdout_pipe, stdin: stdin_pipe}&#xA;{:ok, pid} = Wasmex.start_link(%{bytes: binary, wasi: wasi})&#xA;&#xA;# Put data in stdin pipe&#xA;Wasmex.Pipe.write(stdin_pipe, &amp;#34;Yasoob here!&amp;#34;)&#xA;Wasmex.Pipe.seek(stdin_pipe, 0)&#xA;&#xA;# Call the greet function&#xA;{:ok, []} = Wasmex.call_function(pid, :greet, [])&#xA;&#xA;# Read data from stdout&#xA;Wasmex.Pipe.seek(stdout_pipe, 0)&#xA;IO.puts(Wasmex.Pipe.read(stdout_pipe))&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This should print &lt;code&gt;👋 Data from Elixir: Yasoob here!&lt;/code&gt; on the screen.&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;I had fun learning about Web Assembly and figuring out that it is not too hard to call Go code from Elixir using WASI. I am pretty sure there must be some caveats to this approach as the complexity of the Go code increases but for most basic use cases this is a perfect solution. I haven&amp;rsquo;t benchmarked the memory usage of this solution but that is not a concern for my project at this stage. If push comes to shove, I can always go forward with a Ports-based solution.&lt;/p&gt;&#xA;&lt;p&gt;This small endeavor made me realize that even if Elixir doesn&amp;rsquo;t have a relevant library or package, I can look towards Go as well and interface Go from Elixir. Rust was always an option via Rustler but now Go is also a viable option if something doesn&amp;rsquo;t exist in Rust either (as was the case in my project).&lt;/p&gt;&#xA;&lt;p&gt;I hope this article helps those who are trying to do something similar &amp;#x1f604;&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Apple Vision Framework OCR in Python Using PyObjC</title>
				<link>https://yasoob.me/posts/how-to-use-vision-framework-via-pyobjc/</link>
				<pubDate>Sat, 26 Aug 2023 20:03:31 -0700</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/how-to-use-vision-framework-via-pyobjc/</guid>
				<category>python</category>
				<description>Recognize text in images with Apple&amp;#39;s Vision framework from Python. A practical PyObjC guide to VNRecognizeTextRequest and VNImageRequestHandler.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/vision-framework/header.png&#34; alt=&#34;Apple Vision Framework OCR in Python Using PyObjC&#34;&gt;&lt;/p&gt;&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;&#xA;&lt;p&gt;This post has been sitting in my drafts folder for a long time. Sometime earlier this year I saw a job posting where someone wanted to use Apple&amp;rsquo;s vision framework to do text recognition. I wasn&amp;rsquo;t interested in the job but I was curious about the Vision framework as I had never used it before.&lt;/p&gt;&#xA;&lt;p&gt;In this article, I will take you through how I used PyObjC to interface with the Apple Vision Framework and create a script to detect text in images. In the process, you will learn how PyObjC works and how it maps functions and methods from Objective C to Python.&lt;/p&gt;&#xA;&lt;p&gt;By the end of this article, you will know enough to be able to write a script that takes such an image as input:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/vision-framework/screenshot.png&#34; alt=&#34;screenshot&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;And uses Vision Framework to run OCR over it and produce an output image with overlayed bounding boxes:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/vision-framework/overlayed-image.png&#34; alt=&#34;Overlayed image&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;And also print the detected text in the terminal:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;• Hi everyone!&#xA;I am Yasoob! You might know me from Practical Python Projects or the Intermediate Python book.&#xA;Welcome to my personal blog which is going to be the new home for all of my old and new articles. You&#xA;can turn on &amp;#34;dark mode&amp;#34; by clicking on the moon (right before the RSS icon) in the side-bar. I hope you&#xA;enjoy your stay g&#xA;Source&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So without any further ado, let&amp;rsquo;s begin!&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; While I was halfway through this project, I discovered the wonderful &lt;a href=&#34;https://github.com/RhetTbull/osxphotos&#34;&gt;osxphotos&lt;/a&gt; project on GitHub that also &lt;a href=&#34;https://github.com/RhetTbull/osxphotos/blob/main/osxphotos/text_detection.py&#34;&gt;interfaces with the Vision Framework&lt;/a&gt;. I developed most of the code in this article independently but I did take a lot of inspiration from the &lt;code&gt;osxphotos&lt;/code&gt; project once I found out about it.&lt;/p&gt;&#xA;&lt;h2 id=&#34;what-is-apple-vision-framework&#34;&gt;What is Apple Vision Framework&lt;/h2&gt;&#xA;&lt;p&gt;It is a proprietary framework from Apple that is specifically designed for use with iOS and macOS. It provides a range of pre-trained models and APIs that can be used to quickly and easily add image analysis and computer vision capabilities to an app.&lt;/p&gt;&#xA;&lt;p&gt;I am not an Objective C or Swift programmer so when I heard about this framework, my very next question was whether I could use it from Python. Turns out, the framework is not exposed through a dedicated Python library. However, I could use it via PyObjC. If you have never used or heard about PyObjC, it provides a bridge between Python and Objective C and also provides bindings to most Apple frameworks on macOS.&lt;/p&gt;&#xA;&lt;h2 id=&#34;how-to-use-apple-vision-framework-with-python&#34;&gt;How to use Apple Vision Framework with Python&lt;/h2&gt;&#xA;&lt;p&gt;We will be relying on the following libraries in this tutorial:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://pyobjc.readthedocs.io/en/latest/index.html&#34;&gt;PyObjC&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;PIL/&lt;a href=&#34;https://pillow.readthedocs.io/en/stable/index.html&#34;&gt;Pillow&lt;/a&gt; (to visualize OCR results)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;You can install both of these using the following PIP command:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ pip install Pillow pyobjc&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As I already mentioned, &lt;a href=&#34;https://pyobjc.readthedocs.io/en/latest/index.html&#34;&gt;PyObjC&lt;/a&gt; is a bridge between Python and Objective-C.  It allows full-featured Cocoa applications to be written in pure Python. It provides wrappers for most of the Objective C classes and frameworks on Apple machines. We will be relying on it to make use of native Apple frameworks and classes via Python.&lt;/p&gt;&#xA;&lt;p&gt;Create a  new Python file and add the following imports:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; Quartz&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; Foundation &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; NSURL, NSRange&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; Vision&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; PIL &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; Image, ImageDraw&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The Quartz, Vision, and Foundation packages all come from the &lt;code&gt;pyobjc&lt;/code&gt; library. They provide access to the following features:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Quartz (provides tools for working with graphics on Macs)&lt;/li&gt;&#xA;&lt;li&gt;Foundation (provides access to different core data types)&lt;/li&gt;&#xA;&lt;li&gt;Vision (provides access to the vision framework)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I will be basing this whole tutorial around the official &lt;a href=&#34;https://developer.apple.com/documentation/vision/recognizing_text_in_images&#34;&gt;Apple tutorial&lt;/a&gt; for recognizing text in images using Vision Framework. The only difference will be that the official docs use Swift whereas I will use Python.&lt;/p&gt;&#xA;&lt;p&gt;The text recognition process broadly involves using &lt;a href=&#34;https://developer.apple.com/documentation/vision/vnrecognizetextrequest&#34;&gt;&lt;code&gt;VNRecognizeTextRequest&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://developer.apple.com/documentation/vision/vnimagerequesthandler&#34;&gt;&lt;code&gt;VNImageRequestHandler&lt;/code&gt;&lt;/a&gt;. The &lt;code&gt;VNRecognizeTextRequest&lt;/code&gt; takes in an image-based input and finds and extracts text from that image and the &lt;code&gt;VNImageRequestHandler&lt;/code&gt; performs this request.&lt;/p&gt;&#xA;&lt;p&gt;According to Apple docs, the code for doing text recognition looks like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// Get the CGImage on which to perform requests.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;guard&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; cgImage = UIImage(named: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;snapshot&amp;#34;&lt;/span&gt;)?.cgImage &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt; { &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// Create a new image-request handler.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; requestHandler = VNImageRequestHandler(cgImage: cgImage)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// Create a new request to recognize text.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; request = VNRecognizeTextRequest(completionHandler: recognizeTextHandler)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;do&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;// Perform the text-recognition request.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;try&lt;/span&gt; requestHandler.perform([request])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;} &lt;span style=&#34;color:#66d9ef&#34;&gt;catch&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    print(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Unable to perform the requests: &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;\(&lt;/span&gt;error&lt;span style=&#34;color:#e6db74&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;.&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;and the &lt;code&gt;recognizeTextHandler&lt;/code&gt; (for processing the response) looks something like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;recognizeTextHandler&lt;/span&gt;(request: VNRequest, error: Error?) {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;guard&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; observations =&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            request.results &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt;? [VNRecognizedTextObservation] &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; recognizedStrings = observations.compactMap { observation &lt;span style=&#34;color:#66d9ef&#34;&gt;in&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;// Return the string of the top VNRecognizedText instance.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; observation.topCandidates(&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;).first?.string&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;// Process the recognized strings.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    processResults(recognizedStrings)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Our goal is to replicate all of these steps using PyObjC. The first issue is that the Apple docs make use of &lt;code&gt;UIImage&lt;/code&gt; which is a part of &lt;code&gt;UIKit&lt;/code&gt;. However, pyobjc does not currently provide a wrapper for this framework. I had to do some digging to find a reliable source for this claim. The &lt;a href=&#34;https://raw.githubusercontent.com/ronaldoussoren/pyobjc/e3771a7777a85eaea569885e17581ca5ef41e2ae/docs/notes/framework-wrappers.rst&#34;&gt;official pyobjc docs&lt;/a&gt; mention it but it took me a while to find this page:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/vision-framework/pyobjc-docs.png&#34; alt=&#34;PyObjC docs&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;This means that I have to find another way to get a CGImage instance from a file on the disc.&lt;/p&gt;&#xA;&lt;p&gt;After some research, I found that I can initialize a &lt;code&gt;VNImageRequestHandler&lt;/code&gt; using a &lt;code&gt;CIImage&lt;/code&gt; and then create a &lt;code&gt;CIImage&lt;/code&gt; from a file on disc. The code looks something like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Get the CIImage on which to perform requests.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;input_url &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; NSURL&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;fileURLWithPath_(img_path)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;input_image &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CIImage&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;imageWithContentsOfURL_(input_url)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Create a new image-request handler.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;request_handler &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Vision&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;VNImageRequestHandler&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;alloc()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;initWithCIImage_options_(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        input_image, &lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This code might look fairly verbose compared to the Swift example but if you try to understand how pyobjc works, it will start making sense. Read &lt;a href=&#34;https://pyobjc.readthedocs.io/en/latest/core/intro.html&#34;&gt;this page&lt;/a&gt; of the pyobjc docs and then come back. Now let&amp;rsquo;s explore the above code step by step.&lt;/p&gt;&#xA;&lt;p&gt;I start by creating an &lt;code&gt;NSURL&lt;/code&gt; by passing it a path to the image file I want to perform the OCR on. PyObjC appends a trailing &lt;code&gt;_&lt;/code&gt; on all method calls (not function calls) that take an argument. Next, I pass the &lt;code&gt;NSURL&lt;/code&gt; into the &lt;code&gt;imageWithContentsOfURL_&lt;/code&gt; method of &lt;code&gt;CIImage&lt;/code&gt;. Finally, I pass this &lt;code&gt;CIImage&lt;/code&gt; to the &lt;code&gt;initWithCIImage_options_&lt;/code&gt; method of &lt;code&gt;VNImageRequestHandler&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Objective C does object initialization in two stages. In the first step, it allocates some space and then it initializes an object. Swift masks this whole process. PyObjC allows us to follow the same two-step procedure by first calling &lt;code&gt;alloc()&lt;/code&gt; and then calling a modified form of &lt;code&gt;init&lt;/code&gt; depending on our needs.&lt;/p&gt;&#xA;&lt;p&gt;According to the official docs, &lt;a href=&#34;https://developer.apple.com/documentation/vision/vnimagerequesthandler&#34;&gt;VNImageRequestHandler&lt;/a&gt; has quite a few initializers:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/vision-framework/apple-docs.png&#34; alt=&#34;Apple Docs for VNImageRequestHandler&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;PyObjC allows us to use any of these initializers by appending &lt;code&gt;With&lt;/code&gt; to &lt;code&gt;init&lt;/code&gt; and then following that with the argument names and appending a &lt;code&gt;_&lt;/code&gt; to each argument name. For instance, if I want to call &lt;code&gt;init&lt;/code&gt; with &lt;code&gt;ciImage&lt;/code&gt; and &lt;code&gt;options&lt;/code&gt; arguments, I can use &lt;code&gt;initWithCIImage_options_&lt;/code&gt; and if I want to call &lt;code&gt;init&lt;/code&gt; with &lt;code&gt;ciImage&lt;/code&gt;, &lt;code&gt;orientation&lt;/code&gt; and  &lt;code&gt;options&lt;/code&gt; arguments, I can use &lt;code&gt;initWithCIImage_orientation_options_&lt;/code&gt;. Once you internalize this format, you will be able to convert any Objective C method/function call to pyobjc format with little to no effort.&lt;/p&gt;&#xA;&lt;p&gt;Next, I need to create a Python-based &lt;code&gt;recognizeTextHandler&lt;/code&gt; function. This is what I ended up with:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;recognize_text_handler&lt;/span&gt;(request, error):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    observations &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; request&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;results()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    results &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; observation &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; observations:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        recognized_text &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; observation&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;topCandidates_(&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        results&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append([recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;string(), recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;confidence()])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    print(results)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now I need to create a new Vision request and pass &lt;code&gt;recognizeTextHandler&lt;/code&gt; to it:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Create a new request to recognize text.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;request &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Vision&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;VNRecognizeTextRequest&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;alloc()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;initWithCompletionHandler_(recognize_text_handler)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I know I can use &lt;code&gt;initWithCompletionHandler&lt;/code&gt; because &lt;code&gt;VNRecognizeTextRequest&lt;/code&gt; inherits from the &lt;a href=&#34;https://developer.apple.com/documentation/vision/vnrequest&#34;&gt;&lt;code&gt;VNRequest&lt;/code&gt;&lt;/a&gt; superclass and that superclass has a &lt;a href=&#34;https://developer.apple.com/documentation/vision/vnrequest/2875416-init&#34;&gt;&lt;code&gt;init&lt;/code&gt; method&lt;/a&gt; that takes a &lt;code&gt;completionHandler&lt;/code&gt; argument.&lt;/p&gt;&#xA;&lt;p&gt;The only thing left to do is to initiate the request. I can do that by calling the Python equivalent of &lt;a href=&#34;https://developer.apple.com/documentation/vision/vnimagerequesthandler/2880297-perform&#34;&gt;&lt;code&gt;perform&lt;/code&gt; method&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Perform the text-recognition request.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; request_handler&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;performRequests_error_([vision_request], &lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here is the complete Python code so far:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; Quartz&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; Foundation &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; NSURL&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; Vision&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;recognize_text_handler&lt;/span&gt;(request, error):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    observations &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; request&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;results()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    results &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; observation &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; observations:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# Return the string of the top VNRecognizedText instance.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        recognized_text &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; observation&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;topCandidates_(&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        results&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append([recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;string(), recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;confidence()])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; result &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; results:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        print(result)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# TODO Process the recognized strings.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;img_path &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;./screenshot.png&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Get the CIImage on which to perform requests.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;input_url &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; NSURL&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;fileURLWithPath_(img_path)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;input_image &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CIImage&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;imageWithContentsOfURL_(input_url)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Create a new image-request handler.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;request_handler &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Vision&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;VNImageRequestHandler&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;alloc()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;initWithCIImage_options_(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        input_image, &lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Create a new request to recognize text.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;request &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Vision&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;VNRecognizeTextRequest&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;alloc()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;initWithCompletionHandler_(recognize_text_handler)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Perform the text-recognition request.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; request_handler&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;performRequests_error_([request], &lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you run this code, you should see the detected strings in the terminal. I used the following image for testing (taken from my homepage):&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/vision-framework/screenshot.png&#34; alt=&#34;screenshot&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;And this is the output I saw in the terminal:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;• Hi everyone!&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;0.5&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;I am Yasoob! You might know me from Practical Python Projects or the Intermediate Python book.&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1.0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Welcome to my personal blog which is going to be the new home for all of my old and new articles. You&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1.0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;can turn on &amp;#34;dark mode&amp;#34; by clicking on the moon (right before the RSS icon) in the side-bar. I hope you&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;0.5&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;enjoy your stay g&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1.0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Source&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;1.0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;displaying-detected-bounding-boxes-using-pillow&#34;&gt;Displaying detected bounding boxes using Pillow&lt;/h2&gt;&#xA;&lt;p&gt;I have been able to successfully detect text in an image using Vision Framework but it is very hard to visualize where Vision detected the said text in the image. I can fix that by overlaying the detected bounding boxes on the original image. Pillow](&lt;a href=&#34;https://pillow.readthedocs.io/en/stable/index.html&#34;&gt;https://pillow.readthedocs.io/en/stable/index.html&lt;/a&gt;) makes this overlaying job very convenient.&lt;/p&gt;&#xA;&lt;p&gt;It turns out, the &lt;a href=&#34;https://developer.apple.com/documentation/vision/vnrecognizedtextobservation/3152637-topcandidates?language=objc&#34;&gt;&lt;code&gt;observation.topCandidates_&lt;/code&gt;&lt;/a&gt; method call returns a &lt;a href=&#34;https://developer.apple.com/documentation/vision/vnrecognizedtext?language=objc&#34;&gt;&lt;code&gt;VNRecognizedText&lt;/code&gt;&lt;/a&gt; object and these objects have a &lt;a href=&#34;https://developer.apple.com/documentation/vision/vnrecognizedtext/3152634-boundingboxforrange?language=objc&#34;&gt;&lt;code&gt;boundingBoxForRange&lt;/code&gt;&lt;/a&gt; method that returns the bounding box around the range of characters in an observation. This is exactly what I need.&lt;/p&gt;&#xA;&lt;p&gt;This is what I used to get the bounding box:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; Foundation &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; NSRange&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# ... &lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;box_range &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; NSRange(&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;, len(recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;string()))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;boxObservation &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;boundingBoxForRange_error_(box_range, &lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;boxObservation&lt;/code&gt; is of type CGRect. However, I can not use these coordinates directly as they are in the normalized coordinates space. This means that they range from -1 to 1. I need to convert them to image coordinates first. This is possible via the &lt;a href=&#34;https://developer.apple.com/documentation/vision/2908993-vnimagerectfornormalizedrect&#34;&gt;&lt;code&gt;VNImageRectForNormalizedRect&lt;/code&gt; function&lt;/a&gt;. This function takes in the normalized coordinates and the dimensions of an image and maps the normalized coordinates in the image coordinate space.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Convert the rectangle from normalized coordinates to image coordinates.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;image_width, image_height &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; input_image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;extent()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;size&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;width, input_image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;extent()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;size&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;height&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;rect &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Vision&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;VNImageRectForNormalizedRect(boundingBox, image_width, image_height)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;rsquo;s put this rect in the &lt;code&gt;results&lt;/code&gt; array and create a new function to process all the results and overlay them on the input image:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;recognize_text_handler&lt;/span&gt;(request, error):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# --snip--&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; observation &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; observations:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# --snip--&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        results&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append([recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;string(), recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;confidence(), rect])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    visualize_results(results)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;visualize_results&lt;/span&gt;(results):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    image &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;open(img_path)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    draw&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;ImageDraw&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Draw(image)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; result &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; results:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# TODO: Draw the result bounding box&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;show()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;After doing a little digging, it appears that I can get the x, and y coordinates of the &lt;code&gt;rect&lt;/code&gt; via the following functions:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;CGRectGetMinX&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;CGRectGetMinY&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;CGRectGetMaxX&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;CGRectGetMaxY&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I can update the visualization code to get the appropriate x, and y coordinates and draw them over the image. I replaced the &lt;code&gt;TODO&lt;/code&gt; comment with this code:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;rect &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; result[&lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;min_x &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CGRectGetMinX(rect)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;min_y &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CGRectGetMinY(rect)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;max_x &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CGRectGetMaxX(rect)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;max_y &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CGRectGetMaxY(rect)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;draw&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;rectangle([(min_x, min_y),(max_x, max_y)],outline&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;black&amp;#34;&lt;/span&gt;, width&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;After saving and running the code, I got this output:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/vision-framework/wrong-overlay.png&#34; alt=&#34;Wrong overlay&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;This doesn&amp;rsquo;t seem right! Upon closer inspection, I observed that the y coordinates are upside down. Took me a while to figure out that I could easily fix that by subtracting the y-coordinates from the image height:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;min_y &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; input_image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;extent()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;size&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;height &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CGRectGetMinY(rect)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;max_y &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; input_image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;extent()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;size&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;height &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CGRectGetMaxY(rect)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I am not entirely certain why the coordinates are flipped. I did some &lt;a href=&#34;https://stackoverflow.com/questions/2695262/how-to-compensate-the-flipped-coordinate-system-of-core-graphics-for-easy-drawin&#34;&gt;research&lt;/a&gt; and it just appears that the Core Graphics library simply returns flipped Y coordinates and we need to compensate for it ourselves.&lt;/p&gt;&#xA;&lt;p&gt;This is the complete code so far (with some minor modifications):&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; Quartz&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; Foundation &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; NSURL, NSRange&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; Vision&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; PIL &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; Image, ImageDraw&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;recognize_text_handler&lt;/span&gt;(request, error):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    observations &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; request&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;results()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    results &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; observation &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; observations:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# Return the string of the top VNRecognizedText instance.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        recognized_text &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; observation&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;topCandidates_(&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# Find the bounding-box observation for the string range.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        box_range &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; NSRange(&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;, len(recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;string()))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        boxObservation &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;boundingBoxForRange_error_(box_range, &lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# Get the normalized CGRect value.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        boundingBox &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; boxObservation[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;]&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;boundingBox()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# Convert the rectangle from normalized coordinates to image coordinates.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        image_width, image_height &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; input_image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;extent()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;size&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;width, input_image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;extent()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;size&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;height&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        rect &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Vision&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;VNImageRectForNormalizedRect(boundingBox, image_width, image_height)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        results&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append([recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;string(), recognized_text&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;confidence(), rect])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# Print out the results in the terminal for inspection&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; result &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; results:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        print(result[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    visualize_results(results)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;visualize_results&lt;/span&gt;(results):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    image &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;open(img_path)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    draw&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;ImageDraw&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Draw(image)    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; result &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; results:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        rect &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; result[&lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        min_x &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CGRectGetMinX(rect)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        max_x &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CGRectGetMaxX(rect)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# The y coordinates need to be flipped&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        min_y &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; input_image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;extent()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;size&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;height &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CGRectGetMinY(rect)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        max_y &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; input_image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;extent()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;size&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;height &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CGRectGetMaxY(rect)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# Draw the observation rect on the image&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        draw&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;rectangle([(min_x, min_y),(max_x, max_y)],outline&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;black&amp;#34;&lt;/span&gt;, width&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#75715e&#34;&gt;# Display the final image with all the observations overlayed&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    image&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;show()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;img_path &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;./screenshot.png&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Get the CIImage on which to perform requests.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;input_url &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; NSURL&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;fileURLWithPath_(img_path)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;input_image &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Quartz&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CIImage&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;imageWithContentsOfURL_(input_url)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Create a new image-request handler.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;request_handler &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Vision&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;VNImageRequestHandler&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;alloc()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;initWithCIImage_options_(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    input_image, &lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Create a new request to recognize text.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;request &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Vision&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;VNRecognizeTextRequest&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;alloc()&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;initWithCompletionHandler_(recognize_text_handler)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Perform the text-recognition request.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;error &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; request_handler&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;performRequests_error_([request], &lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Deallocate memory&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;request_handler&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;dealloc()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;request&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;dealloc()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Save and run the code and you should see something similar to this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/vision-framework/overlayed-image.png&#34; alt=&#34;Overlayed image&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;I hope you learned a little bit about how to use PyObjC and how to interact with the native Objective C classes, functions, and frameworks. It was a very interesting journey for me as I had never worked with Quartz, Vision, and Core Graphics libraries before. I had no clue about how PyObjC worked either. I just had a vision (no pun intended) of being able to use the Vision framework for text detection and learned everything else on the fly.&lt;/p&gt;&#xA;&lt;p&gt;Would I use PyObjC for programming against Objective C frameworks again? It depends. If I have to develop a very complex application that is entirely based on the Objective C frameworks then I might just use Swift as the tooling is much better. However, if the Objective C frameworks are just a small part of the application then I might just go ahead and use PyObjC. A big reason for this apart from the dedicated tooling is that sometimes &lt;a href=&#34;https://github.com/ronaldoussoren/pyobjc/issues/518&#34;&gt;it can be hard to debug errors in PyObjC-based code&lt;/a&gt;. I had to pull my hair quite a bit while developing this sample application and I would not want to go through that same experience on a bigger project with considerably more complex PyObjC code.&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>How to Efficiently Reorder or Rerank Items in Database</title>
				<link>https://yasoob.me/posts/how-to-efficiently-reorder-or-rerank-items-in-database/</link>
				<pubDate>Sun, 12 Feb 2023 23:32:12 +0500</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/how-to-efficiently-reorder-or-rerank-items-in-database/</guid>
				<category>programming</category>
				<category>database</category>
				<description>Ever wondered how Jira and Trello store the order of tasks or issues? How they can effortlessly reorder items in the database even when there are a million items? In this article, you will gain an understanding of reordering and reranking techniques and how to store order information in the database to facilitate efficient reordering.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/reorder-items/header.png&#34; alt=&#34;How to Efficiently Reorder or Rerank Items in Database&#34;&gt;&lt;/p&gt;&lt;p&gt;I was once thinking about Trello and Jira and wondered how they implemented the sorting functionality in their drag &amp;amp; drop interface. You can have a million items/cards and both of these platforms will allow you to change the order in a simple drag and drop manner and efficiently update their position in the database.&lt;/p&gt;&#xA;&lt;p&gt;How could I implement such a system? It was hard to do research on this topic because most queries returned results from blogs that showed how to implement a drag and drop component using &lt;a href=&#34;https://react-dnd.github.io/react-dnd/&#34;&gt;React DnD&lt;/a&gt; and similar libraries but did not show how to persist the new order in a database. Nevertheless, I kept on searching and was able to read up on 3 different methods and want to share them with you.&lt;/p&gt;&#xA;&lt;h2 id=&#34;problem&#34;&gt;Problem&lt;/h2&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s set up the problem that motivated this research. Imagine you have a list that has associated items. The db models might look something like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;List&lt;/span&gt;(models&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Model):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    name &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; models&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CharField(max_length&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;100&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;Item&lt;/span&gt;(models&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Model):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    list &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; models&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;ForeignKey(List, related_name&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;items&amp;#39;&lt;/span&gt;, on_delete&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;models&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CASCADE)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    name &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; models&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CharField(max_length&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;100&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    order &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; models&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;IntegerField(default&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now imagine you have 10 items and the order goes from 1-10 for these 10 items. For simplicity&amp;rsquo;s sake, this is how they might look like:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;|order |  name       |&#xA;|------|-------------|&#xA;| 1    | Item No: 1  |&#xA;| 2    | Item No: 2  |&#xA;| 3    | Item No: 3  |&#xA;| 4    | Item No: 4  |&#xA;| 5    | Item No: 5  |&#xA;| 6    | Item No: 6  |&#xA;| 7    | Item No: 7  |&#xA;| 8    | Item No: 8  |&#xA;| 9    | Item No: 9  |&#xA;| 10   | Item No: 10 |&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now, you are are being asked to update the order of the 10th item to 2. The resulting list will look something like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;|order |  name       |&#xA;|------|-------------|&#xA;| 1    | Item No: 1  |&#xA;| 2    | Item No: 10 |&#xA;| 3    | Item No: 2  |&#xA;| 4    | Item No: 3  |&#xA;| 5    | Item No: 4  |&#xA;| 6    | Item No: 5  |&#xA;| 7    | Item No: 6  |&#xA;| 8    | Item No: 7  |&#xA;| 9    | Item No: 8  |&#xA;| 10   | Item No: 9  |&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the problem is, how can you make this reordering operating efficient? In this nieve example, you will have to re-order each successive item in the database and modify its order. This will lead to 9 total database calls for modifying the order of item 10 from 10 to 2.&lt;/p&gt;&#xA;&lt;p&gt;For a small list, this brute-force approach might work. At most you will have to update the ordering of all the items between the current order position and the new order position. If this is the solution you want to go ahead with, you can read &lt;a href=&#34;https://www.revsys.com/tidbits/keeping-django-model-objects-ordered/&#34;&gt;this post on the Revsys blog&lt;/a&gt; on how to implement something like this in Django. However, this solution will not scale so lets look at a few diffrent approaches to fixing this problem.&lt;/p&gt;&#xA;&lt;h2 id=&#34;approach-1-order-items-in-increments-of-100&#34;&gt;Approach 1: Order items in increments of 100&lt;/h2&gt;&#xA;&lt;p&gt;The first approach is to set the initial order value in multiples of 100 (or any other large number). This is how the default ordering will look like:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;|order |  name       |&#xA;|------|-------------|&#xA;| 100  | Item No: 1  |&#xA;| 200  | Item No: 2  |&#xA;| 300  | Item No: 3  |&#xA;| 400  | Item No: 4  |&#xA;| 500  | Item No: 5  |&#xA;| 600  | Item No: 6  |&#xA;| 700  | Item No: 7  |&#xA;| 800  | Item No: 8  |&#xA;| 900  | Item No: 9  |&#xA;| 1000 | Item No: 10 |&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When you have to modify the order of item 10 and move it to position 2, you can simply update the order value to be between 100 and 200. This will result in an order value of 150 for item 10. This will not require any changes to the ordering of the rest of the items as long as the difference between the order value of adjacent items is more than 1.&lt;/p&gt;&#xA;&lt;p&gt;This is what the newly ordered table will look like:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;|order |  name       |&#xA;|------|-------------|&#xA;| 100  | Item No: 1  |&#xA;| 150  | Item No: 10 |&#xA;| 200  | Item No: 2  |&#xA;| 300  | Item No: 3  |&#xA;| 400  | Item No: 4  |&#xA;| 500  | Item No: 5  |&#xA;| 600  | Item No: 6  |&#xA;| 700  | Item No: 7  |&#xA;| 800  | Item No: 8  |&#xA;| 900  | Item No: 9  |&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This approach allows us to reorder and place 100 items between any 2 items with default ordering before it runs into problems. What would you do when two adjacent items have an order difference of only 1? Let&amp;rsquo;s take a look at the next approach and see how to get around this.&lt;/p&gt;&#xA;&lt;h2 id=&#34;approach-2-order-items-using-a-floating-number&#34;&gt;Approach 2: Order items using a floating number&lt;/h2&gt;&#xA;&lt;p&gt;This approach suggests to ditch integers and start using floating point numbers to keep the order. This will result in such a table structure:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;|order |  name       |&#xA;|------|-------------|&#xA;| 1.0  | Item No: 1  |&#xA;| 2.0  | Item No: 2  |&#xA;| 3.0  | Item No: 3  |&#xA;| 4.0  | Item No: 4  |&#xA;| 5.0  | Item No: 5  |&#xA;| 6.0  | Item No: 6  |&#xA;| 7.0  | Item No: 7  |&#xA;| 8.0  | Item No: 8  |&#xA;| 9.0  | Item No: 9  |&#xA;| 10.0 | Item No: 10 |&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now when you reorder and move Item no 10 to position 2, it will get an order value of 1.5. You can keep on moving items around and there will always be room to add more items as the order is now a floating point number.&lt;/p&gt;&#xA;&lt;p&gt;Pretty good approach! This solves the previous issue where we ran out of values to assign to the order key when adjacent values had an order difference of only 1. However, the floats also have a limit. I doubt you will encounter that limit in most typical cases but it is there and it is good to be aware of it. Most databases have their own limit for how big a float can be so I will not go into too much detail.&lt;/p&gt;&#xA;&lt;p&gt;There is one more approach that overcomes these limitations.&lt;/p&gt;&#xA;&lt;h2 id=&#34;approach-3-order-items-using-lexorank&#34;&gt;Approach 3: Order items using LexoRank&lt;/h2&gt;&#xA;&lt;p&gt;LexoRank is currently used by Jira for ordering and ranking issues. You can read &lt;a href=&#34;https://tmcalm.nl/blog/lexorank-jira-ranking-system-explained/&#34;&gt;this article&lt;/a&gt; to get some idea of how it works inside Jira from an admin standpoint.&lt;/p&gt;&#xA;&lt;p&gt;The word LexoRank can be divided into two parts:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Lexo: refers to the word lexicographical which basically means alphabetical ordering.&lt;/li&gt;&#xA;&lt;li&gt;Rank: refers to the position of Jira issues on a board’s backlog, on a kanban board itself or in the active sprint on a scrum board.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;It basically makes use of alphanumeric strings to keep the order. By default, the items might be ordered like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;|order |  name       |&#xA;|------|-------------|&#xA;| a    | Item No: 1  |&#xA;| b    | Item No: 2  |&#xA;| c    | Item No: 3  |&#xA;| d    | Item No: 4  |&#xA;| e    | Item No: 5  |&#xA;| f    | Item No: 6  |&#xA;| g    | Item No: 7  |&#xA;| h    | Item No: 8  |&#xA;| i    | Item No: 9  |&#xA;| j    | Item No: 10 |&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you want to move item 10 to position 2, you can simply append &amp;ldquo;a&amp;rdquo; at the end. The updated order will look like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;|order |  name       |&#xA;|------|-------------|&#xA;| a    | Item No: 1  |&#xA;| aa   | Item No: 10 |&#xA;| b    | Item No: 2  |&#xA;| c    | Item No: 3  |&#xA;| d    | Item No: 4  |&#xA;| e    | Item No: 5  |&#xA;| f    | Item No: 6  |&#xA;| g    | Item No: 7  |&#xA;| h    | Item No: 8  |&#xA;| i    | Item No: 9  |&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now if you want to move item 9 to position 3, the updated order might resemble this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;|order |  name       |&#xA;|------|-------------|&#xA;| a    | Item No: 1  |&#xA;| aa   | Item No: 10 |&#xA;| ab   | Item No: 9  |&#xA;| b    | Item No: 2  |&#xA;| c    | Item No: 3  |&#xA;| d    | Item No: 4  |&#xA;| e    | Item No: 5  |&#xA;| f    | Item No: 6  |&#xA;| g    | Item No: 7  |&#xA;| h    | Item No: 8  |&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This way you can either keep on appending characters at the end of the order value or update one of the characters whenever you want to modify the order. The actual LexoRank implementation is not this simple but uses the same concept. It offsets each new order value and also makes use of buckets. These buckets come into play when individual order values become too long and need to be normalized. You can read &lt;a href=&#34;https://stackoverflow.com/questions/40718900/jiras-lexorank-algorithm-for-new-stories&#34;&gt;this StackOverflow answer&lt;/a&gt; to get a better sense of how it works.&lt;/p&gt;&#xA;&lt;p&gt;And that&amp;rsquo;s it! One thing I could have done better while doing this research is to search for &amp;ldquo;ranking&amp;rdquo; algorithms on top of &amp;ldquo;ordering&amp;rdquo; algorithms. That might have yielded better results much quicker. If this post helps you in any way, please do let me know.&lt;/p&gt;&#xA;&lt;p&gt;I plan on keeping future articles short and to-the-point so that I can keep writing more often. A long post takes too much time and requires a ton of editing. I will keep writing those as well but I don&amp;rsquo;t want most new ideas to end up on my drafts folder and never see the light of day. One such draft has been open in a separate tab on my laptop for more than 2 months now 🙃 Wish me luck and pray that I stick to this new plan of publishing more frequently.&lt;/p&gt;&#xA;&lt;h2 id=&#34;further-reading&#34;&gt;Further reading&lt;/h2&gt;&#xA;&lt;p&gt;Here is a list of articles that might help if you want to read more on this topic:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://stackoverflow.com/questions/40718900/jiras-lexorank-algorithm-for-new-stories&#34;&gt;Jira&amp;rsquo;s Lexorank algorithm for new stories&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://cs.stackexchange.com/questions/60530/terminology-what-does-alphanumeric-order-mean-in-relation-to-decimals&#34;&gt;Terminology - What does alphanumeric order mean in relation to decimals?&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://medium.com/whisperarts/lexorank-what-are-they-and-how-to-use-them-for-efficient-list-sorting-a48fc4e7849f&#34;&gt;LexoRanks — what are they and how to use them for efficient list sorting&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.revsys.com/tidbits/keeping-django-model-objects-ordered/&#34;&gt;Keeping Django Models Ordered&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Building a Synced Spotify Lyrics Display in Python</title>
				<link>https://yasoob.me/posts/spotify-synced-and-translated-lyrics-display/</link>
				<pubDate>Thu, 11 Aug 2022 01:43:58 +0500</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/spotify-synced-and-translated-lyrics-display/</guid>
				<category>python</category>
				<category>programming</category>
				<category>spotify</category>
				<category>automation</category>
				<category>project</category>
				<description>How I built a Python app that reads Spotify&amp;#39;s current song and playback position and shows synced, translated lyrics across two screens.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/spotify-lyrics/header.png&#34; alt=&#34;Building a Synced Spotify Lyrics Display in Python&#34;&gt;&lt;/p&gt;&lt;p&gt;Hi guys! 👋&lt;/p&gt;&#xA;&lt;p&gt;It has been a while since I last posted anything. I have been busy but I am back with a fun article. I came across a job posting on Upwork where someone was looking for a software that plays the lyrics of a Spotify song on dual screens. One screen will display the English lyrics and the other one will display Hungarian lyrics. I was really intrigued so I decided to give it a go. In this article I am going to talk about the whole thought process I went through while trying to figure out a solution as I think that part is often missing from programming tutorials.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/spotify-lyrics/job.png&#34; alt=&#34;Job posting&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;I learned about a few fun things while implementing this project. The first one is MPRIS (Media Player Remote Interfacing Specification). It is a standard D-Bus interface that provides a common programmatic API for controlling media players. Spotify supports MPRIS however, as far as I am aware, MPRIS is mainly a Unix-specific technology. It is theoretically supported on Mac but I couldn&amp;rsquo;t find much useful information about it.&lt;/p&gt;&#xA;&lt;p&gt;I did not end up using MPRIS for this project but I wanted to mention it here for my future self. And if you are working with multimedia on a Unix-based system, you should definitely check it out!&lt;/p&gt;&#xA;&lt;p&gt;Enough with the prelude, let&amp;rsquo;s dive right in.&lt;/p&gt;&#xA;&lt;h2 id=&#34;final-product&#34;&gt;Final product&lt;/h2&gt;&#xA;&lt;p&gt;This is what I ended up making:&lt;/p&gt;&#xA;&lt;video width=&#34;100%&#34; height=&#34;100%&#34; controls&gt;&#xA; &lt;source src=&#34;https://i.imgur.com/UMC4EUe.mp4&#34; type=&#34;video/mp4&#34;&gt;&#xA;  Your browser does not support the video tag.&#xA;&lt;/video&gt;&#xA;&lt;p&gt;As you can see, the lyrics are all synced up with the song. Only the currently playing stanza is showed up on the screen. The lyrics are loaded from local text files where each song has an accompanying text file containing the lyrics.&lt;/p&gt;&#xA;&lt;h2 id=&#34;doing-the-research&#34;&gt;Doing the research&lt;/h2&gt;&#xA;&lt;p&gt;As soon as I read the problem statement, I decided to flex my Google-fu and run some searches. You will be surprised how often there is an open source project doing exactly what you are trying to do and you can repurpose it for your use case. However, my searches didn&amp;rsquo;t result in much success. I guess the main reason for it was that this is such a niche use case. Spotify already provides perfectly synced lyrics for songs and most people don&amp;rsquo;t need them translated. And even if they do, they can simply use Google translate.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/spotify-lyrics/spotify-english-lyrics.png&#34; alt=&#34;Lyrics inside Spotify&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;I did come across two projects on GitHub:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://github.com/Jugran/lyrics-in-terminal&#34;&gt;Lyrics-in-Terminal&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://github.com/SwagLyrics/SwSpotify&#34;&gt;SwSpotify&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;However, neither of these projects catered to my specific needs. The first project was not cross-platform. It only works on Linux and so I ruled it out right away.&lt;/p&gt;&#xA;&lt;p&gt;The second project was a bit more useful. It gives the name of the currently playing song and the artist for that song. Most importantly, it was multi-platform. I figured that if I can get this to work on my machine, I can use the name of the song and the artist to locate a local text file containing the lyrics of the song and display them in a browser window using Flask.&lt;/p&gt;&#xA;&lt;p&gt;The only remaining issue was that the song and artist name were not enough for me to display the lyrics. I needed a way to display only the current stanza that was playing. SwSpotify didn&amp;rsquo;t have an API for me to get the current location of the playhead. I needed that to figure out which stanza to play. Luckily, SwSpotify showed me a method that I could use to get this information. I saw that it was using Apple Script to query Spotify for the song information.&lt;/p&gt;&#xA;&lt;p&gt;This is what the &lt;a href=&#34;https://github.com/SwagLyrics/SwSpotify/blob/master/SwSpotify/spotify.py#L111&#34;&gt;relevant code section&lt;/a&gt; looked like:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;apple_script_code &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;# Check if Spotify is currently running&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;if application &amp;#34;Spotify&amp;#34; is running then&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    # If this executes it means Spotify is currently running&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    getCurrentlyPlayingTrack()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;end if&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;on getCurrentlyPlayingTrack()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    tell application &amp;#34;Spotify&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        set isPlaying to player state as string&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        set currentArtist to artist of current track as string&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        set currentTrack to name of current track as string&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        return {currentArtist, currentTrack, isPlaying}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    end tell&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;end getCurrentlyPlayingTrack&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Sadly I had no idea which queries were supported by the Spotify application. I decided to run some Google searches again and came across &lt;a href=&#34;https://stackoverflow.com/questions/8901556/controlling-spotify-with-applescript&#34;&gt;this StackOverflow question&lt;/a&gt;. Someone had helpfully mentioned a file that contained all the available queries.&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/Applications/Spotify.app/Contents/Resources/Spotify.sdef&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I quickly opened it up and saw &lt;code&gt;player position&lt;/code&gt;. I tested it out in the Apple Script Editor and thankfully it worked right away:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/spotify-lyrics/apple-script.png&#34; alt=&#34;Apple Script Editor&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;This is the final Apple Script that I ended up with:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;if application &amp;#34;Spotify&amp;#34; is running then&#xA;    # If this executes it means Spotify is currently running&#xA;    getCurrentTrackPosition()&#xA;end if&#xA;on getCurrentTrackPosition()&#xA;    tell application &amp;#34;Spotify&amp;#34;&#xA;        set trackPosition to player position as string&#xA;        return trackPosition&#xA;    end tell&#xA;end getCurrentTrackPosition&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After figuring out the Apple Script, I decided that I was going to prepare the lyrics files such that there was a timecode before each stanza. I can then process these lyrics files in Python and match the track position with the appropriate stanza.&lt;/p&gt;&#xA;&lt;p&gt;This is what the relevant section of one of these files ended up looking like:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[00:08.62]&#xA;First things first&#xA;I&amp;#39;ma say all the words inside my head&#xA;I&amp;#39;m fired up and tired of the way that things have been, oh ooh&#xA;The way that things have been, oh ooh&#xA;&#xA;[00:22.63]&#xA;Second thing second&#xA;Don&amp;#39;t you tell me what you think that I can be&#xA;I&amp;#39;m the one at the sail, I&amp;#39;m the master of my sea, oh ooh&#xA;The master of my sea, oh ooh&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;At this point, the only missing piece was to figure out how to stream lyrics from Flask to the browser. I wanted it to be as simple as possible so I didn&amp;rsquo;t want to use web sockets. Luckily I had used streaming responses in Flask before so I knew I could use them for this purpose. I searched online for a ready-made example and came across &lt;a href=&#34;https://stackoverflow.com/questions/61398680/updating-streamed-data-from-flask-in-real-time&#34;&gt;this StackOverflow answer&lt;/a&gt; that contained some sample code for me to use.&lt;/p&gt;&#xA;&lt;h2 id=&#34;final-code&#34;&gt;Final code&lt;/h2&gt;&#xA;&lt;p&gt;I used the code from that answer and ended up with this final code:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; SwSpotify &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; spotify, SpotifyNotRunning, SpotifyPaused&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; flask &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; Flask, render_template&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; subprocess&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; time&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; re&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;app &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Flask(__name__)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;get_current_time&lt;/span&gt;():&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    apple_script_code &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    # Check if Spotify is currently running&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    if application &amp;#34;Spotify&amp;#34; is running then&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        # If this executes it means Spotify is currently running&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        getCurrentTrackPosition()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    end if&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    on getCurrentTrackPosition()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        tell application &amp;#34;Spotify&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;            set trackPosition to player position as string&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;            return trackPosition&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        end tell&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    end getCurrentTrackPosition&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    result &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; subprocess&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;run(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        [&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;osascript&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;-e&amp;#34;&lt;/span&gt;, apple_script_code],&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        capture_output&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;True&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        encoding&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;utf-8&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    print(result&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;stdout)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; result&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;stdout &lt;span style=&#34;color:#f92672&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;get_sec&lt;/span&gt;(time_str):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;Get seconds from time.&amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    m, s &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; time_str&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;split(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;:&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; int(m) &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;60&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; float(s)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;get_lyrics&lt;/span&gt;(song_name, language):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;try&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;with&lt;/span&gt; open(&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;./&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;language&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;_lyrics/&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;song_name&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;.txt&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;r&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; f:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            lyrics &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; f&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;read()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;except&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;FileNotFoundError&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    pattern &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; re&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;compile(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;\[(.+)\]((?:&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;\n&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;.+)+)&amp;#34;&lt;/span&gt;, re&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MULTILINE)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    splitted &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; re&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;findall(pattern, lyrics)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    time_stanza &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; {}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; (time, stanza) &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; splitted:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        time_stanza[get_sec(time)] &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; stanza&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;strip()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; time_stanza&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;@app.route&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;/&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;index&lt;/span&gt;():&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; render_template(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;index.html&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;@app.route&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;/stream&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;stream&lt;/span&gt;():&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;generate&lt;/span&gt;():&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;while&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;True&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;try&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                title, artist &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; spotify&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;current()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;except&lt;/span&gt; (SpotifyNotRunning, SpotifyPaused) &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; e:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                print(e)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                print(&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;title&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt; - &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;artist&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                current_time &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; float(get_current_time())&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                print(current_time)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                time_stanza &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; get_lyrics(title, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;english&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                current_stanza &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; time_stanza:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    time_list &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; list(time_stanza&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;keys())&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; index, stanza_start_time &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; enumerate(time_list):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; (&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                            stanza_start_time &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; current_time&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                            &lt;span style=&#34;color:#f92672&#34;&gt;and&lt;/span&gt; time_list[index &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;] &lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt; current_time&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        ):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                            current_stanza &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; time_stanza[stanza_start_time]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                            &lt;span style=&#34;color:#66d9ef&#34;&gt;break&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#66d9ef&#34;&gt;yield&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;title&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;title()&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt; - &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;artist&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;title()&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt; ##&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;current_stanza&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;\n&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;----&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            time&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;sleep(&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; app&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;response_class(generate(), mimetype&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;text/plain&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;app&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;run()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is the accompanying HTML template:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-jinja&#34; data-lang=&#34;jinja&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&amp;lt;!DOCTYPE html&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&amp;lt;html&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&amp;lt;head&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&amp;lt;/head&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&amp;lt;body&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &amp;lt;div class=&amp;#34;song-meta&amp;#34;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &amp;lt;img src=&lt;span style=&#34;color:#75715e&#34;&gt;{{&lt;/span&gt; url_for&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;static&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;,&lt;/span&gt; filename&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;images/music.png&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#75715e&#34;&gt;}}&lt;/span&gt; width=&amp;#34;50&amp;#34; alt=&amp;#34;song name&amp;#34; /&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &amp;lt;span id=&amp;#34;songName&amp;#34;&amp;gt;Loading..&amp;lt;/span&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &amp;lt;/div&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &amp;lt;div class=&amp;#34;lyrics&amp;#34;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &amp;lt;pre id=&amp;#34;stanza&amp;#34;&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &amp;lt;/pre&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &amp;lt;/div&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &amp;lt;script&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        var songNameSpan = document.getElementById(&amp;#39;songName&amp;#39;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        var stanzaSpan = document.getElementById(&amp;#39;stanza&amp;#39;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        var xhr = new XMLHttpRequest();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        xhr.open(&amp;#39;GET&amp;#39;, &amp;#39;&lt;span style=&#34;color:#75715e&#34;&gt;{{&lt;/span&gt; url_for&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;stream&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#75715e&#34;&gt;}}&lt;/span&gt;&amp;#39;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        xhr.onreadystatechange = function () {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            var all_lines = xhr.responseText.split(&amp;#39;\n----&amp;#39;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            last_line = all_lines.length - 2&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            var songName_stanza = all_lines[last_line]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            if (songName_stanza){&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                songName_stanza = songName_stanza.split(&amp;#39;##&amp;#39;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                console.log(songName_stanza)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                songNameSpan.textContent = songName_stanza[0]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                stanzaSpan.textContent = songName_stanza[1]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            if (xhr.readyState == XMLHttpRequest.DONE) {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                /*Sometimes it stops working when the stream is finished (song changes)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                so I just refresh the page. It almost always solves the issue*/&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                document.location.reload()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                songNameSpan.textContent = &amp;#34;The End of Stream&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        xhr.send();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &amp;lt;/script&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &amp;lt;style&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        html,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        body {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            height: 100%;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        body {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            margin: 0;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            background-color: #272727;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        .song-meta {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            position: absolute;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            top: 40px;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            left: 40px;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            display: flex;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            align-items: center;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        #songName {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            font-size: 2rem;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            margin-left: 20px;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            background-color: white;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            padding: 10px 20px;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            border-radius: 20px;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        .lyrics {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            height: 100%;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            padding: 0;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            margin: 0;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            display: flex;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            align-items: center;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            justify-content: center;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        #stanza {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            width: auto;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            font-family: Helvetica, sans-serif;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            padding: 5px;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            margin: 10px;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            line-height: 1.5em;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            color: white;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            font-size: 4rem;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            text-align: center;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &amp;lt;/style&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&amp;lt;/body&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&amp;lt;/html&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;My final directory structure looked like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;.&#xA;├── app.py&#xA;├── english_lyrics&#xA;│   └── Believer.txt&#xA;├── static&#xA;│   └── images&#xA;│       └── music.png&#xA;└── templates&#xA;    └── index.html&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And this is what the final application website looked like:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/spotify-lyrics/final-application.png&#34; alt=&#34;Final web app&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;There is a lot of stuff that is not optimized in the Python code. This is a quick and dirty solution to this problem but it works perfectly fine. I did not work with the buyer so I had no reason to improve it. I just wanted to test out the idea because the project seemed fun 😃&lt;/p&gt;&#xA;&lt;p&gt;I had a lot of fun while working on this project. I hope you learned about my thought process in this article and saw how you can go from point 0 to a fully working project and put different pieces together. If you like reading about this kind of stuff please comment below. I love to hear from you guys!&lt;/p&gt;&#xA;&lt;p&gt;Till next time! 👋&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Setting Up Custom Root Domain using Webflow and Cloudflare</title>
				<link>https://yasoob.me/posts/setting-up-custom-root-domain-webflow-cloudflare/</link>
				<pubDate>Thu, 28 Apr 2022 03:08:35 +0500</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/setting-up-custom-root-domain-webflow-cloudflare/</guid>
				<category>no-code</category>
				<category>webflow</category>
				<category>dns</category>
				<description>Are you trying to set up a custom root domain with Webflow &amp;amp; Cloudflare but it is not working? I recently did the same and faced some issues. Let me save you some time and show you how to set it up. By the end, you will have working redirection from www subdomain to your root domain.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/webflow-cloudflare/hero.png&#34; alt=&#34;Setting Up Custom Root Domain using Webflow and Cloudflare&#34;&gt;&lt;/p&gt;&lt;p&gt;Hi everyone! &amp;#x1f44b;&lt;/p&gt;&#xA;&lt;p&gt;I tried Webflow for the first time a few days ago and fell in love with it. I have been programming for a good number of years now and I am fairly comfortable with HTML and CSS but I can&amp;rsquo;t imagine building complex interactions without Webflow anymore. The grass is surprisingly mostly green on the other side &amp;#x1f606;&lt;/p&gt;&#xA;&lt;h2 id=&#34;problem&#34;&gt;Problem&lt;/h2&gt;&#xA;&lt;p&gt;But you aren&amp;rsquo;t here to listen to my praise for Webflow. You are probably here because you tried to set up a custom root domain with Webflow and it failed. Maybe you also received the &amp;ldquo;Error too many redirects&amp;rdquo; error like I did when I was trying to make it work and the Webflow University article wasn&amp;rsquo;t making much sense. Or maybe you were able to get the &lt;code&gt;www&lt;/code&gt; subdomain routing to work with Webflow but want to set up root domain routing instead. In this post, I will go through a few of the errors I faced and how I was able to fix them and successfully set up root domain routing.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/webflow-cloudflare/too-many-requests.png&#34; alt=&#34;Too many requests error&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Caption:&lt;/em&gt; Error too many redirects&lt;/p&gt;&#xA;&lt;h2 id=&#34;setting-up-a-custom-domain-on-webflow&#34;&gt;Setting up a custom domain on Webflow&lt;/h2&gt;&#xA;&lt;p&gt;The very first step is to go to your Webflow project settings and add a new custom domain:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/webflow-cloudflare/webflow-custom-domain.png&#34; alt=&#34;webflow-custom-domain&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;You will see that Webflow automatically adds the &lt;code&gt;www&lt;/code&gt; subdomain. At this point you can scroll to the top of the project settings page and publish your website on the new domain you just added:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/webflow-cloudflare/webflow-domain-publish.png&#34; alt=&#34;webflow-domain-publish&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Now we need to go to &lt;a href=&#34;https://dash.cloudflare.com/&#34;&gt;Cloudflare Dashboard&lt;/a&gt; and set up our DNS records.&lt;/p&gt;&#xA;&lt;h2 id=&#34;setting-up-dns-records-on-cloudflare&#34;&gt;Setting up DNS records on Cloudflare&lt;/h2&gt;&#xA;&lt;p&gt;I am going to use &lt;code&gt;yasoob.me&lt;/code&gt; as an example domain for this article.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/webflow-cloudflare/cloudflare-add-site.png&#34; alt=&#34;cloudflare-add-site&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Go ahead and add the following two CNAME records on the next page:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CNAME     @      proxy-ssl.webflow.com&#xA;CNAME     www    proxy-ssl.webflow.com&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;@&lt;/code&gt; will automatically convert to your root domain once you enter the record. Make sure you set the &lt;strong&gt;Proxy status&lt;/strong&gt; to DNS only. Otherwise, the SSL will not work.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/webflow-cloudflare/cloudflare-dns-records.png&#34; alt=&#34;cloudflare-dns-records&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;This will automatically turn on CNAME flattening as we have a CNAME pointing root to Webflow.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/webflow-cloudflare/cloudflare-cname-flattening.png&#34; alt=&#34;cloudflare-cname-flattening&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;If you were receiving the &lt;code&gt;Too many redirects&lt;/code&gt; error before you started following this guide, chances are that you had also added the &lt;code&gt;A&lt;/code&gt; records to Cloudflare.  Your configuration might have looked like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/webflow-cloudflare/cloudflare-wrong-dns.png&#34; alt=&#34;cloudflare-wrong-dns&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;This configuration will work fine if you want to have the &lt;code&gt;www&lt;/code&gt; subdomain as the main website and redirect people from &lt;code&gt;root&lt;/code&gt; domain to this subdomain. But it will not work if you want to use the root domain as the main website and redirect people from the &lt;code&gt;www&lt;/code&gt; subdomain to your root domain.&lt;/p&gt;&#xA;&lt;h2 id=&#34;marking-root-domain-as-default-on-webflow&#34;&gt;Marking root domain as default on Webflow&lt;/h2&gt;&#xA;&lt;p&gt;Now we just need to go to project settings on Webflow and mark the root domain as the default website:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/webflow-cloudflare/webflow-default-domain.png&#34; alt=&#34;webflow-default-domain&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Sweet! now you just need to wait for a while, let the DNS changes propagate, and then visit the newly published website.&lt;/p&gt;&#xA;&lt;h2 id=&#34;bonus&#34;&gt;Bonus&lt;/h2&gt;&#xA;&lt;p&gt;When I was trying to connect Cloudflare with Webflow, I was running &lt;code&gt;dig&lt;/code&gt; to verify if the DNS changes had successfully propagated. However, once Cloudflare started handling my DNS, I saw the following error in &lt;code&gt;dig&lt;/code&gt; output:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ dig @1.1.1.1 yasoob.me                                                                                                                  &#xA;&#xA;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.6 &amp;lt;&amp;lt;&amp;gt;&amp;gt; @1.1.1.1 yasoob.me&#xA;; (1 server found)&#xA;;; global options: +cmd&#xA;;; Got answer:&#xA;;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: SERVFAIL, id: 34361&#xA;;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1&#xA;&#xA;;; OPT PSEUDOSECTION:&#xA;; EDNS: version: 0, flags:; udp: 1232&#xA;; OPT=15: 00 16 61 74 20 64 65 6c 65 67 61 74 69 6f 6e 20 61 73 65 63 2e 63 6f 6d 2e 70 6b 2e (&amp;#34;..at delegation yasoob.me.&amp;#34;)&#xA;; OPT=15: 00 17 5b 32 36 32 30 3a 34 64 3a 34 30 30 30 3a 36 32 35 39 3a 37 70 6b 20 41 (&amp;#34;..[2620:4d:4000:6259:7:2:0:1]:53 rcode=REFUSED for yasoob.me A&amp;#34;)&#xA;;; QUESTION SECTION:&#xA;;yasoob.me.&#x9;&#x9;&#x9;IN&#x9;A&#xA;&#xA;;; Query time: 678 msec&#xA;;; SERVER: 1.1.1.1#53(1.1.1.1)&#xA;;; WHEN: Thu Apr 28 00:55:18 PKT 2022&#xA;;; MSG SIZE  rcvd: 140&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I thought I had misconfigured Cloudflare. I am not a DNS expert. I know enough to be dangerous but this &lt;code&gt;REFUSED&lt;/code&gt; error was above my paygrade.&lt;/p&gt;&#xA;&lt;p&gt;I tried changing the DNS server I was using to resolve the domain and surprisingly it didn&amp;rsquo;t give the same output:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ dig @8.8.8.8 yasoob.me &#xA;&#xA;; &amp;lt;&amp;lt;&amp;gt;&amp;gt; DiG 9.10.6 &amp;lt;&amp;lt;&amp;gt;&amp;gt; @8.8.8.8 yasoob.me&#xA;; (1 server found)&#xA;;; global options: +cmd&#xA;;; Got answer:&#xA;;; -&amp;gt;&amp;gt;HEADER&amp;lt;&amp;lt;- opcode: QUERY, status: NOERROR, id: 22014&#xA;;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1&#xA;&#xA;;; OPT PSEUDOSECTION:&#xA;; EDNS: version: 0, flags:; udp: 512&#xA;;; QUESTION SECTION:&#xA;;yasoob.me.&#x9;&#x9;&#x9;IN&#x9;A&#xA;&#xA;;; ANSWER SECTION:&#xA;yasoob.me.&#x9;&#x9;60&#x9;IN&#x9;A&#x9;52.49.198.28&#xA;yasoob.me.&#x9;&#x9;60&#x9;IN&#x9;A&#x9;3.248.8.137&#xA;yasoob.me.&#x9;&#x9;60&#x9;IN&#x9;A&#x9;52.212.43.230&#xA;&#xA;;; Query time: 140 msec&#xA;;; SERVER: 8.8.8.8#53(8.8.8.8)&#xA;;; WHEN: Thu Apr 28 00:55:15 PKT 2022&#xA;;; MSG SIZE  rcvd: 72&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It was also not working in my browser and I was out of ideas. Then the one thing I didn&amp;rsquo;t expect to help, helped. It was &amp;hellip;waiting&amp;hellip; 😂 Turns out when they ask to give DNS propagation some time, they aren&amp;rsquo;t saying that for no reason. I waited and the error just vanished. Cloudflare also started returning the correct results as the Google DNS. So I guess what I am trying to say is that for certain errors with DNS, make sure you have waited a while before aimlessly searching for solutions. Maybe the error will resolve itself in due time.&lt;/p&gt;&#xA;&lt;p&gt;One more thing, if you are trying to set up Google Search Console and Google asks you to put a TXT record in your DNS records, you can use &lt;code&gt;@&lt;/code&gt; as the host. They don&amp;rsquo;t specify the host when they give you the instructions so I hope this helps you in case you try to figure that out next &amp;#x1f604;&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;I hope this article helps save you some time while trying to integrate Cloudflare and Webflow and setting up a custom root domain for the latter. If you have any questions/suggestions/feedback please write them in a comment below or shoot me an email.&lt;/p&gt;&#xA;&lt;p&gt;Have a good day! &amp;#x2764;&amp;#xfe0f;&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>How to Extract WhatsApp Messages from an iPhone Backup</title>
				<link>https://yasoob.me/posts/extracting-whatsapp-messages-from-ios-backup/</link>
				<pubDate>Sun, 24 Apr 2022 06:20:49 +0500</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/extracting-whatsapp-messages-from-ios-backup/</guid>
				<category>programming</category>
				<category>python</category>
				<category>reverse-engineering</category>
				<category>ios</category>
				<description>Find where WhatsApp chats live in an iPhone backup, decrypt an encrypted iOS backup with Python, and read your messages from ChatStorage.sqlite.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/exploring-ios-backup/hero.png&#34; alt=&#34;How to Extract WhatsApp Messages from an iPhone Backup&#34;&gt;&lt;/p&gt;&lt;p&gt;Hi everyone! &amp;#x1f44b; I was recently exploring how to get a local backup of WhatsApp messages from my iPhone. I switched from Android to iOS in the past and lost all of my WhatsApp messages. I wanted to make sure that if I switched again from iOS to Android I don&amp;rsquo;t lose any messages. I don&amp;rsquo;t really care if I can import the messages in WhatsApp. I just don&amp;rsquo;t want to lose all of the important information I have in my chats. I don&amp;rsquo;t have any immediate plans for switching (if ever) but it seemed like a fun challenge and so I started surveying the available tools and how they work.&lt;/p&gt;&#xA;&lt;p&gt;This was mostly a learning exercise for me regarding how Apple stores iOS backups and how I can selectively extract information and data from one. My target was to have a local copy of WhatsApp messages that I can read and search through locally. It would be doubly awesome if I can move the messages to an Android device but, as I mentioned before, that wasn&amp;rsquo;t my main aim.&lt;/p&gt;&#xA;&lt;h3 id=&#34;exploring-ios-backup&#34;&gt;Exploring iOS backup&lt;/h3&gt;&#xA;&lt;p&gt;By default, when you create an iOS backup on Mac (Catalina in my case), it is stored under &lt;code&gt;~/Library/Application Support/MobileSync/Backup/&lt;/code&gt;. This folder contains sub-folders with unique device identifiers. Each sub-folder is a backup and contains a bunch of additional subfolders along with the following 4 important files:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;Info.plist&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;Manifest.db&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;Manifest.plist&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;Status.plist&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;We mainly care about both of the &lt;code&gt;Manifest&lt;/code&gt; files.&lt;/p&gt;&#xA;&lt;p&gt;The &lt;code&gt;Manifest.plist&lt;/code&gt; file is a binary Property List file that contains information about the backup. It contains:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Backup keybag: The Backup keybag contains a set of data protection class keys that are different from the keys in the System keybag, and backed-up data is re-encrypted with the new class keys. Keys in the Backup keybag facilitate the secure storage of backups. We will learn about protection classes later&lt;/li&gt;&#xA;&lt;li&gt;Date: This is the timestamp of a backup created or last updated&lt;/li&gt;&#xA;&lt;li&gt;ManifestKey: This is the key used to encrypt Manifest.db (wrapped with protection class four)&lt;/li&gt;&#xA;&lt;li&gt;WasPasscodeSet: This identifies whether a passcode was set on the device when it was last synced&lt;/li&gt;&#xA;&lt;li&gt;And much more&amp;hellip;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Source: &lt;a href=&#34;https://www.oreilly.com/library/view/practical-mobile-forensics/9781788839198/6c69c5a8-5226-4211-916e-9a56fd7bdd2c.xhtml&#34;&gt;O&amp;rsquo;Reilly&lt;/a&gt; + &lt;a href=&#34;https://www.richinfante.com/2017/3/16/reverse-engineering-the-ios-backup&#34;&gt;Richinfante&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Whereas, the &lt;code&gt;Manifest.db&lt;/code&gt; file contains all the juicy info about the files in the backup and their paths. The only problem is that the &lt;code&gt;Manifest.db&lt;/code&gt; file is encrypted and we need to use the information from the &lt;code&gt;Manifest.plist&lt;/code&gt; file to decrypt it. If the backup was not encrypted, we could have probably gotten away without making use of the &lt;code&gt;Manifest.plist&lt;/code&gt; file.&lt;/p&gt;&#xA;&lt;p&gt;We can verify that the db file is encrypted by opening it in any SQL db viewer. I used &amp;ldquo;&lt;a href=&#34;https://sqlitebrowser.org/&#34;&gt;DB Browser for SQLite&lt;/a&gt;&amp;rdquo; and it showed me this screen:&lt;/p&gt;&#xA;&lt;p&gt;![SQLCipher Encryption](/images/exploring-ios-backup/SQLCipher encryption.png)&lt;/p&gt;&#xA;&lt;p&gt;This clearly shows that the db is encrypted. Later we will see that not only is the DB encrypted, but every file is also encrypted with its own random per-file encryption key.&lt;/p&gt;&#xA;&lt;h3 id=&#34;decrypting-the-manifestdb-file&#34;&gt;Decrypting the Manifest.db file&lt;/h3&gt;&#xA;&lt;p&gt;The basic decryption process is as follows:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Decode the keybag stored in the &lt;code&gt;BackupKeyBag&lt;/code&gt; entry of &lt;code&gt;Manifest.plist&lt;/code&gt;. A high-level overview of this structure is given in the &lt;a href=&#34;https://www.apple.com/ca/business-docs/iOS_Security_Guide.pdf&#34;&gt;iOS Security Whitepaper&lt;/a&gt;. The &lt;a href=&#34;http://theiphonewiki.com/wiki/index.php?title=ITunes_Backup#BackupKeyBag&#34;&gt;iPhone Wiki&lt;/a&gt; describes the binary format: a 4-byte string type field, a 4-byte big-endian length field, and then the value itself.&lt;/p&gt;&#xA;&lt;p&gt;The important values are the PBKDF2 &lt;code&gt;ITER&lt;/code&gt;ations and &lt;code&gt;SALT&lt;/code&gt;, the double protection salt &lt;code&gt;DPSL&lt;/code&gt; and iteration count &lt;code&gt;DPIC&lt;/code&gt;, and then for each protection &lt;code&gt;CLS&lt;/code&gt;, the &lt;code&gt;WPKY&lt;/code&gt; wrapped key.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Using the backup password derive a 32-byte key using the correct PBKDF2 salt and number of iterations. First, use a SHA256 round with &lt;code&gt;DPSL&lt;/code&gt; and &lt;code&gt;DPIC&lt;/code&gt;, then a SHA1 round with &lt;code&gt;ITER&lt;/code&gt; and &lt;code&gt;SALT&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Unwrap each wrapped key according to &lt;a href=&#34;http://www.apps.ietf.org/rfc/rfc3394.html&#34;&gt;RFC 3394&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Decrypt the manifest database by pulling the 4-byte protection class and longer key from the &lt;code&gt;ManifestKey&lt;/code&gt; in &lt;code&gt;Manifest.plist&lt;/code&gt;, and unwrapping it. You now have a SQLite database with all file metadata.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;For each file of interest, get the class-encrypted per-file encryption key and protection class code by looking in the &lt;code&gt;Files.file&lt;/code&gt; database column for a binary plist containing &lt;code&gt;EncryptionKey&lt;/code&gt; and &lt;code&gt;ProtectionClass&lt;/code&gt; entries. Strip the initial four-byte length tag from &lt;code&gt;EncryptionKey&lt;/code&gt; before using.&lt;/p&gt;&#xA;&lt;p&gt;Then, derive the final decryption key by unwrapping it with the class key that was unwrapped with the backup password. Then decrypt the file using AES in CBC mode with a zero IV.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Source: &lt;a href=&#34;https://stackoverflow.com/questions/1498342/how-to-decrypt-an-encrypted-apple-itunes-iphone-backup/13793043#13793043&#34;&gt;StackOverflow&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;If protection classes and double protection doesn&amp;rsquo;t make much sense, I would highly recommend reading the &lt;a href=&#34;https://www.apple.com/ca/business-docs/iOS_Security_Guide.pdf&#34;&gt;iOS Security Whitepaper&lt;/a&gt; from page 12 onwards. It provides details about all of this and why iOS uses these protection classes.&lt;/p&gt;&#xA;&lt;p&gt;If you don&amp;rsquo;t know what a &lt;strong&gt;Keybag&lt;/strong&gt; is, Apple has &lt;a href=&#34;https://support.apple.com/guide/security/aside/sec8e00e0dd8/1/web/1&#34;&gt;decent documentation&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;A data structure used to store a collection of class keys. Each type (user, device, system, backup, escrow, or iCloud Backup) has the same format.&lt;/p&gt;&#xA;&lt;p&gt;A header containing: Version (set to four in iOS 12 or later), Type (system, backup, escrow, or iCloud Backup), Keybag UUID, an HMAC if the keybag is signed, and the method used for wrapping the class keys—tangling with the UID or PBKDF2, along with the salt and iteration count.&lt;/p&gt;&#xA;&lt;p&gt;A list of class keys: Key UUID, Class (which file or Keychain Data Protection class), wrapping type (UID-derived key only; UID-derived key and passcode-derived key), wrapped class key, and a public key for asymmetric classes.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;We can read the &lt;code&gt;Manifest.plist&lt;/code&gt; file in Python using the &lt;a href=&#34;https://bitbucket.org/wooster/biplist/src/master/&#34;&gt;&lt;code&gt;biplist&lt;/code&gt;&lt;/a&gt; module. You can install it using &lt;code&gt;pip&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;pip install biplist&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And then use it like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; biplist &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; readPlist&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; os&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;backup_directory &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; os&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;path&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;expanduser(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;~/Library/Application Support/MobileSync/Backup/&amp;lt;unique_id&amp;gt;&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;plist_path &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; os&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;path&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;join(backup_directory, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Manifest.plist&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;plist &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; readPlist(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Manifest.plist&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Don&amp;rsquo;t forget to replace &lt;code&gt;&amp;lt;unique_id&amp;gt;&lt;/code&gt; with the name of you particular device backup folder.&lt;/p&gt;&#xA;&lt;p&gt;This is what the &lt;code&gt;plist&lt;/code&gt; contents would look like:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/exploring-ios-backup/image-20220423162825355.png&#34; alt=&#34;Manifest.plist&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;From this dict, we require the &lt;code&gt;backupKeyBag&lt;/code&gt; and &lt;code&gt;ManifestKey&lt;/code&gt;. It will help us decrypt the &lt;code&gt;Manifest.db&lt;/code&gt; file. The &lt;code&gt;BackupKeybag&lt;/code&gt; is a binary string with the following format:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;4-byte block identifier&lt;/li&gt;&#xA;&lt;li&gt;4-byte block length (most significant byte first), length 4 means total block length of 0xC bytes.&lt;/li&gt;&#xA;&lt;li&gt;data&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The first block is &amp;ldquo;VERS&amp;rdquo; with a version number of 3. There are a lot of block types: VERS, TYPE, UUID, HMCK, WRAP, SALT, ITER, UUID, CLAS, WRAP, KTYP, WPKY, etc.&lt;/p&gt;&#xA;&lt;p&gt;Source: &lt;a href=&#34;https://www.theiphonewiki.com/wiki/ITunes_Backup#BackupKeyBag&#34;&gt;IPhone Wiki&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;decrypting-the-keybag&#34;&gt;Decrypting the keybag&lt;/h3&gt;&#xA;&lt;p&gt;There are quite a few resources available online that show you how you can decrypt the keybag. It uses PBKDF2 for key generation and AES for encryption. You can take a look at &lt;a href=&#34;https://stackoverflow.com/a/13793043&#34;&gt;this StackOverflow answer&lt;/a&gt; for working Python code to decrypt the keybag. I will be making use of the code from that answer.&lt;/p&gt;&#xA;&lt;p&gt;There are a bunch of different protection classes. The one used for the manifest database is class 3. We can find this by reading the first 4 bytes of the &lt;code&gt;ManifestKey&lt;/code&gt; value in our &lt;code&gt;Manifest.plist&lt;/code&gt; file:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; struct&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;manifest_class &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; struct&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;unpack(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;lt;l&amp;#39;&lt;/span&gt;, plist[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;ManifestKey&amp;#39;&lt;/span&gt;][:&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;])[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# Output: 3&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I encrypted my iOS backup. This is beneficial because Apple doesn&amp;rsquo;t back up sensitive data unless the backup is encrypted. Sensitive data includes stuff like WiFi passwords. Now we can use the code from StackOverflow, the initial backup encryption passphrase you used while creating the backup, and the rest of the ManifestKey from the &lt;code&gt;Manifest.plist&lt;/code&gt; to decrypt the &lt;code&gt;Manifest.db&lt;/code&gt; file:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;manifest_key &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; plist[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;ManifestKey&amp;#39;&lt;/span&gt;][&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;:]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;kb &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; Keybag(plist[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;BackupKeyBag&amp;#39;&lt;/span&gt;])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;kb&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;unlockWithPassphrase(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;passphrase&amp;#39;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;key &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; kb&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;unwrapKeyForClass(manifest_class, manifest_key)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;with&lt;/span&gt; open(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Manifest.db&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;rb&amp;#39;&lt;/span&gt;) &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; f:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    encrypted_db &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; f&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;read()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;decrypted_data &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; AESdecryptCBC(encrypted_db, key)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;with&lt;/span&gt; open(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;decrypted_manifest.db&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;wb&amp;#39;&lt;/span&gt;) &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; f:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    f&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;write(decrypted_data)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As you can see above, if you don&amp;rsquo;t remember the passphrase you used while backing up your iOS device, you can not decrypt anything. It is necessary to continue the rest of the decryption process.&lt;/p&gt;&#xA;&lt;p&gt;Now if we try to open the &lt;code&gt;decrypted_manifest.db&lt;/code&gt; in a SQL viewer we can see the actual data:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/exploring-ios-backup/decrypted-manifest.png&#34; alt=&#34;decrypted manifest.plist&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;We can search for all files associated with WhatsApp by doing a global search for WhatsApp. The chats are stored in a &lt;code&gt;ChatStorage.sqlite&lt;/code&gt; file:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/exploring-ios-backup/whatsapp-manifest-plist.png&#34; alt=&#34;whatsapp-manifest-plist&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;We can get this record using Python:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; sqlite3&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;db_conn &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; sqlite3&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;connect(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;decrypted_manifest.db&amp;#39;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;relative_path &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Chatstorage.sqlite&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;query &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    SELECT fileID, file&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    FROM Files&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    WHERE relativePath = ?&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    ORDER BY domain, relativePath&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    LIMIT 1;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;cur &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; db_conn&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;cursor()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;cur&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;execute(query, (relative_path,))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;result &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; cur&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;fetchone()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;file_id, file_bplist &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; result&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;One thing to note is that the &lt;code&gt;fileID&lt;/code&gt; is made up of a hash of the domain + file name so it would probably be the same for you. It is generated like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;import hashlib&#xA;&#xA;domain = &amp;#34;AppDomainGroup-group.net.whatsapp.WhatsApp.shared&amp;#34;&#xA;relative_path = &amp;#34;ChatStorage.sqlite&amp;#34;&#xA;hash = hashlib.sha1(f&amp;#34;{domain}-{relative_path}&amp;#34;.encode()).hexdigest()&#xA;&#xA;# hash = 7c7fba66680ef796b916b067077cc246adacf01d&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The record in the db contains the binary plist file associated with &lt;code&gt;ChatStorage.sqlite&lt;/code&gt; file. We got a hold of that by running the above query. We can take a look inside by using the &lt;code&gt;readPlistFromString&lt;/code&gt; method of the &lt;code&gt;biplist&lt;/code&gt; module and extract the required information:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; biplist &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; readPlistFromString&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;file_plist &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; readPlistFromString(file_bplist)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# print(file_plist)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# {&amp;#39;$archiver&amp;#39;: &amp;#39;NSKeyedArchiver&amp;#39;,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;$objects&amp;#39;: [&amp;#39;$null&amp;#39;,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#               {&amp;#39;$class&amp;#39;: Uid(5),&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;Birth&amp;#39;: 1617036196,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;EncryptionKey&amp;#39;: Uid(3),&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;Flags&amp;#39;: 0,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;GroupID&amp;#39;: 501,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;InodeNumber&amp;#39;: 45839007,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;LastModified&amp;#39;: 1650483880,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;LastStatusChange&amp;#39;: 1650481761,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;Mode&amp;#39;: 33188,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;ProtectionClass&amp;#39;: 3,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;RelativePath&amp;#39;: Uid(2),&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;Size&amp;#39;: 22056960,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;UserID&amp;#39;: 501},&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#               &amp;#39;ChatStorage.sqlite&amp;#39;,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#               {&amp;#39;$class&amp;#39;: Uid(4),&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;NS.data&amp;#39;: b&amp;#39;\x03\x00\x00\x00tE1\xd1H\n&amp;#34;e\x06\xf7\x1cl&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                           b&amp;#39;\x82\xed\x05\xe7\x1d\x1c\xd6\x97\x0e\xe9\x8b&amp;#34;&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                           b&amp;#39;\xfa\x16\x93\x9c3\x18\xbe\n\x14\x1eR;f\x98\xe3v&amp;#39;},&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#               {&amp;#39;$classes&amp;#39;: [&amp;#39;NSMutableData&amp;#39;, &amp;#39;NSData&amp;#39;, &amp;#39;NSObject&amp;#39;],&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#                &amp;#39;$classname&amp;#39;: &amp;#39;NSMutableData&amp;#39;},&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#               {&amp;#39;$classes&amp;#39;: [&amp;#39;MBFile&amp;#39;, &amp;#39;NSObject&amp;#39;], &amp;#39;$classname&amp;#39;: &amp;#39;MBFile&amp;#39;}],&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;$top&amp;#39;: {&amp;#39;root&amp;#39;: Uid(1)},&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;$version&amp;#39;: 100000}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;file_data &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; file_plist[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;$objects&amp;#39;&lt;/span&gt;][file_plist[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;$top&amp;#39;&lt;/span&gt;][&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;root&amp;#39;&lt;/span&gt;]&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;integer]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;protection_class &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; file_data[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;ProtectionClass&amp;#39;&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;encryption_key &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; file_plist[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;$objects&amp;#39;&lt;/span&gt;][file_data[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;EncryptionKey&amp;#39;&lt;/span&gt;]&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;integer][&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;NS.data&amp;#39;&lt;/span&gt;][&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;:]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# file_data&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# {&amp;#39;$class&amp;#39;: Uid(5),&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;Birth&amp;#39;: 1617036196,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;EncryptionKey&amp;#39;: Uid(3),&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;Flags&amp;#39;: 0,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;GroupID&amp;#39;: 501,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;InodeNumber&amp;#39;: 45839007,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;LastModified&amp;#39;: 1650483880,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;LastStatusChange&amp;#39;: 1650481761,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;Mode&amp;#39;: 33188,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;ProtectionClass&amp;#39;: 3,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;RelativePath&amp;#39;: Uid(2),&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;Size&amp;#39;: 22056960,&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#  &amp;#39;UserID&amp;#39;: 501}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# protection_class&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# 3&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# encryption_key&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;# ---truncated---&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we need to use the keybag class (&lt;code&gt;kb&lt;/code&gt;) to unwrap the encryption key from above for the specified protection class (3):&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;file_decryption_key &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; kb&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;unwrapKeyForClass(protection_class, encryption_key)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;decrypting-chatstoragesqlite&#34;&gt;Decrypting ChatStorage.sqlite&lt;/h3&gt;&#xA;&lt;p&gt;Sweet! All that is left is to decrypt the actual chat db. But where is it stored? Apple stores files in the backup folder in a predictable format. It puts them in a subdirectory with the name starting with the first two characters of fileID (eg &lt;code&gt;7c/7c7fba66680ef796b916b067077cc246adacf01d&lt;/code&gt;). We can get the full path to the chat db file like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;filename_in_backup &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; os&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;path&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;join(backup_directory, file_id[:&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;], file_id)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will allow us to open the encrypted file and decrypt it using the &lt;code&gt;file_decryption_key&lt;/code&gt; we extracted above:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;with&lt;/span&gt; open(filename_in_backup, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;rb&amp;#39;&lt;/span&gt;) &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; encrypted_file:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    encrypted_data &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; encrypted_file&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;read()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;decrypted_data &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; AESdecryptCBC(encrypted_data, file_decryption_key)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This &lt;code&gt;AESdecryptCBC&lt;/code&gt; function is a part of the code we got from StackOverflow&lt;/p&gt;&#xA;&lt;p&gt;Sometimes the encryption introduces padding at the end of the data to make it a multiple of the blocksize. So we need to make sure we remove any padding from the end of the data as well:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;removePadding&lt;/span&gt;(data, blocksize&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;16&lt;/span&gt;):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    n &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; int(data[&lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;])  &lt;span style=&#34;color:#75715e&#34;&gt;# RFC 1423: last byte contains number of padding bytes.&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; n &lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt; blocksize &lt;span style=&#34;color:#f92672&#34;&gt;or&lt;/span&gt; n &lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt; len(data):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;raise&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;Exception&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Invalid CBC padding&amp;#39;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; data[:&lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt;n]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;decrypted_data &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; removePadding(decrypted_data)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can save this decrypted data in a new SQLite file:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;with&lt;/span&gt; open(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;decrypted_ChatStorage.sqlite&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;wb&amp;#39;&lt;/span&gt;) &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; f:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    f&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;write(decrypted_data)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If we now open this new file in a SQLite browser, we can see all the tables:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/exploring-ios-backup/whatsapp-messages-table.png&#34; alt=&#34;WhatsApp Messages Table&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;The chats are stored in the &lt;code&gt;ZWAMESSAGE&lt;/code&gt; table:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/exploring-ios-backup/whatsapp-messages.png&#34; alt=&#34;WhatsApp Messages&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;If you are looking for all the media files that were sent with messages, you will have to go back to the decrypted &lt;code&gt;Manifest.db&lt;/code&gt; file and filter for media files stored under &lt;code&gt;Message/Media&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/exploring-ios-backup/media-manifest-plist.png&#34; alt=&#34;media manifest.plist&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;You can use the following SQL query to get all of these media files:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;SELECT fileID,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;       relativePath,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;       flags,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;       file&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;FROM Files&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;WHERE relativePath&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    LIKE &amp;#39;Message/Media/%&amp;#39;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now here comes the best part. You don&amp;rsquo;t have to do any of this yourself. There is already a Python program out there that can parse through your iOS backup, download all the media files, chats, and contact list, and convert them into HTML format. This way you can read your chats without porting the backup into a WhatsApp client.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://github.com/KnugiHK/Whatsapp-Chat-Exporter&#34;&gt;Whatsapp-Chat-Exporter&lt;/a&gt; works with iOS and Android &amp;#x2728;&lt;/p&gt;&#xA;&lt;p&gt;I used this tool to eventually convert all of my WhatsApp messages into HTML format for easy browsing on my laptop.&lt;/p&gt;&#xA;&lt;h3 id=&#34;useful-resources&#34;&gt;Useful Resources&lt;/h3&gt;&#xA;&lt;p&gt;I took some help from a bunch of different sources while writing this article. You can go through them to get a deeper understanding of some of the stuff mentioned in this article:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.richinfante.com/2017/3/16/reverse-engineering-the-ios-backup&#34;&gt;Reverse Engineering the iOS Backup&lt;/a&gt; - Contains a detailed listing of all the different files in the backup folder and what they contain&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://stackoverflow.com/a/13793043&#34;&gt;StackOverflow: How to decrypt an encrypted Apple iTunes iPhone backup?&lt;/a&gt; - This answer contains all the information required to successfully write a decryption program for iOS backups&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://github.com/KnugiHK/iphone_backup_decrypt&#34;&gt;iphone-backup-decrypt&lt;/a&gt; - A Python tool that can decrypt a local iOS backup and help you extract files from it. This is based on the SO answer above&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://github.com/KnugiHK/Whatsapp-Chat-Exporter&#34;&gt;Whatsapp-Chat-Exporter&lt;/a&gt; - A Python tool based on &lt;code&gt;iphone-backup-decrypt&lt;/code&gt; that can extract WhatsApp data from iOS backup and convert it into HTML files for reading without the WhatsApp client&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h3&gt;&#xA;&lt;p&gt;I hope you learned a thing or two from this article. I had a fun time diving into the weeds of iOS backups. I had no idea how Apple was storing the backup and how easy/hard it was going to be to get the particular file I wanted from that backup. Suffice to say it wasn&amp;rsquo;t too hard and taught me a few fun things in the process.&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Web Automation With Selenium And Python</title>
				<link>https://yasoob.me/posts/web-automation-with-selenium/</link>
				<pubDate>Sat, 23 Apr 2022 05:05:36 +0500</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/web-automation-with-selenium/</guid>
				<category>programming</category>
				<category>devops</category>
				<category>self-hosted</category>
				<description>In this article we will take a look at how we can automate basic web interactions using Selenium. By the end of this article you will have an automated booking bot that can reserve court space for you automatically. You will also learn about XPath and how to traverse an HTML document using Python, LXML and XPath.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/hero.png&#34; alt=&#34;Web Automation With Selenium And Python&#34;&gt;&lt;/p&gt;&lt;p&gt;Hi everyone! &amp;#x1f44b; I recently moved to Redmond, WA, and tried to get into some sports that could keep me active and moving. After looking around for a bit I realized that half the people here play badminton so it was an easy decision for me to sign up for a local badminton academy. However, after signing up I realized that most of the courts were already booked for prime-time (between 4-8 pm). I found out that the booking for the courts opens up on Saturday at around 10 am and the good timeslots for the next whole week are booked in the first 15-20 minutes. I did what any sane programmer would do and started thinking about how to automate the whole booking process. This article is going to walk you through the manual booking process and explain how I automated it.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;tldr&lt;/strong&gt;: you can download the source for the bot &lt;a href=&#34;https://github.com/yasoob/nwba-booking-bot&#34;&gt;from GitHub&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;manual-booking-process&#34;&gt;Manual booking process&lt;/h3&gt;&#xA;&lt;p&gt;It is always important to fully explore the manual workflow before you attempt to automate anything. We will be automating the Northwest Badminton Academy booking system. This is their reservations page (&lt;a href=&#34;https://www.northwestbadminton.com/courtreservation&#34;&gt;link&lt;/a&gt;).&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/homepage.png&#34; alt=&#34;homepage nwba&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;This page lists all the court reservation rules. It is important for us to keep these in mind as they will play a role in how we automate the bookings. The important rules are:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;We may only book 1 slot each day&lt;/li&gt;&#xA;&lt;li&gt;We may book only 3 slots during weekdays (Mon-Fri)&lt;/li&gt;&#xA;&lt;li&gt;We may book 1 slot each day on Saturday and Sunday&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;At the bottom of the page, they also link to the reservation page with a full calendar (&lt;a href=&#34;https://northwestbadmintonacademy.zenplanner.com/zenplanner/portal/calendar.cfm&#34;&gt;link&lt;/a&gt;). Once you click on that you will be redirected to this page:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/image-20211023170630722.png&#34; alt=&#34;booking login&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Interestingly, the booking is not hosted by NWBA themselves. They outsource it to zen planner. So essentially, we will be automating zen planner bookings. This also means that the final automation should work for most other places as well that use zen planner.&lt;/p&gt;&#xA;&lt;p&gt;Once you go ahead and log in, you can go to the calendar page (&lt;a href=&#34;https://northwestbadmintonacademy.sites.zenplanner.com/calendar.cfm&#34;&gt;link&lt;/a&gt;):&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/image-20211023170722486.png&#34; alt=&#34;booking calendar&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;The calendar shows which timeslots are available, you can click on any time which has a few slots open and it will take you to the timeslot reservation page:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/image-20211023170857889.png&#34; alt=&#34;timeslot reservation&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;From here you can click on &amp;ldquo;Reserve&amp;rdquo; and the page should refresh and tell you that your reservation was successful.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/image-20211023170937209.png&#34; alt=&#34;Reservation successful&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;And while following the booking rules, we can book a total of 5 slots each week. 3 of them during the week and 2 on weekends.&lt;/p&gt;&#xA;&lt;p&gt;Now that we know the manual booking process, let&amp;rsquo;s figure out how to automate this.&lt;/p&gt;&#xA;&lt;h3 id=&#34;getting-the-tools-ready&#34;&gt;Getting the tools ready&lt;/h3&gt;&#xA;&lt;p&gt;We will be using Python 3.9 for this project. We will be relying on Selenium for the automation. Let&amp;rsquo;s start by creating a brand new folder, creating a virtual environment in it, and installing selenium.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ mkdir booking_bot&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ cd booking_bot&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ python -m venv venv&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ source venv/bin/activate&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;$ pip install selenium&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Depending on which operating system you are using, you will have to download the respective Chrome webdriver as well. We will be using Chrome driver with selenium. You can go to the &lt;a href=&#34;https://chromedriver.chromium.org/&#34;&gt;official Chrome driver website&lt;/a&gt; and download the latest stable release for your operating system. You will end up with a zip file and the zip file will contain a binary called &amp;ldquo;chromedriver&amp;rdquo;. Put this binary in the &lt;code&gt;booking_bot&lt;/code&gt; folder.&lt;/p&gt;&#xA;&lt;p&gt;Now we can go ahead and start with the actual coding.&lt;/p&gt;&#xA;&lt;h3 id=&#34;getting-started-with-coding&#34;&gt;Getting started with coding&lt;/h3&gt;&#xA;&lt;p&gt;I generally open up the Python REPL and also keep an &lt;code&gt;app.py&lt;/code&gt; file open in the background. I test out new code in the REPL in an interactive fashion and then copy the code to the &lt;code&gt;app.py&lt;/code&gt; file. This makes the iteration loop very quick and I don&amp;rsquo;t have to continuously re-run the &lt;code&gt;app.py&lt;/code&gt; code with each small change. We will be doing the same here. Create an &lt;code&gt;app.py&lt;/code&gt; file in the &lt;code&gt;booking_bot&lt;/code&gt; folder and then run Python in a terminal.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s start by importing selenium, firing up a Chrome instance, and opening the NWBA login page in it:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; selenium &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; webdriver&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;url &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;https://northwestbadmintonacademy.sites.zenplanner.com/login.cfm&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;browser &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; webdriver&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Chrome(executable_path&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;./chromedriver&amp;#39;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;browser&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;get(url)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The executable path might be different based on which folder you are running Python in the terminal from and where your &lt;code&gt;chromedriver&lt;/code&gt; executable is saved. Modify the path accordingly.&lt;/p&gt;&#xA;&lt;p&gt;If everything goes well, you should now have a Chrome window open that says &amp;ldquo;Chrome is being controlled by automated test software&amp;rdquo;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;automating-login&#34;&gt;Automating login&lt;/h3&gt;&#xA;&lt;p&gt;The way automation with selenium works is that we need to tell selenium which HTML tags we want to interact with and what do we want to do with them. Automating the login involves telling Selenium which fields on the page are the username and password fields and what value do we want to pass on to them and then which button is the submit button.&lt;/p&gt;&#xA;&lt;p&gt;We can help Selenium find the relevant tags on the page in multiple ways. We can use any of the following methods:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;find_element_by_id&lt;/li&gt;&#xA;&lt;li&gt;find_element_by_name&lt;/li&gt;&#xA;&lt;li&gt;find_element_by_xpath&lt;/li&gt;&#xA;&lt;li&gt;find_element_by_link_text&lt;/li&gt;&#xA;&lt;li&gt;find_element_by_partial_link_text&lt;/li&gt;&#xA;&lt;li&gt;find_element_by_tag_name&lt;/li&gt;&#xA;&lt;li&gt;find_element_by_class_name&lt;/li&gt;&#xA;&lt;li&gt;find_element_by_css_selector&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;You can find complete documentation for each of these methods &lt;a href=&#34;https://selenium-python.readthedocs.io/locating-elements.html&#34;&gt;over here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;At this point, we can open up developer tools in Chrome and inspect the input field and see which method might suit our needs the best.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/image-20211023172200772.png&#34; alt=&#34;inspect login&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Based on the HTML code for the input fields, it seems like we can just use the &lt;code&gt;name&lt;/code&gt; attribute of the input tag to uniquely identify it.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;user_block &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; browser&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;find_element(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;name&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;username&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;pw_block &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; browser&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;find_element_by_name(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;password&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can pass in values for these fields using the &lt;code&gt;send_keys&lt;/code&gt; method:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;user_block&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;send_keys(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;your_email&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;pw_block&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;send_keys(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;your_password&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we need to uniquely identify the &amp;ldquo;Log In&amp;rdquo; button. I will show you how to use my favorite method to do that. We will be using XPath. They have never failed me and they are versatile enough to be used everywhere. XPath is a language used for locating nodes in an XML document and it works equally well in HTML as well. There is a little bit of syntax that you need to learn but most of the time a quick Google search for a particular use-case is enough.&lt;/p&gt;&#xA;&lt;p&gt;The &amp;ldquo;Log In&amp;rdquo; button has the type &lt;code&gt;SUBMIT&lt;/code&gt; and we will be locating it based on the type. The code for this is:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;submit_button = browser.find_element_by_xpath(&amp;#34;//input[@type=&amp;#39;SUBMIT&amp;#39;]&amp;#34;)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We are using &lt;code&gt;find_element_by_xpath&lt;/code&gt; method here as compared to &lt;code&gt;find_elements_by_xpath&lt;/code&gt;. This only returns one element. As for the XPath, &lt;code&gt;//&lt;/code&gt; tells selenium to find the input tag no matter how deeply nested it is in the document. The &lt;code&gt;type&lt;/code&gt; tells it to find only those input tags that have a type of &lt;code&gt;SUBMIT&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Clicking the submit button is now as easy as:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;submit_button.click()&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If everything goes well, this will redirect us to the Profile view.&lt;/p&gt;&#xA;&lt;h3 id=&#34;automating-calendar-interaction&#34;&gt;Automating calendar interaction&lt;/h3&gt;&#xA;&lt;p&gt;We need to figure out how to get from the profile view to the Calendar page. Thankfully there is a handy &lt;code&gt;Calendar&lt;/code&gt; button in the sidebar.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/image-20211023173608045-5110268.png&#34; alt=&#34;Profile view&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;We can locate this button in multiple ways using XPath. I will demonstrate two of them here just to show you the power of XPath. The first one is:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;calendar_btn = browser.find_element_by_xpath(&amp;#34;//td[@id=&amp;#39;idNavigation&amp;#39;]//li[2]/a&amp;#34;)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;//td[@id=&#39;idNavigation&#39;]&lt;/code&gt; returns the &lt;code&gt;td&lt;/code&gt; tags with the id of &lt;code&gt;idNavigation&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;//li[2]&lt;/code&gt; selects the second &lt;code&gt;li&lt;/code&gt; nested under the &lt;code&gt;td&lt;/code&gt; tag (counting starts from 1 in XPath)&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;/a&lt;/code&gt; selects the direct &lt;code&gt;a&lt;/code&gt; child of &lt;code&gt;li&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The second method is:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;calendar_btn = browser.find_element_by_xpath(&amp;#34;//a[text()=&amp;#39;Calendar&amp;#39;]&amp;#34;)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This selects the &lt;code&gt;a&lt;/code&gt; tag in the HTML document that has the text &lt;code&gt;Calendar&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;You can use whichever one you prefer and add the follow-up code for clicking the button:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;calendar_btn.click()&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This should take us to the Calendar page.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/reservation-list.png&#34; alt=&#34;Calendar home&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;This only shows one date but we want to navigate to whichever date we want. There are again two ways to do it. We can either click the arrow icons right next to the date or we can figure out the URL pattern for dates and recreate that ourselves. Just for a little bit of challenge, I will go with the latter option.&lt;/p&gt;&#xA;&lt;p&gt;Go ahead, copy the current URL, navigate to a different date and compare the two URLs and see what changed.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/annotated-reservation-list.png&#34; alt=&#34;image-20211024143358857&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;The initial URL was:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;https://northwestbadmintonacademy.sites.zenplanner.com/calendar.cfm?calendarType=PERSON:6C482159-B1D5-47E0-8427-CCCF2EC1DAC9&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The new URL is:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;https://northwestbadmintonacademy.sites.zenplanner.com/calendar.cfm?DATE=2021-10-25&amp;amp;calendarType=PERSON:6C482159-B1D5-47E0-8427-CCCF2EC1DAC9&amp;amp;VIEW=LIST&amp;amp;PERSONID=6C482159-B1D5-47E0-8427-CCCF2EC1DAC9&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Seems like there are two dynamic parts of the URL. The first one is the date and the second one is a &lt;code&gt;PERSON&lt;/code&gt; identifier. I wonder if we can get the &lt;code&gt;PERSON&lt;/code&gt; identifier from the HTML document. The identifier is a part of the initial URL as well so it seems like the Calendar button already has it. We can extract the identifier very easy:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;user_id = calendar_btn.get_attribute(&amp;#39;href&amp;#39;).split(&amp;#39;=&amp;#39;)[-1].split(&amp;#39;:&amp;#39;)[-1]&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We had already located the calendar button. We just needed the HREF attribute of that tag and Selenium makes it super easy to extract attributes from tags.&lt;/p&gt;&#xA;&lt;p&gt;We don&amp;rsquo;t need the whole HREF so we split it at &lt;code&gt;=&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[&amp;#39;https://northwestbadmintonacademy.sites.zenplanner.com/calendar.cfm?calendarType&amp;#39;, &amp;#39;PERSON:6C482159-B1D5-47E0-8427-CCCF2EC1DAC9&amp;#39;]&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We then take the latter half and split it at &lt;code&gt;:&lt;/code&gt; and take the last element from the returning list:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[&amp;#39;PERSON&amp;#39;, &amp;#39;6C482159-B1D5-47E0-8427-CCCF2EC1DAC9&amp;#39;]&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we can recreate the specific date URL ourselves:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;query_date = &amp;#34;2021-10-24&amp;#34;&#xA;calendar_date_link = f&amp;#34;https://northwestbadmintonacademy.sites.zenplanner.com/calendar.cfm?DATE={query_date}&amp;amp;calendarType=PERSON:{user_id}&amp;amp;VIEW=LIST&amp;amp;PERSONID={user_id}&amp;#34;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;While we are at it, let&amp;rsquo;s create a separate method to return the next 7 dates:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;import datetime&#xA;&#xA;def next_7_dates():&#xA;    today = datetime.datetime.today()&#xA;    date_list = []&#xA;    for x in range(0,7):&#xA;        new_date = today + datetime.timedelta(days=x)&#xA;        date_list.append(new_date.strftime(&amp;#39;%Y-%m-%d&amp;#39;))&#xA;    return date_list&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We use the &lt;a href=&#34;https://docs.python.org/3/library/datetime.html&#34;&gt;&lt;code&gt;datetime&lt;/code&gt;&lt;/a&gt; library to get today&amp;rsquo;s date and then use &lt;code&gt;timedelta&lt;/code&gt; to add more days to it and finally use &lt;code&gt;strftime&lt;/code&gt; to only extract the year (&lt;code&gt;%Y&lt;/code&gt;), month (&lt;code&gt;%m&lt;/code&gt;), and day (&lt;code&gt;%d&lt;/code&gt;) from it.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s look at the calendar itself now. We can click on any green date that has a few spots open and go to the final booking page:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/dev-tools-annotation-list.png&#34; alt=&#34;calendar time select&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;I generally prefer to play at 6 pm so we can add some logic where our automation bot looks at the available times and figures out if our favorite time is available or not. If it is not available it will then go to the next page. This is simple enough to code:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;booking_link = browser.find_element_by_xpath(&amp;#34;//div[text()=&amp;#39;6:00 PM&amp;#39;]&amp;#34;)&#xA;full = &amp;#39;sessionFull&amp;#39; in booking_link.get_attribute(&amp;#39;class&amp;#39;)&#xA;if not full:&#xA;    booking_link.click()&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We are making use of the building blocks that we have already learned about. We locate the &lt;code&gt;div&lt;/code&gt; tag that has our required time as &lt;code&gt;text&lt;/code&gt;. We then check if there are any slots available via the existence of &lt;code&gt;sessionFull&lt;/code&gt; class on the &lt;code&gt;div&lt;/code&gt; tag. If the timeslot is not full, we click on the booking link.&lt;/p&gt;&#xA;&lt;h3 id=&#34;automating-the-final-booking&#34;&gt;Automating the final booking&lt;/h3&gt;&#xA;&lt;p&gt;After clicking on one of the timeslot links, we should now be redirected to the final booking page. From here we just need to click on the &lt;code&gt;Reserve&lt;/code&gt; button and then verify that we got booked.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/dev-tools-calendar.png&#34; alt=&#34;Final reservation page&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;We can click on the &lt;code&gt;Reservation&lt;/code&gt; button using the following code:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;browser.find_element_by_xpath(&amp;#34;//a[text()=&amp;#39;Reserve&amp;#39;]&amp;#34;).click()&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Afterward, the page should refresh and you should see the following confirmation screen:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/booking-bot/dev-tools-calendar-2.png&#34; alt=&#34;Booking confirmation&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;We can check for the existence of the &lt;code&gt;Reserved&lt;/code&gt; div to confirm that our booking went through without a hitch:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;reserved = &amp;#34;Reserved&amp;#34; in browser.find_element_by_xpath(&amp;#34;//div[@class=&amp;#39;bold green&amp;#39;]&amp;#34;).text&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we have all the required pieces and we just need to put them in our &lt;code&gt;app.py&lt;/code&gt; file and give them some structure.&lt;/p&gt;&#xA;&lt;h3 id=&#34;final-code&#34;&gt;Final code&lt;/h3&gt;&#xA;&lt;p&gt;The final code looks something like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; datetime&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; selenium &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; webdriver&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; selenium.webdriver.support &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; expected_conditions&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; selenium.webdriver.support.ui &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; WebDriverWait&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;from&lt;/span&gt; selenium.webdriver.common.by &lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; By&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;next_7_dates&lt;/span&gt;():&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    today &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; datetime&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;datetime&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;today()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    date_list &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; x &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; range(&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        new_date &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; today &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; datetime&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;timedelta(days&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;x)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        date_list&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append(new_date&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;strftime(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;%Y-%m-&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;%d&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&lt;/span&gt;))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; date_list&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;login&lt;/span&gt;(browser):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    print(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;[+] Logging in.&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    browser&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;find_element(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;name&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;username&amp;#34;&lt;/span&gt;)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;send_keys(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;your_email&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    browser&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;find_element(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;name&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;password&amp;#34;&lt;/span&gt;)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;send_keys(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;your_password&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    browser&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;find_element(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;xpath&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;//input[@type=&amp;#39;SUBMIT&amp;#39;]&amp;#34;&lt;/span&gt;)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;click()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;reserve_time&lt;/span&gt;(browser, favorite_times):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; fav_time &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; favorite_times:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        booking_link &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; browser&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;find_element(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;xpath&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;//div[text()=&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;fav_time&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;]&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        full &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;sessionFull&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; booking_link&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;get_attribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;class&amp;#39;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;not&lt;/span&gt; full:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            booking_link&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;click()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;continue&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        browser&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;find_element(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;xpath&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;//a[text()=&amp;#39;Reserve&amp;#39;]&amp;#34;&lt;/span&gt;)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;click()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        reserved &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Reserved&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; browser&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;find_element(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;xpath&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;//div[@class=&amp;#39;bold green&amp;#39;]&amp;#34;&lt;/span&gt;)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;text&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; reserved:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;True&lt;/span&gt;, fav_time&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;False&lt;/span&gt;, &lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;main&lt;/span&gt;():&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    browser &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; webdriver&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Chrome(executable_path&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;r&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;/usr/local/bin/chromedriver&amp;#39;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    url &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;https://northwestbadmintonacademy.sites.zenplanner.com/login.cfm&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    browser&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;get(url)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    login(browser)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    timeout_secs &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;20&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    calendar_btn &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; WebDriverWait(browser, timeout_secs)\&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        &lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;until(expected_conditions&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;presence_of_element_located((By&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;XPATH, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;//td[@id=&amp;#39;idNavigation&amp;#39;]//li[2]//a&amp;#34;&lt;/span&gt;)))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    user_id &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; calendar_btn&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;get_attribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;href&amp;#39;&lt;/span&gt;)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;split(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;=&amp;#39;&lt;/span&gt;)[&lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;]&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;split(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;:&amp;#39;&lt;/span&gt;)[&lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    calendar_btn&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;click()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    favorite_times &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;5:00 PM&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;6:00 PM&amp;#34;&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    booked_details &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; count, date &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; enumerate(next_7_dates()):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; len(booked_details) &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;and&lt;/span&gt; count &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            print(&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;[+] Already booked 3 weekdays. Skipping &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;date&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;continue&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        print(&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;[+] Trying to look for timeslots on &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;date&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        calendar_date_link &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; (&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;https://northwestbadmintonacademy.sites.zenplanner.com/calendar.cfm?&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;DATE=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;date&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;amp;calendarType=PERSON:&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;user_id&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;amp;VIEW=LIST&amp;amp;PERSONID=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;user_id&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        browser&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;get(calendar_date_link)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        reserved, reservation_time &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; reserve_time(browser, favorite_times)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; reserved:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            booked_details&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append((date, reservation_time))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    print(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;[+] I was able to successfully reserve the following date/times:&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; date, reservation_time &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; booked_details:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        print(&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;\t&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;date&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;: &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{&lt;/span&gt;reservation_time&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; __name__ &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;__main__&amp;#34;&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    main()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The code is divided into 4 functions and most of them are self-explanatory. However, there are a few things in here that we did not discuss above. While running the final &lt;code&gt;app.py&lt;/code&gt;, I found out that &lt;code&gt;find_element_by_*&lt;/code&gt; methods are deprecated, and instead I should use the &lt;code&gt;find_element&lt;/code&gt; method.&lt;/p&gt;&#xA;&lt;p&gt;Moreover, I was encountering the &lt;code&gt;StaleElementReferenceException&lt;/code&gt; while locating the calendar button in the HTML. &lt;a href=&#34;https://stackoverflow.com/a/44914767&#34;&gt;This StackOverflow answer&lt;/a&gt; gives a very good explanation of this exception and also gives a solution. What was happening is that we were locating the calendar button while the browser was still finishing the logging in process and as soon as we tried to access the calendar button, it had become stale. In order to overcome this, we have to wait a bit for the calendar element to become present on the page after the logging-in process has already started. This way Selenium waits for the process to finish and makes sure the calendar button does not become stale before we try to access it.&lt;/p&gt;&#xA;&lt;p&gt;The code for this is:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;from selenium.webdriver.support import expected_conditions&#xA;from selenium.webdriver.support.ui import WebDriverWait&#xA;from selenium.webdriver.common.by import By&#xA;&#xA;# ....&#xA;&#xA;calendar_btn = WebDriverWait(browser, timeout_secs)\&#xA;                        .until(expected_conditions.presence_of_element_located((By.XPATH, &amp;#34;//td[@id=&amp;#39;idNavigation&amp;#39;]//li[2]//a&amp;#34;)))&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Selenium waits until the expected condition becomes true before it continues the execution of the rest of the code.&lt;/p&gt;&#xA;&lt;p&gt;We could have overcome this issue by adding an explicit &lt;code&gt;time.sleep(10)&lt;/code&gt; as well but the problem with that is the element might become available sooner than 10 seconds but we would not be able to do anything before the whole 10 seconds have elapsed.&lt;/p&gt;&#xA;&lt;p&gt;As for the code flow, we start execution with the main method. It creates the browser window and logs us in. It then loops through the next seven days and for each day it tries to book our favorite time. After booking one timeslot for a day it moves on to the next day and skips any other timeslots available for the same day. Before moving on to the next day, it also verifies that we haven&amp;rsquo;t booked more than 3 weekdays before moving on to the next weekday. Finally, it prints the slots that it was able to book.&lt;/p&gt;&#xA;&lt;p&gt;You might need to change two details in this code. One is the username and password values and the other is the &lt;code&gt;favorite_times&lt;/code&gt; list.&lt;/p&gt;&#xA;&lt;p&gt;Now you can run this script on Saturday morning as soon as the bookings open up and you should hopefully be able to snag a few good timeslots.&lt;/p&gt;&#xA;&lt;h3 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h3&gt;&#xA;&lt;p&gt;This was a fun project to explore a little bit about Selenium and I am hoping you learned something new from it. I like leaving people with some tips on how to further develop a tutorial project. There are so many ways you can improve this and a few things that come to mind are:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Make Chrome run in headless mode so that no window opens up on the screen&lt;/li&gt;&#xA;&lt;li&gt;Make it run automatically on Saturday so that you don&amp;rsquo;t even have to wake up (look into crontab or &lt;a href=&#34;https://yasoob.me/posts/github-actions-web-scraper-schedule-tutorial/&#34;&gt;scheduled GitHub Actions&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;li&gt;Add better error handling and maybe spawn multiple Selenium processes so that you can check multiple days in parallel&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The possibilities are endless! I hope you enjoyed this tutorial. You can download the complete source for the bot &lt;a href=&#34;https://github.com/yasoob/nwba-booking-bot&#34;&gt;from GitHub&lt;/a&gt;. If you liked this article, you can read similar fun stuff over at &lt;a href=&#34;https://yasoob.me&#34;&gt;my blog&lt;/a&gt;. See you later!&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>How to get a job in big-tech (Internships/New grads)?</title>
				<link>https://yasoob.me/posts/get-job-in-big-tech/</link>
				<pubDate>Wed, 22 Sep 2021 17:45:07 -0700</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/get-job-in-big-tech/</guid>
				<category>personal</category>
				<category>mentor</category>
				<description>Are you looking to break into big-tech? In this post, I share some tips and tricks that helped me get an internship + job at Microsoft. You don&amp;#39;t need to spend every waking minute grinding Leetcode. You can be smart and prepare for the interview a bit more strategically. Read the article to learn more.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/job-prep/header.png&#34; alt=&#34;How to get a job in big-tech (Internships/New grads)?&#34;&gt;&lt;/p&gt;&lt;p&gt;Hi all! &amp;#x1f44b;&lt;/p&gt;&#xA;&lt;p&gt;If you have been following me for a while then you might be aware that I work at Microsoft. Every so often I get asked by people about how to get a job in big tech. Some people have always dreamed about working for FAANG. Microsoft isn&amp;rsquo;t in FAANG but it comes as close as you can get. I will write down some of the common answers I have given to people over the last few months. Keep in mind that most of the advice in this post is based around my own experience interviewing and is in no way a foolproof guide on how your interview process would go.&lt;/p&gt;&#xA;&lt;p&gt;I have broken down the whole process in chronological order. Feel free to skip to whichever stage you are at right now.&lt;/p&gt;&#xA;&lt;h3 id=&#34;preparing-for-the-phone-screen&#34;&gt;Preparing for the Phone Screen&lt;/h3&gt;&#xA;&lt;p&gt;The first step is to prepare for the phone screen. Sometimes you will be lucky and the recruiter will only ask simple questions that have nothing to do with coding but sometimes you might be asked to go through a simple code screen. In this part of the article we will focus on preparing you for the code screen. Even though I had been programming for a good number of years before I did my first technical interview, I just didn&amp;rsquo;t have enough experience solving interview problems. There is no alternative to solving real algorithmic questions. However, you can be smart about how you go about doing it so that you don&amp;rsquo;t burn yourself out.&lt;/p&gt;&#xA;&lt;p&gt;Taking an algorithms course will help you understand the basic concepts but you definitely need to practice real interview questions. I personally hadn&amp;rsquo;t taken an algos course before I took my coding interview for Microsoft. I also did not grind Leetcode mindlessly. What I ended up doing was, I followed the &lt;a href=&#34;https://www.hackerrank.com/interview/interview-preparation-kit&#34;&gt;Interview prep track on HackerRank&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/job-prep/hacker-rank.png&#34; alt=&#34;Hacker Rank&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;I did not go through the whole question bank. I did enough to feel comfortable about solving most basic algorithm questions. After this stage I felt comfortable about passing a phone screen but not a real algo interview at big tech.&lt;/p&gt;&#xA;&lt;h3 id=&#34;preparing-for-behavioral-interview&#34;&gt;Preparing for behavioral Interview&lt;/h3&gt;&#xA;&lt;p&gt;After preparing for the phone screen you need to start practicing behavioral interview questions. Most people don&amp;rsquo;t realize how important this part is. I can be a fairly extroverted person when I have to be and even for me it was really important that I spent my time preparing for the behavioral portion of the interview. It sounds funny in hindsight but I was once doing a phone screen and the CEO on the other end asked me the most basic question: &amp;ldquo;Tell me about yourself&amp;rdquo;. I started telling her all about my background, where I am from, how interested I am in arts, and whatnot. I wasn&amp;rsquo;t aware that what she wanted to know was my technical background. She couldn&amp;rsquo;t care less about my family background and which part of the world I came from. This might be obvious to a few of you but it is not to everyone.&lt;/p&gt;&#xA;&lt;p&gt;A friend of mine who works at Google gave me a very useful tip. Most companies ask the same 10-15 questions. You need to prepare these questions really well. You can find question banks online which will tell you about some of these questions. The most important questions I prepared for my interview were:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Tell me about yourself.&lt;/li&gt;&#xA;&lt;li&gt;Tell me about a project you worked on.&lt;/li&gt;&#xA;&lt;li&gt;Why do you want to work here?&lt;/li&gt;&#xA;&lt;li&gt;Tell me about something new you recently learned?&lt;/li&gt;&#xA;&lt;li&gt;Tell me a time when you had a problem with a coworker?&lt;/li&gt;&#xA;&lt;li&gt;Do you have any questions for me?&lt;/li&gt;&#xA;&lt;li&gt;Tell about your weakness?&lt;/li&gt;&#xA;&lt;li&gt;Tell me about a time you failed and how did you deal with it?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Most of the interviews I have given so far revolved around the same questions. A few of the people did not even word the questions any differently!&lt;/p&gt;&#xA;&lt;p&gt;Now let&amp;rsquo;s talk about how to answer these questions.&lt;/p&gt;&#xA;&lt;p&gt;For the first one, you need to prepare an elevator pitch. Write it down. Don&amp;rsquo;t try to think of something on the fly. You need to trim your response to max a minute or a minute and a half. You will be surprized how quickly time passes when you start talking about yourself therefore it is imperative that you keep your response succint and to the point. Focus on your tech background and what you have done recently. I generally talk about how passionate I am about programming and how that passion led me to author two books. I also talk about what I am working on these days just to show I am still engaged with the field. Practice your delivery so that it sounds natural and not memorized.&lt;/p&gt;&#xA;&lt;p&gt;For 2, I just talk about my favorite project whichever that may be at the time.You can talk about some open source project you created in your free time or about a group project you did for one of your classes. Keep it short. If the interviewer is interested, they may ask followup questions.&lt;/p&gt;&#xA;&lt;p&gt;3 is easy. You can talk about how what the company is working on relates to what you want to do in life. For big tech it can be about the positive impact you can have on so many people. You might have a different opinion but we are not going to argue about that here. Chances are that big tech won&amp;rsquo;t even bother asking you this question. This is more useful for smaller startups. Do some research. Try to figure out what narrative the company is pushing for and talk about how excited that narrative makes you. This way you also show that you did your research and are actually invested in this interview. You can also talk about how you use some open source stuff the company maintains and it makes you excited about working for the company.&lt;/p&gt;&#xA;&lt;p&gt;4 can be anything. And I mean anything. I remember I talked about IPFS (InterPlanetary File System) when someone asked me this question. If you don&amp;rsquo;t know about it, check it out. It&amp;rsquo;s pretty neat piece of tech.&lt;/p&gt;&#xA;&lt;p&gt;For 5 I would probably talk about a group project I did.&lt;/p&gt;&#xA;&lt;p&gt;6 is particularly important in my opinion. I have seen people shy away from asking questions to the interviewer. I have asked all sorts of questions over the years and they have been received very well by the interviewers. I have asked:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;The last time you were looking for a job, why did you pick this place?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;What do you look for in a job and how has _____ helped meet those requirements?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Favorite project you have worked on?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Most difficult day at work?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;7 is tricky. Don&amp;rsquo;t just talk about a strength and make it sound like a weakness. Try to talk about an actual weakness which wouldn&amp;rsquo;t directly impact your ability to work at the company. I usually talk about my short attention span and I follow it up with an example of how I am trying to improve.&lt;/p&gt;&#xA;&lt;p&gt;8 is fairly self-explanatory. Think of a time you failed and talk about what you did to cope with it. I talk about how I tried to start a coding club in high school back in Pakistan but it didn&amp;rsquo;t work out as most kids didn&amp;rsquo;t see a real need for it. I coped with it by trying to start a coding club in college instead. It ended up being one of the best things I did and led to some really good friendships.&lt;/p&gt;&#xA;&lt;h3 id=&#34;getting-your-foot-in-the-door&#34;&gt;Getting your foot in the door&lt;/h3&gt;&#xA;&lt;p&gt;You have done the prep. Now you need to get that ellusive first interview with your favorite company. If you are from a big name university like Harvard, MIT or Stanford, you can go to your department career fairs and talk to recruiters from FAANG. Chances are you don&amp;rsquo;t need to put in any more effort and the recruiter would help make sure you get your shot at the first interview. But what should you do if you are from a lesser known place?&lt;/p&gt;&#xA;&lt;p&gt;You have two options. The first one is to look for alumni. If anyone from my college/university reaches out to me for a referral at Microsoft (or wherever I am working at when they reach out), chances are that I would recommend them after talking to them. A lot of people believe that you need to know the alumni really well to ask for a referral but that is not entirely true. Look for people on LinkedIn who are from your college and who work at companies where you want to work. Send them a polite message asking for a few minutes of their time to discuss what they work on. Even if half the people respond, it is still a very good number. Talk to them about their role at the company and tell them that you are interested in applying and if they have any advice. If they are willing to refer you, they will probably mention it then.&lt;/p&gt;&#xA;&lt;p&gt;The second option is to talk to your professors. Often times people don&amp;rsquo;t realize how resourceful their professors are. These are the same people whose classmates are now managers at different tech companies. If you have a good rapport with a professor, ask them for advice. Tell them that you are applying for internships/jobs and were wondering if they have a particular place in mind that might be a good fit for you. They will usually mention if they can refer you or not.&lt;/p&gt;&#xA;&lt;p&gt;From among these options, try to pick one where the referral is more direct and more senior. For instance, your professor might personally know a hiring manager at a company. If that is the case, take the referral from your professor rather than approaching an alumni. If an alumni is a hiring manager or works at a very senior position, take their referral. What I have observed is that if the referral goes to a hiring manager who directly knows the referee, you might have an easier time during the interview. You might also be able to skip a few interviews. Most big tech companies have around 5 rounds of interviews. I have seen people skip 2-3 interviews based on a referral. The more you skip, the less chances you will have of screwing up &amp;#x1f609;&lt;/p&gt;&#xA;&lt;h3 id=&#34;preparing-for-the-main-coding-interviews&#34;&gt;Preparing for the main coding interviews&lt;/h3&gt;&#xA;&lt;p&gt;Now that you have gotten your foot in the door, it is time to prepare for the main coding interview part. My assumption is that by this point you already have some grasp of typical algorithm questions. We want to focus on fast-tracking your coding interview prep for a specific company. Let&amp;rsquo;s suppose you have a Google interview coming up. Go to Google and search for &amp;ldquo;top Google Leetcode questions&amp;rdquo;&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/job-prep/google-search.png&#34; alt=&#34;Google search&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Now open any of these links and look at what questions Google asks. You don&amp;rsquo;t need to grind all Leetcode questions as I think you can better spend your time doing something else. Focus on the top 10-20 questions. Read the questions and try solving them. If you can&amp;rsquo;t solve them, look at the solution and try to understand it. Afterwards, try writing the solution yourself without any help. I can&amp;rsquo;t stress how important it is to write out the solution in an IDE and not just assume that once you have read the solution you know how it all works. It also helps build your muscle memory.&lt;/p&gt;&#xA;&lt;p&gt;You can also look at Glassdoor and Reddit to get a sense of what a particular company tests the interviewees on. This is very useful in mentally preparing yourself.&lt;/p&gt;&#xA;&lt;p&gt;The main takeaway we are aiming to get out of this exercise is to figure out what kind of questions your specific company likes to ask. You will see a pattern once you have done 10-20 questions. It might be that Google likes to focus on graphs and trees quiet a lot. Make sure you know these topics very well and can solve new questions. After a little bit of more targetted practice, you will be ready.&lt;/p&gt;&#xA;&lt;h3 id=&#34;interview-scheduling&#34;&gt;Interview scheduling&lt;/h3&gt;&#xA;&lt;p&gt;The only advice I have on this front is that make sure you don&amp;rsquo;t schedule the interview with your favorite company as the first interview you will be giving in an interview cycle. Schedule some interviews with slightly less desirable companies before that. You will learn a lot while going through the interview cycle and you can use those learnings to improve your chances of having a fantastic interview with your dream company.&lt;/p&gt;&#xA;&lt;p&gt;If you believe that your first interview would go without any hiccups, please be prepared. I bombed the first interview in my interview cycle with a major company. I knew the answer to the question I was being asked but just because I hadn&amp;rsquo;t practiced it by typing out the solution, I blanked out. It was very embarrasing &amp;#x1f61c; That is why writing out the solutions during practice is paramount and doing interviews with your favourite companies later on in the cycle is important.&lt;/p&gt;&#xA;&lt;h3 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h3&gt;&#xA;&lt;p&gt;We all believe that the tech interview cycle is broken. Most of the time you will not be touching similar Leetcode stuff during your day to day job. But till the interview cycle is fixed, the best we can do is to learn how to play well with the pre-existing system.&lt;/p&gt;&#xA;&lt;p&gt;A lot of advice here might seem a bit too blunt and direct. I have tried to distill my knowledge in a few paragraphs. Also do keep in mind that this is just my perspective on big tech interviews. Your mileage may vary so make sure you are well prepared for whatever comes your way.&lt;/p&gt;&#xA;&lt;p&gt;If you have any feedback or anything useful to add to this discussion, please comment below. I would love to hear your take on this topic &amp;#x1f60a;&lt;/p&gt;&#xA;&lt;p&gt;Until next time. Take care! &amp;#x1f44b; &amp;#x2764;&amp;#xfe0f;&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>How to web scrape on Schedule using Github Actions?</title>
				<link>https://yasoob.me/posts/github-actions-web-scraper-schedule-tutorial/</link>
				<pubDate>Wed, 04 Aug 2021 13:24:54 +0500</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/github-actions-web-scraper-schedule-tutorial/</guid>
				<category>programming</category>
				<category>python</category>
				<category>GitHub</category>
				<description>I recently got to work on a web scraping project that I deployed on GitHub. The scraper runs daily on a schedule and emails the extracted data all for free using GitHub Actions! In this article, I will show you how I developed this project and how you too can make use of GitHub Actions for free.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/github-actions/hero.png&#34; alt=&#34;How to web scrape on Schedule using Github Actions?&#34;&gt;&lt;/p&gt;&lt;p&gt;Hi everyone! &amp;#x1f44b; It&amp;rsquo;s been a long time since I last posted on this blog. I was busy graduating from college and moving places and that didn&amp;rsquo;t leave enough time for fun new projects. I am still in the middle of it all but recently did a project that gave me a tutorial idea to write about. I was asked to create a web scraper that would scrape a certain website, filter the data and then send an email with that data. I will show you what I was tasked with, how I developed it, and how I deployed it for free using GitHub Actions.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can find the corresponding GitHub repo &lt;a href=&#34;https://github.com/yasoob/github-action-scraper-tutorial/&#34;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;requirements&#34;&gt;Requirements&lt;/h2&gt;&#xA;&lt;p&gt;I was asked if I could write an application that would monitor this &lt;a href=&#34;https://ppra.org.pk/&#34;&gt;website below&lt;/a&gt; and extract tender information and email only the latest tenders to an email id. I explored the website and quickly agreed.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/github-actions/ppra-homepage.png&#34; alt=&#34;PPRA homepage&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;h2 id=&#34;plan-of-action&#34;&gt;Plan of Action&lt;/h2&gt;&#xA;&lt;p&gt;I had come across some fun projects by the likes of &lt;a href=&#34;https://github.com/simonw/package-stats/blob/main/.github/workflows/fetch_stats.yml&#34;&gt;Simon Wilson&lt;/a&gt; and wanted to test out GitHub Actions for myself. What better way to test it out than deploying a working scraper that automatically runs on a schedule and emails the scraped data?&lt;/p&gt;&#xA;&lt;p&gt;The first step is to download the web page using Python and pull out the table into a more useable data structure. I opted for regex initially and then settled on Pandas for the initial extraction.&lt;/p&gt;&#xA;&lt;p&gt;The next step is to email the parsed data. For that, I am going to rely on a &lt;a href=&#34;https://github.com/marketplace/actions/send-email&#34;&gt;GitHub action created by Dawid Dziurla&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;installing-the-required-libraries&#34;&gt;Installing the required libraries&lt;/h2&gt;&#xA;&lt;p&gt;We will be making use of the following two libraries:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;pandas&lt;/li&gt;&#xA;&lt;li&gt;requests&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Go ahead and add both of these libraries into a &lt;code&gt;requirements.txt&lt;/code&gt; file in the root of your project directory/repository and install them if you haven&amp;rsquo;t already. Later on, we will be using this file to install these dependencies in the GitHub Actions execution environment.&lt;/p&gt;&#xA;&lt;h2 id=&#34;writing-the-scraper&#34;&gt;Writing the scraper&lt;/h2&gt;&#xA;&lt;p&gt;This is by far the most time-consuming part of the whole process. However, it is pretty simple once you know what you are doing. The first step is to figure out the URL of the tenders page. The website uses AJAX so going to the tenders page does not change the URL in the address bar. To find the actual URL, we can open up Developer Tools and look at the requests made while navigating to the tenders page.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/github-actions/network-manager.png&#34; alt=&#34;Network Manager&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;This first URL is the direct URL of the tenders page but it does not have a page number in the URL. For it to use the page number as well we can navigate to the 2nd page of the tenders and take a look at the new request (notice the &lt;code&gt;PageNo=2&lt;/code&gt; at the end of the URL). We can now follow the pattern of this request to query for however many pages we want.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/github-actions/network-manager-2.png&#34; alt=&#34;Network manager 2&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;At this point, we can write some Python code to download the page using &lt;a href=&#34;https://docs.python-requests.org/en/master/&#34;&gt;requests&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; requests &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; r&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;html &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; r&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;get(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https://ppra.org.pk/dad_tenders.asp?PageNo=1&amp;#39;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now that we know how to query for different pages, we need to figure out how to parse the table. I initially tried using regex as for such simple use cases it has always worked out pretty well for me. I know about &lt;a href=&#34;https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags&#34;&gt;this SO answer&lt;/a&gt; but we are parsing a known, limited subset of HTML so it is perfectly fine to use regex for that.&lt;/p&gt;&#xA;&lt;p&gt;However, regex posed a few issues. It wasn&amp;rsquo;t working exactly the way I wanted it to. I had forgotten about the &lt;code&gt;re.DOTALL&lt;/code&gt; flag while writing my initial pattern and my regex pattern wasn&amp;rsquo;t working past the &lt;code&gt;\n&lt;/code&gt; character. Instead of fixing this issue, I decided to give Pandas a try. I had heard that you could easily parse an HTML table using Pandas but I had never tried it so I thought about giving that a try instead.&lt;/p&gt;&#xA;&lt;p&gt;My main motivation for taking on new projects is that I get to explore and learn new stuff and then write about it on this blog so I actively try to opt for new methods even if I know the old method works perfectly fine. You will never learn about new and better ways if you don&amp;rsquo;t explore, right?&lt;/p&gt;&#xA;&lt;p&gt;Using Pandas is extremely straightforward. We can use the following snippet to parse the tables in the document:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; pandas &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; pd&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;dfs &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; pd&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;read_html(html&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;text)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;However, by only supplying the HTML to &lt;code&gt;read_html&lt;/code&gt; method, Pandas extracts all the tables from the page. In my testing, this resulted in 4 tables.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; dfs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[                                                   &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;  Please Click on image to Download&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;View&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt; Only &lt;span style=&#34;color:#ae81ff&#34;&gt;1.&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;..&lt;/span&gt;,                        &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;                                                  &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;  Tender Closing Date :  Month January  Feburay  March  April  May  Jun&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;,                   &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;  PPRA Ref No: TSE,             &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;                                                  &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;         &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;                &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;                      &lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;   Tender No                                    Tender  Details  Download  Advertised Date           Closing Date&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;   TS455000E  Pakistan Aeronautical Complex, Kamra Procureme&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;   &lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;10&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;   TS454835E  Pakistan State Oil, Karachi Miscellaneous Work&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;    &lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;15&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; PM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;   TS453722E  State Life Insurance Corporation of Pakistan, &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;              &lt;span style=&#34;color:#ae81ff&#34;&gt;24&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;   TS453262E  Sui Southern Gas Company Limited, Karachi SSGC&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;   &lt;span style=&#34;color:#ae81ff&#34;&gt;23&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; PM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;   TS455691E  National Database &lt;span style=&#34;color:#f92672&#34;&gt;and&lt;/span&gt; Registration Authority N&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;16&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt;   TS453260E  Sui Southern Gas Company Limited, Karachi SSGC&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;23&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;12&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; PM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;   TS456503E  National Heritage &lt;span style=&#34;color:#f92672&#34;&gt;&amp;amp;&lt;/span&gt; Intrigation Division, Isla&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;24&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To only extract the table we need, we can tell Pandas to extract the table with the width attribute set to 656. There is only one table in the whole HTML with that specific attribute value so it only results in 1 extracted table.&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;dfs = pd.read_html(html.text, attrs={&amp;#39;width&amp;#39;: &amp;#39;656&amp;#39;})&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; dfs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[            &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;                                                  &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;         &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;                &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;                      &lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;   Tender No                                    Tender  Details  Download  Advertised Date           Closing Date&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;   TS456131E  Sui Southern Gas Company Limited, Karachi Supp&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;   &lt;span style=&#34;color:#ae81ff&#34;&gt;25&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; PM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;   TS456477E  National Accountability Bureau, Sukkur Service&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;16&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;   TS456476E  Sukkur Electric Power Company (SEPCO), Sukkur &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;12&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;   TS456475E  Evacuee Trust Property Board, Multan Services &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;17&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;10&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;   TS456474E  Military Engineering Services (Navy), Karachi &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;13&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt;   TS456473E  National University of Science &lt;span style=&#34;color:#f92672&#34;&gt;and&lt;/span&gt; Technology,&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;17&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;   TS456490E  Shaikh Zayed Hospital, Lahore Miscellaneous Wo&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;19&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;   TS456478E  Ministry of Religious Affairs &lt;span style=&#34;color:#f92672&#34;&gt;&amp;amp;&lt;/span&gt; Interfaith Har&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;16&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;9&lt;/span&gt;   TS456489E  Cantonment Board, Rawalpindi Services Required&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;17&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;12&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; PM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;10&lt;/span&gt;  TS456480E  National Bank of Pakistan, Lahore Miscellaneou&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;16&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;  TS456481E  National Bank of Pakistan, Lahore Miscellaneou&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;       NaN        &lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt;  &lt;span style=&#34;color:#ae81ff&#34;&gt;16&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2021&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;00&lt;/span&gt; AM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;There are still a few issues with this extraction.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Pandas isn&amp;rsquo;t able to automatically extract header for our table&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;Advertised Date&lt;/code&gt; column data isn&amp;rsquo;t parsed as a date&lt;/li&gt;&#xA;&lt;li&gt;Download column is all &lt;code&gt;NaN&lt;/code&gt;s&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;To fix the first issue, we can pass in the &lt;code&gt;header&lt;/code&gt; parameter to &lt;code&gt;read_html&lt;/code&gt; and Pandas will make the respective row the header of the table. The second issue can be fixed by passing in &lt;code&gt;parse_dates&lt;/code&gt; parameter and Pandas will parse the data in the respective column as dates. There are multiple ways to resolve the third issue. I ended up using regex to extract the download links into a list and then assigning that list to the &lt;code&gt;Download&lt;/code&gt; column in our data frame.&lt;/p&gt;&#xA;&lt;p&gt;The &lt;code&gt;read_html&lt;/code&gt; method call looks something like this after fixing the first two issues:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;dfs &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; pd&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;read_html(html&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;text, attrs&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;width&amp;#39;&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;656&amp;#39;&lt;/span&gt;}, header&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;, parse_dates&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Advertised Date&amp;#39;&lt;/span&gt;])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The regex for extracting the &lt;code&gt;Download&lt;/code&gt; links and assigning them to the &lt;code&gt;Download&lt;/code&gt; column looks like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;download_links &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; re&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;findall(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;lt;a target=&amp;#34;_blank&amp;#34; href=&amp;#34;(.+?)&amp;#34;&amp;gt;&amp;lt;img border=&amp;#34;0&amp;#34; src=&amp;#34;images/(?:.+?)&amp;#34;&amp;gt;&amp;lt;/a&amp;gt;&amp;#39;&lt;/span&gt;,html&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;text)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;download_links &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;lt;a href=&amp;#39;https://ppra.org.pk/&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt;link&lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#39; style=&amp;#39;display: block;text-align: center;&amp;#39;&amp;gt; &amp;lt;img src=&amp;#39;https://ppra.org.pk/images/download_icon.gif&amp;#39;/&amp;gt;&amp;lt;/a&amp;gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; link &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; download_links]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;tender_table &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; dfs[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;tender_table[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Download&amp;#39;&lt;/span&gt;] &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; download_links&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The extracted links are relative so we can use list comprehension to prepend the actual URL to the extracted link. I am converting the link into an anchor tag and encapsulating an image with that because of two reasons. Firstly, it would look nice in our final email, and secondly, the table would look similar to what our client is used to seeing on the website so there would be less visual fatigue while looking at the email.&lt;/p&gt;&#xA;&lt;p&gt;The client asked me to generate emails with the tenders for the latest date only. The tenders for the latest date sometimes span multiple pages so we can put all the code we have so far into a separate function and then pass in page numbers to that function to extract the tables from a specific page.&lt;/p&gt;&#xA;&lt;p&gt;The code with the function looks like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;import requests as r&#xA;import pandas as pd&#xA;import re&#xA;&#xA;url_template = &amp;#34;https://ppra.org.pk/dad_tenders.asp?PageNo=&amp;#34;&#xA;&#xA;def download_parse_table(url):&#xA;    html = r.get(url)&#xA;    dfs = pd.read_html(html.text, attrs={&amp;#39;width&amp;#39;: &amp;#39;656&amp;#39;}, header=0, parse_dates=[&amp;#39;Advertised Date&amp;#39;])&#xA;    download_links = re.findall(&amp;#39;&amp;lt;a target=&amp;#34;_blank&amp;#34; href=&amp;#34;(.+?)&amp;#34;&amp;gt;&amp;lt;img border=&amp;#34;0&amp;#34; src=&amp;#34;images/(?:.+?)&amp;#34;&amp;gt;&amp;lt;/a&amp;gt;&amp;#39;,html.text)&#xA;    download_links = [&amp;#34;&amp;lt;a href=&amp;#39;https://ppra.org.pk/&amp;#34;+link+&amp;#34;&amp;#39; style=&amp;#39;display: block;text-align: center;&amp;#39;&amp;gt; &amp;lt;img src=&amp;#39;https://ppra.org.pk/images/download_icon.gif&amp;#39;/&amp;gt;&amp;lt;/a&amp;gt;&amp;#34; for link in download_links]&#xA;    tender_table = dfs[0]&#xA;    tender_table[&amp;#39;Download&amp;#39;] = download_links&#xA;    return tender_table&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To put all the extracted tables into one data frame, we need to put them all into a list and use the &lt;a href=&#34;https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html&#34;&gt;&lt;code&gt;pd.concat&lt;/code&gt; method&lt;/a&gt;. The code for that looks like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;combined_df = []&#xA;for index in range(1,8):&#xA;    df = download_parse_table(url_template+str(index))&#xA;    combined_df.append(df)&#xA;&#xA;combined_df = pd.concat(combined_df)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; combined_df&#xA;    Tender No                                    Tender  Details                                           Download Advertised Date           Closing Date&#xA;0   TS455000E  Pakistan Aeronautical Complex, Kamra Procureme...  &amp;lt;a href=&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-30   4/8/2021 10:30:00 AM&#xA;1   TS454835E  Pakistan State Oil, Karachi Miscellaneous Work...  &amp;lt;a href=&amp;#39;https://ppra.org.pk/doc/30-7/42pso307...      2021-07-30    5/8/2021 2:15:00 PM&#xA;2   TS453722E  State Life Insurance Corporation of Pakistan, ...  &amp;lt;a href=&amp;#39;https://ppra.org.pk/doc/30-7/42life30...      2021-07-30              24/8/2021&#xA;3   TS453262E  Sui Southern Gas Company Limited, Karachi SSGC...  &amp;lt;a href=&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-30   23/8/2021 3:00:00 PM&#xA;4   TS455691E  National Database and Registration Authority N...  &amp;lt;a href=&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-30  16/8/2021 11:00:00 AM&#xA;..        ...                                                ...                                                ...             ...                    ...&#xA;25  TS456443E  Civil Aviation Authority, Karachi TENDER NOTIC...  &amp;lt;a href=&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-29  13/8/2021 11:00:00 AM&#xA;26  TS454178E  Zarai Taraqiati Bank Ltd (ZTBL), Islamabad Inf...  &amp;lt;a href=&amp;#39;https://ppra.org.pk/doc/28-7/ztb287-1...      2021-07-28  10/8/2021 11:00:00 AM&#xA;27  TS454566E  Sui Northern Gas Pipelines Limited, Lahore Rel...  &amp;lt;a href=&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-28    1/9/2021 3:30:00 PM&#xA;28  TS455579E  Pakistan Ordnance Factories, Wah Cantt Repair ...  &amp;lt;a href=&amp;#39;https://ppra.org.pk/doc/28-7/pof287-4...      2021-07-28   4/8/2021 10:20:00 AM&#xA;29  TS455365E  Pakistan National Shipping Corporation (PNSC),...  &amp;lt;a href=&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-28  24/8/2021 11:00:00 AM&#xA;&#xA;[210 rows x 5 columns]&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It looks mostly fine but there is one issue. The index is preserved after the &lt;code&gt;concat&lt;/code&gt;. I want to reset it so that it goes from 0-209 instead of 0-29 multiple times. This is also easy to acomplish. We just need to modify the &lt;code&gt;concat&lt;/code&gt; method call like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;combined_df &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; pd&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;concat(combined_df)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;reset_index(drop&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;True&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; combined_df&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     Tender No                                    Tender  Details                                           Download Advertised Date           Closing Date&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;    TS455000E  Pakistan Aeronautical Complex, Kamra Procureme&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;a href&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-30   4/8/2021 10:30:00 AM&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;    TS454835E  Pakistan State Oil, Karachi Miscellaneous Work&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;a href&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https://ppra.org.pk/doc/30-7/42pso307...      2021-07-30    5/8/2021 2:15:00 PM&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;    TS453722E  State Life Insurance Corporation of Pakistan, &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;a href&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https://ppra.org.pk/doc/30-7/42life30...      2021-07-30              24/8/2021&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;    TS453262E  Sui Southern Gas Company Limited, Karachi SSGC&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;a href&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-30   23/8/2021 3:00:00 PM&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;    TS455691E  National Database &lt;span style=&#34;color:#f92672&#34;&gt;and&lt;/span&gt; Registration Authority N&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;a href&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-30  16/8/2021 11:00:00 AM&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;..&lt;/span&gt;         &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;                                                &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;                                                &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;             &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;                    &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;205&lt;/span&gt;  TS456443E  Civil Aviation Authority, Karachi TENDER NOTIC&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;a href&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-29  13/8/2021 11:00:00 AM&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;206&lt;/span&gt;  TS454178E  Zarai Taraqiati Bank Ltd (ZTBL), Islamabad Inf&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;a href&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https://ppra.org.pk/doc/28-7/ztb287-1...      2021-07-28  10/8/2021 11:00:00 AM&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;207&lt;/span&gt;  TS454566E  Sui Northern Gas Pipelines Limited, Lahore Rel&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;a href&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-28    1/9/2021 3:30:00 PM&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;208&lt;/span&gt;  TS455579E  Pakistan Ordnance Factories, Wah Cantt Repair &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;a href&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https://ppra.org.pk/doc/28-7/pof287-4...      2021-07-28   4/8/2021 10:20:00 AM&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;209&lt;/span&gt;  TS455365E  Pakistan National Shipping Corporation (PNSC),&lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;  &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;a href&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https://ppra.org.pk/download.asp?tend...      2021-07-28  24/8/2021 11:00:00 AM&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[&lt;span style=&#34;color:#ae81ff&#34;&gt;210&lt;/span&gt; rows x &lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt; columns]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This looks much better!&lt;/p&gt;&#xA;&lt;p&gt;Next we need to filter this data for the latest date. We can do that using just two lines:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;latest_date &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; combined_df&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;iloc[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;][&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Advertised Date&amp;#39;&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;filtered_df &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; combined_df[combined_df[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Advertised Date&amp;#39;&lt;/span&gt;] &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; latest_date]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We first extract the latest date which is the &lt;code&gt;Advertised Date&lt;/code&gt; of the first item in the table and then filter the rest of the table using that value.&lt;/p&gt;&#xA;&lt;p&gt;Now we can convert this into an HTML table. Pandas does not create a full HTML document so we need to create one ourselves and then embed the Pandas output in it:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;html_string = &amp;#34;&amp;#34;&amp;#34;&#xA;    &amp;lt;html&amp;gt;&#xA;    &amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Latest PPRA Tenders&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&#xA;    &amp;lt;body&amp;gt;&#xA;            &amp;lt;style&amp;gt;&#xA;        table {&#xA;            border-collapse: collapse;&#xA;            border: 1px solid silver;&#xA;        }&#xA;        table tr:nth-child(even) {&#xA;            background: #E0E0E0;&#xA;        }&#xA;        &amp;lt;/style&amp;gt;&#xA;        %s&#xA;    &amp;lt;/body&amp;gt;&#xA;    &amp;lt;/html&amp;gt;&#xA;&amp;#34;&amp;#34;&amp;#34;&#xA;&#xA;table_html = filtered_df.to_html(index=False,render_links=True, justify=&amp;#34;center&amp;#34;, &#xA;    escape=False, border=4)&#xA;with open(&amp;#39;ppra.html&amp;#39;, &amp;#39;w&amp;#39;) as f:&#xA;    f.write(html_string %(table_html))&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I used the &lt;code&gt;%s&lt;/code&gt; string interpolation method because I have some &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tags with &lt;code&gt;{}&lt;/code&gt; braces and it confuses Python if I use the f-strings.&lt;/p&gt;&#xA;&lt;p&gt;After running what we have so far, the output (&lt;code&gt;ppra.html&lt;/code&gt;) looks like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/github-actions/output-table.png&#34; alt=&#34;Output Table&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;There is one issue, the &lt;code&gt;Tender Details&lt;/code&gt; column looks very cluttered. Instead of putting the details data in a single font-weight and on the same line, we need to break it up as they do on the original website. The easiest way to do that is to extract the details using regex and then replace the details in the data frame with the extracted ones.&lt;/p&gt;&#xA;&lt;p&gt;The regex for details extraction looks something like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;details = re.findall(&amp;#39;&amp;lt;td bgcolor=&amp;#34;(?:.+?)&amp;#34; width=&amp;#34;305&amp;#34;&amp;gt;(.+?)&amp;lt;/td&amp;gt;&amp;#39;, html.text, re.DOTALL)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The detail cells have a specific width so we extract the data based on that. We use &lt;code&gt;re.DOTALL&lt;/code&gt; because the details span multiple lines and we want &lt;code&gt;.&lt;/code&gt; to match the carriage return (&lt;code&gt;\r&lt;/code&gt;) and newline character (&lt;code&gt;\n&lt;/code&gt;) as well. The extracted details contain &lt;code&gt;\r\n&lt;/code&gt; and we can get rid of them using this list comprehension:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;details = [detail.replace(&amp;#39;\r\n&amp;#39;,&amp;#39;&amp;#39;) for detail in details]&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let&amp;rsquo;s assign this details list to our data frame:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;tender_table[&amp;#34;Tender  Details&amp;#34;] = details&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;final-scraper-code&#34;&gt;Final scraper code&lt;/h2&gt;&#xA;&lt;p&gt;The final scraper code looks like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; requests &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; r&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; pandas &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; pd&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; re&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;url_template &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;https://ppra.org.pk/dad_tenders.asp?PageNo=&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;html_string &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    &amp;lt;html&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    &amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Latest PPRA Tenders&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    &amp;lt;body&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;lt;style&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        table {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;            border-collapse: collapse;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;            border: 1px solid silver;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        table tr:nth-child(even) {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;            background: #E0E0E0;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;lt;/style&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;%s&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    &amp;lt;/body&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    &amp;lt;/html&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;download_parse_table&lt;/span&gt;(url):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    html &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; r&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;get(url)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    details &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; re&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;findall(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;lt;td bgcolor=&amp;#34;(?:.+?)&amp;#34; width=&amp;#34;305&amp;#34;&amp;gt;(.+?)&amp;lt;/td&amp;gt;&amp;#39;&lt;/span&gt;, html&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;text, re&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;DOTALL)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    details &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [detail&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;replace(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;\r\n&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&lt;/span&gt;,&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;) &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; detail &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; details]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    dfs &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; pd&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;read_html(html&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;text, attrs&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;width&amp;#39;&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;656&amp;#39;&lt;/span&gt;}, header&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;, &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        parse_dates&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Advertised Date&amp;#39;&lt;/span&gt;])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    download_links &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; re&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;findall(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;lt;a target=&amp;#34;_blank&amp;#34; href=&amp;#34;(.+?)&amp;#34;&amp;gt;&amp;lt;img border=&amp;#34;0&amp;#34; src=&amp;#34;images/(?:.+?)&amp;#34;&amp;gt;&amp;lt;/a&amp;gt;&amp;#39;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        html&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;text)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    download_links &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;lt;a href=&amp;#39;https://ppra.org.pk/&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt;link&lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#39; style=&amp;#39;display: block;text-align: center;&amp;#39;&amp;gt; &amp;lt;img src=&amp;#39;https://ppra.org.pk/images/download_icon.gif&amp;#39;/&amp;gt;&amp;lt;/a&amp;gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; link &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; download_links]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    tender_table &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; dfs[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    tender_table[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Download&amp;#39;&lt;/span&gt;] &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; download_links&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    tender_table[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Tender  Details&amp;#34;&lt;/span&gt;] &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; details&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; tender_table&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;combined_df &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; []&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; index &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; range(&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;8&lt;/span&gt;):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    df &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; download_parse_table(url_template&lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt;str(index))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    combined_df&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;append(df)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;combined_df &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; pd&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;concat(combined_df)&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;reset_index(drop&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;True&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;latest_date &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; combined_df&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;iloc[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;][&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Advertised Date&amp;#39;&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;filtered_df &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; combined_df[combined_df[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;Advertised Date&amp;#39;&lt;/span&gt;] &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; latest_date]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;table_html &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; filtered_df&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;to_html(index&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;False&lt;/span&gt;,render_links&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;True&lt;/span&gt;, justify&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;center&amp;#34;&lt;/span&gt;, &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    escape&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;False&lt;/span&gt;, border&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;with&lt;/span&gt; open(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;ppra.html&amp;#39;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;w&amp;#39;&lt;/span&gt;) &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; f:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    f&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;write(html_string &lt;span style=&#34;color:#f92672&#34;&gt;%&lt;/span&gt;(table_html))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;getting-started-with-github-action&#34;&gt;Getting started with Github Action&lt;/h2&gt;&#xA;&lt;p&gt;I am going to keep this intro to GitHub Actions very short. GitHub Actions have a concept of workflows. Actions will execute workflows. These workflows are contained inside the &lt;code&gt;.github/workflows&lt;/code&gt; folder in the root of the repo and list the steps we want Actions to execute. I went ahead and created a &lt;code&gt;.github/workflows&lt;/code&gt; folder in my project root and then created a &lt;code&gt;scrape.yml&lt;/code&gt; file inside the &lt;code&gt;workflows&lt;/code&gt; folder. GH Actions would make more sense if I show you the complete YAML file and then explain it.&lt;/p&gt;&#xA;&lt;p&gt;The contents of the &lt;code&gt;scrape.yml&lt;/code&gt; file are this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;name: Scrape&#xA;&#xA;on:&#xA;  schedule:&#xA;    - cron: &amp;#34;0 4 * * *&amp;#34;&#xA;  workflow_dispatch:&#xA;&#xA;env:&#xA;  ACTIONS_ALLOW_UNSECURE_COMMANDS: true&#xA;&#xA;jobs:&#xA;  scrape-latest:&#xA;    runs-on: ubuntu-latest&#xA;&#xA;    steps:&#xA;      - name: Checkout repo&#xA;        uses: actions/checkout@v2&#xA;      - name: Set up Python&#xA;        uses: actions/setup-python@v2.0.0&#xA;        with:&#xA;          python-version: &amp;#39;3.7&amp;#39;&#xA;      - name: Install requirements&#xA;        run: pip install -r requirements.txt&#xA;      - name: Run Scraper&#xA;        run: python scraper.py&#xA;      - name: Set env vars&#xA;        run: |&#xA;          echo &amp;#34;DATE=$(python -c &amp;#39;import datetime as dt; print(dt.datetime.now().date())&amp;#39;)&amp;#34; &amp;gt;&amp;gt; $GITHUB_ENV&#xA;      - name: Send mail&#xA;        uses: dawidd6/action-send-mail@v3&#xA;        with:&#xA;          server_address: smtp.gmail.com&#xA;          server_port: 465&#xA;          username: ${{secrets.MAIL_USERNAME}}&#xA;          password: ${{secrets.MAIL_PASSWORD}}&#xA;          subject: Latest PPRA tenders for ${{env.DATE}}&#xA;          to: hi@yasoob.me&#xA;          from: Automated Email&#xA;          ignore_cert: true&#xA;          secure: true&#xA;          html_body: file://ppra.html&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We start by naming the Action. In our case, we named it &lt;code&gt;Scrape&lt;/code&gt;. Next, we tell GitHub when to execute this action. The first time is via a cron schedule and the second is via the online workflow dispatcher. The cron value is similar to the crontab you might have used on Linux. You can use &lt;a href=&#34;https://crontab.guru/&#34;&gt;Crontab Guru&lt;/a&gt; to explore crontabs. The one I am using will cause the workflow to run every day at 4 o&amp;rsquo;clock. This is in UTC. The &lt;code&gt;workflow_dispatch&lt;/code&gt; is used just for testing. This way we don&amp;rsquo;t have to wait until 4 o&amp;rsquo;clock just to test it and can trigger the workflow manually using the online interface.&lt;/p&gt;&#xA;&lt;p&gt;Next, we create an environment variable to which our execution environment will have access. &lt;code&gt;ACTIONS_ALLOW_UNSECURE_COMMANDS&lt;/code&gt; is required for Python on GitHub due to a bug. I am not sure if it is fixed or not.  Afterward, we install Python, install the requirements and run the scraper. Then we set the &lt;code&gt;DATE&lt;/code&gt; variable to the current server time. This will be used in the subject of our email.&lt;/p&gt;&#xA;&lt;p&gt;For the email sending part, I am using the awesome &lt;a href=&#34;https://github.com/marketplace/actions/send-email&#34;&gt;&lt;code&gt;send-email&lt;/code&gt;&lt;/a&gt; action which makes the whole process super simple. I provide it with my Gmail username and password and point it to the generated HTML file and it automatically sends the email.&lt;/p&gt;&#xA;&lt;p&gt;We also need to make sure we configure the secrets in the repository settings page so that the &lt;code&gt;send-email&lt;/code&gt; action has access to the &lt;code&gt;MAIL_USERNAME&lt;/code&gt; and &lt;code&gt;MAIL_PASSWORD&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/github-actions/github-secret-settings.png&#34; alt=&#34;GitHub Repository settings&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;We can test the execution by pushing everything to GitHub and then going to the Actions tab of the repo. From there we can select our workflow and manually trigger it.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/github-actions/github-action-workflow.png&#34; alt=&#34;Github action workflow&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;h2 id=&#34;github-actions-feedback&#34;&gt;GitHub Actions Feedback&lt;/h2&gt;&#xA;&lt;p&gt;The Action has been running successfully for a few days now. I have fallen in love with the simplicity of Actions. The only major issue is that you should not use the free version for anything time-sensitive. The action execution is almost always delayed by a few minutes when using the scheduler. For most simple cases it is fine though. I am also not sure if the situation is any different under the paid plan. However, if you dispatch the workflow using the online interface, it mostly gets scheduled for execution right away.&lt;/p&gt;&#xA;&lt;p&gt;I will use Actions again in the future when I have similar projects. The only thing to keep in mind is that Actions only have a limited amount of free minutes. If you go beyond this limit, you will have to pay and the price varies based on the operating system. The free account is limited to &lt;a href=&#34;https://github.com/pricing&#34;&gt;2000 minutes per month&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;I hope you all enjoyed this tutorial. You can find the corresponding GitHub repo &lt;a href=&#34;https://github.com/yasoob/github-action-scraper-tutorial/&#34;&gt;here&lt;/a&gt;. I had a ton of fun working on it. If you have any questions, comments, or suggestions, please feel free to comment below or send me an email (hi @ yasoob.me) or a &lt;a href=&#34;https://twitter.com/yasoob&#34;&gt;tweet&lt;/a&gt;. I do plan on writing about a bunch of other stuff but time is at a premium these days. However, I am hoping the situation would soon change &amp;#x1f604; I will see you in the next article &amp;#x2764;&amp;#xfe0f;&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Understanding and Generating a UPC-A barcode using Python</title>
				<link>https://yasoob.me/posts/understanding-and-generating-upc-a-barcode-using-python/</link>
				<pubDate>Mon, 12 Apr 2021 18:49:08 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/understanding-and-generating-upc-a-barcode-using-python/</guid>
				<category>programming</category>
				<category>python</category>
				<description>I have always been fascinated with barcodes and QR codes. I theoretically knew how barcodes worked but I wanted to solidify my understanding by making one from scratch. In this article, I will take you on a guided tour of how barcodes work and how we can make one from scratch using Python. I will focus on Universal Product Code type A (UPC-A) for this tutorial.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/barcode/barcode-hero.png&#34; alt=&#34;Understanding and Generating a UPC-A barcode using Python&#34;&gt;&lt;/p&gt;&lt;p&gt;Hi everyone! &amp;#x1f44b; I have always been fascinated by barcodes and QR codes. I have known for a long time about how they work in theory but I never did enough research on it. It seemed like I would learn a lot from diving deeper and implementing a barcode generator from scratch. There is no substitute for learning more about something by creating it from scratch so that is exactly what I did.&lt;/p&gt;&#xA;&lt;p&gt;This article is in a similar vein as my &lt;a href=&#34;https://yasoob.me/posts/understanding-and-writing-jpeg-decoder-in-python/&#34;&gt;&amp;ldquo;Understanding and Decoding a JPEG Image using Python&amp;rdquo;&lt;/a&gt; article. I will take you on a guided tour of how a barcode works and how to create a super simple barcode generator for the Universal Product Code (UPC-A) using pure Python.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; I have borrowed some code and ideas from &lt;a href=&#34;https://github.com/WhyNotHugo/python-barcode&#34;&gt;Hugo&lt;/a&gt; for this article.&lt;/p&gt;&#xA;&lt;h3 id=&#34;history&#34;&gt;History&lt;/h3&gt;&#xA;&lt;p&gt;It seems like barcodes have been there even before I was born. Turns out that is true. According to &lt;a href=&#34;https://en.wikipedia.org/wiki/Barcode&#34;&gt;Wikipedia&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The &lt;em&gt;barcode&lt;/em&gt; was invented by Norman  Joseph Woodland and Bernard Silver and patented in the US in 1951. The invention was based on Morse code that was extended to thin and thick bars. However, it took over twenty years before this invention became commercially successful.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;The idea for an automated entry system (barcode) originated when a Drexel student overheard a food chain owner asking for a system to automatically read product information during checkout. No doubt the barcode later found huge commercial success in the retail industry!&lt;/p&gt;&#xA;&lt;p&gt;The idea for encoding this information in the form of bars originated from morse code. One of the early versions just extended the dots to form vertical lines. The follow-up versions included a bunch of fun types of barcodes. There was also a proposal for a circular bullseye barcode in the early days. A major reason they didn&amp;rsquo;t stay for long is that the printers would sometimes smear the ink and that would render the code unreadable. However, printing vertical bars meant that the smears would only increase the bar height and the code would still be readable.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/barcode/Bullseye-Barcode-Patent-Relegen-Blog-e1511412089110.png&#34; alt=&#34;Blog | The Little-Known History Of The First Bullseye Barcode&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;h3 id=&#34;typical-barcode&#34;&gt;Typical barcode&lt;/h3&gt;&#xA;&lt;p&gt;A typical barcode usually contains:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Left guard bars&lt;/li&gt;&#xA;&lt;li&gt;Center bars&lt;/li&gt;&#xA;&lt;li&gt;Right guard bars&lt;/li&gt;&#xA;&lt;li&gt;Check digit&lt;/li&gt;&#xA;&lt;li&gt;Actual information between the guards&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The way the information is encoded in a barcode is called the symbology. Some symbologies allow storing alphabets but some only allow storing digits. There are tons of different symbologies out there and each is prevalent in a different industry.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/barcode/barcode_types.png&#34; alt=&#34;Barcode types - Choosing the right barcode: Code128, EAN, UPC, ITF-14 or  Code39&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://www.barcodecreatorsoftware.com/barcode-types/&#34;&gt;Image Source&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h3 id=&#34;upc-a&#34;&gt;UPC-A&lt;/h3&gt;&#xA;&lt;p&gt;In this article, we will be focusing on the UPC-A barcode. This is type A of the Universal Product Code barcode. It only allows storing digits (0-9) in the bars. I chose it for this article because it is super simple and quite a few other codes are just an extension of this.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/barcode/UPCdiag.png&#34; alt=&#34;About Barcodes - UPC retail barcodes&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;http://www.computalabel.com/Images/UPCdiag.png&#34;&gt;image source&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The symbology for UPC-A only allows storing 12 digits. The first digit, Number System Character, decides how the rest of the digits in the barcode will be interpreted. For example, If it is a 0, 1, 6, 7, or 8, it is going to be interpreted as a typical retail product. If it starts with a 2 then it is going to be interpreted as a produce item that contains a weight or price. The next 10 digits represent product-specific information and the interpretation depends on the NSC. The last digit is a check digit and helps detect certain errors in the barcode.&lt;/p&gt;&#xA;&lt;p&gt;We will try to create a UPC-A barcode using pure Python. I will not add the digits to the SVG but that would be a simple extension once we have the main barcode generation working.&lt;/p&gt;&#xA;&lt;p&gt;You can get more information about UPC and other forms of barcodes &lt;a href=&#34;https://www.wikiwand.com/en/Barcode&#34;&gt;from Wikipedia&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;check-digit-calculation&#34;&gt;Check digit calculation&lt;/h3&gt;&#xA;&lt;p&gt;The check digit allows the barcode reader to detect certain errors that might have been introduced into the barcode for various reasons. Each symbology uses a specific formula for calculating the check digit. The check digit equation for UPC-A looks like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/barcode/check-digit.png&#34; alt=&#34;Check digit calculation&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Here x_1 is the first digit of UPC and x_12 is the check digit itself that is unknown. The steps for calculating the check digit are:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Sum all odd-numbered positions (1,3,5&amp;hellip;)&lt;/li&gt;&#xA;&lt;li&gt;Multiply the sum by 3&lt;/li&gt;&#xA;&lt;li&gt;Sum all even-numbered positions (2,4,6&amp;hellip;) and add them to the result from step 2&lt;/li&gt;&#xA;&lt;li&gt;Calculate the result from step 3 modulo 10&lt;/li&gt;&#xA;&lt;li&gt;If the result from step 4 is 0 then the check digit is 0. Otherwise check digit is 10 - result from step 4&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;This error-check algorithm is known as the &lt;a href=&#34;https://en.wikipedia.org/wiki/Luhn_algorithm&#34;&gt;Luhn algorithm&lt;/a&gt;. It is one of the many different error detection algorithms out there.&lt;/p&gt;&#xA;&lt;h3 id=&#34;barcode-encoding&#34;&gt;Barcode encoding&lt;/h3&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/barcode/barcode-encoding.png&#34; alt=&#34;barcode-encoding&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Wikipedia provides very good visualization for what the barcode encoding looks like for UPC-A. There are two sets of digits that are divided by a middle guard. Each digit is encoded by 7 vertical lines or modules. Each of these can be either black or white. For example, 0 is encoded as &lt;code&gt;WWWBBWB&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The digits from 0-9 are encoded slightly differently on the left side of M (middle guard) vs the right side. A fun fact is that the right side encoding of a digit is an optical inverse of its left side encoding. For example, the 1 on the left side is encoded as &lt;code&gt;WWBBWWB&lt;/code&gt; and the 1 on the right side is encoded as &lt;code&gt;BBWWBBW&lt;/code&gt;. A reason for this is that this allows barcode readers to figure out if they are scanning the barcode in the correct direction or not. Some scanners would do two passes, once reading from left to right and once from right to left and some would simply reverse the input data without a second pass if it started scanning from the wrong direction.&lt;/p&gt;&#xA;&lt;p&gt;The whole visual representation of the barcode is divided into the following parts and unique patterns of black and white vertical lines (also known as modules):&lt;/p&gt;&#xA;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Position&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Element&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Count&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;Module width&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Quiet zone&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;9 modules (all white)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Start guard bar&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3 modules (BWB)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Left digit&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;6&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;7 modules (variable)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;4&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Mid guard bar&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;5 modules (WBWBW)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;5&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Right digit&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;5&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;7 modules (variable)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;6&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Check digit&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;7 modules (variable)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;7&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;End guard bar&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3 modules (BWB)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;8&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Quiet zone&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;1&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;9 modules (all white)&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;p&gt;There are a total of 113 modules or 113 black+white lines in a UPC-A barcode.&lt;/p&gt;&#xA;&lt;h3 id=&#34;defining-encoding-table&#34;&gt;Defining encoding table&lt;/h3&gt;&#xA;&lt;p&gt;The very first step in creating our custom barcode generator is to define the encoding table for the digits and the guard bars. Start by creating a new &lt;code&gt;barcode_generator.py&lt;/code&gt; file and adding this code to it:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;UPC&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    The all-in-one class that represents the UPC-A&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    barcode.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    EDGE &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;101&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    MIDDLE &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;01010&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    CODES &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;L&amp;#34;&lt;/span&gt;: (&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0001101&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0011001&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0010011&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0111101&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0100011&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0110001&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0101111&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0111011&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0110111&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0001011&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        ),&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;R&amp;#34;&lt;/span&gt;: (&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1110010&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1100110&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1101100&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1000010&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1011100&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1001110&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1010000&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1000100&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1001000&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1110100&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        ),&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    SIZE &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{0:.3f}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;mm&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    TOTAL_MODULES &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;113&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    MODULE_WIDTH &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0.33&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    MODULE_HEIGHT &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;25.9&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    EXTENDED_MODULE_HEIGHT &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; MODULE_HEIGHT &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt;MODULE_WIDTH&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;BARCODE_WIDTH &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; TOTAL_MODULES &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; MODULE_WIDTH&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    BARCODE_HEIGHT &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; EXTENDED_MODULE_HEIGHT&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;__init__&lt;/span&gt;(self, upc):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; list(str(upc))[:&lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; len(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc) &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;raise&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;Exception&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;The UPC has to be of length 11 or 12 (with check digit)&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here we are creating an all-in-one class and defining some class variables and the mapping between digits and the black/white lines (modules). The 1 represents black and 0 represents white. &lt;code&gt;EDGE&lt;/code&gt; represents the start and end guards. &lt;code&gt;MIDDLE&lt;/code&gt; represents the middle guard. &lt;code&gt;CODES&lt;/code&gt; dictionary contains two tuples mapped to &lt;code&gt;L&lt;/code&gt; and &lt;code&gt;R&lt;/code&gt; for the left and right digits. The index position in the tuple represents the digit we are mapping. For example, the first element of the &lt;code&gt;L&lt;/code&gt; tuple represents the 0 digit that is encoded to &lt;code&gt;WWWBBWB&lt;/code&gt; or &lt;code&gt;0001101&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The &lt;code&gt;MODULE_WIDTH&lt;/code&gt; and the other sizes are all taken &lt;a href=&#34;https://en.wikipedia.org/wiki/Universal_Product_Code?oldformat=true&#34;&gt;from Wikipedia&lt;/a&gt;. These are the dimensions of a typical UPC-A barcode in the normal sizing. You can tweak these sizes to an extent and the barcode should still work fine. The &lt;code&gt;EXTENDED_MODULE_HEIGHT&lt;/code&gt; refers to the height of the modules or bars for the three guards (L, M, R) and the first and last digit (check digit) of the UPC. These modules are generally taller than the other modules. This extended height is also taken from Wikipedia. The barcode is still valid without this height difference but it looks nice with this height difference and shows a clear separation of the left and right digits. For example, compare these two barcodes:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/barcode/extension-module-difference.png&#34; alt=&#34;extension-module-difference&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;I find the left barcode cleaner and nicer than the right one. I can clearly tell where the digits are being divided by a middle guard.&lt;/p&gt;&#xA;&lt;p&gt;I also added an &lt;code&gt;__init__&lt;/code&gt; method that takes the &lt;code&gt;upc&lt;/code&gt; as input and throws an &lt;code&gt;Exception&lt;/code&gt; if the size is smaller than 11. I haven&amp;rsquo;t added code for verifying the total length because I am truncating it to the first 11 digits. We will add the 12th check digit ourselves. The input &lt;code&gt;upc&lt;/code&gt; can be any integer up to a length of 11 digits. We don&amp;rsquo;t care about NSC and what the code actually represents.&lt;/p&gt;&#xA;&lt;h3 id=&#34;check-digit--error-detection&#34;&gt;Check digit &amp;amp; error detection&lt;/h3&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s implement the error detection and check digit calculation to our class. We will use the same formula we talked about earlier:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;UPC&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;calculate_check_digit&lt;/span&gt;(self):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Calculate the check digit&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [int(digit) &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; digit &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc[:&lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;]]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        oddsum &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; sum(upc[::&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        evensum &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; sum(upc[&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;::&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        check &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; (evensum &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; oddsum &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;) &lt;span style=&#34;color:#f92672&#34;&gt;%&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;10&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; check &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; [&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; [&lt;span style=&#34;color:#ae81ff&#34;&gt;10&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; check]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I am using list slicing to get the even and odd digit positions and then doing some arithmetic for the check digit calculation. It might have been better to let the user input the check digit and then compare that to our calculated check digit and make sure the entered barcode is correct. It would have made the barcode entry more robust but I will leave that error detection up to you.&lt;/p&gt;&#xA;&lt;h3 id=&#34;encoding-upc&#34;&gt;Encoding UPC&lt;/h3&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s add a new method to encode the UPC to the &lt;code&gt;01&lt;/code&gt; mapping we defined in our class. The code will look something like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;UPC&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;__init__&lt;/span&gt;(self, upc):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; list(str(upc))[:&lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; len(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc) &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;raise&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;Exception&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;The UPC has to be of length 11 or 12 (with check digit)&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;calculate_check_digit()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        encoded_code &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;encode()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;encode&lt;/span&gt;(self):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Encode the UPC based on the mapping defined above&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        code &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;EDGE[:]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; _i, number &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; enumerate(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt;]):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            code &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CODES[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;L&amp;#34;&lt;/span&gt;][int(number)]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        code &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MIDDLE&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; number &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc[&lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt;:]:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            code &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CODES[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;R&amp;#34;&lt;/span&gt;][int(number)]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        code &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;EDGE&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;encoded_upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; code&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;encode&lt;/code&gt; method simply loops over the UPC and creates a corresponding string containing a pattern of 0 and 1 based on each digit in the UPC. It appropriately uses the &lt;code&gt;L&lt;/code&gt; and &lt;code&gt;R&lt;/code&gt; mapping depending on whether the UPC digit being iterated on is in the first half of UPC or the second. It also adds the three guard bars at the correct places.&lt;/p&gt;&#xA;&lt;p&gt;For example, it will turn &lt;code&gt;123456789104&lt;/code&gt; into &lt;code&gt;10100110010010011011110101000110110001010111101010100010010010001110100110011011100101011100101&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;I also modified the &lt;code&gt;__init__&lt;/code&gt; method to make use of the newly created &lt;code&gt;encode&lt;/code&gt; method.&lt;/p&gt;&#xA;&lt;h3 id=&#34;generating-base-svg&#34;&gt;Generating base SVG&lt;/h3&gt;&#xA;&lt;p&gt;We will be outputting an SVG from our code. The way SVGs work is somewhat similar to HTML. They also contain a bunch of tags that you might have seen in an HTML document. An SVG will start with an &lt;code&gt;XML&lt;/code&gt; tag and a &lt;code&gt;DOCTYPE&lt;/code&gt;. This will be followed by an &lt;code&gt;svg&lt;/code&gt; tag that contains all the meat of our SVG. In this SVG we will group everything in a &lt;code&gt;g&lt;/code&gt; (group) tag. In this group tag, we will define the different modules (vertical bars) as a &lt;code&gt;rect&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Putting everything in a group just makes vector graphic editors (Inkscape, Illustrator, etc) play nicely with the generated SVGs.&lt;/p&gt;&#xA;&lt;p&gt;A simple SVG looks something like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-xml&#34; data-lang=&#34;xml&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&amp;lt;?xml version=&amp;#34;1.0&amp;#34; encoding=&amp;#34;UTF-8&amp;#34;?&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&amp;lt;!DOCTYPE svg&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;  PUBLIC &amp;#39;-//W3C//DTD SVG 1.1//EN&amp;#39;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;  &amp;#39;http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd&amp;#39;&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;svg&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;version=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1.1&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;xmlns=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;http://www.w3.org/2000/svg&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;width=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;44.000mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;height=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;23.000mm&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;g&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;id=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;barcode_group&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;rect&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;width=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;100%&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;height=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;100%&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;style=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;fill:white&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;rect&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;x=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;6.500mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;y=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1.000mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;width=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0.330mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;height=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;15.000mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;style=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;fill:black;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;rect&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;x=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;6.830mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;y=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1.000mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;width=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0.330mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;height=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;15.000mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;style=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;fill:white;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;rect&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;x=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;7.160mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;y=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1.000mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;width=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0.330mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;height=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;15.000mm&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;style=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;fill:black;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;&amp;lt;!-- truncated --&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;/g&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Even on a cursory look, it is fairly easy to imagine what this SVG code will visually look like.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s add some code to our class to generate a skeleton/boilerplate SVG that we can later fill in:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; xml.dom&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;UPC&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;__init__&lt;/span&gt;(self, upc):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#x9;&#x9;&lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;create_barcode()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;create_barcode&lt;/span&gt;(self):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;prepare_svg()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;prepare_svg&lt;/span&gt;(self):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Create the complete boilerplate SVG for the barcode&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;create_svg_object()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_root &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;documentElement&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        group &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;createElement(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;g&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        group&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;id&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;barcode_group&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_group &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_root&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;appendChild(group)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        background &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;createElement(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;rect&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        background&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;width&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;100%&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        background&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;height&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;100%&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        background&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;style&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;fill: white&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_group&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;appendChild(background)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;create_svg_object&lt;/span&gt;(self):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Create an SVG object&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        imp &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; xml&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;dom&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;getDOMImplementation()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        doctype &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; imp&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;createDocumentType(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;svg&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;-//W3C//DTD SVG 1.1//EN&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        document &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; imp&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;createDocument(&lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;svg&amp;#34;&lt;/span&gt;, doctype)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;documentElement&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;version&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1.1&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;documentElement&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;xmlns&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;http://www.w3.org/2000/svg&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;documentElement&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;width&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;BARCODE_WIDTH)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;documentElement&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;height&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;BARCODE_HEIGHT)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; document&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;create_module&lt;/span&gt;(self, xpos, ypos, width, height, color):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Create a module and append a corresponding rect to the SVG group&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;createElement(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;rect&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;x&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(xpos))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;y&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(ypos))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;width&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(width))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;height&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(height))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;style&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;fill:&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(color))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_group&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;appendChild(element)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We are doing a couple of things here. Let&amp;rsquo;s look at each method one by one.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;code&gt;__init__&lt;/code&gt;: I modified it to make use of the &lt;code&gt;create_barcode&lt;/code&gt; method&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;create_barcode&lt;/code&gt;: For now it simply calls the &lt;code&gt;prepare_svg&lt;/code&gt; method. We will soon update it to do more stuff&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;prepare_svg&lt;/code&gt;: Calls &lt;code&gt;create_svg_object&lt;/code&gt; to create a skeleton SVG object and then adds a group to store our barcode and a white rectangle inside that said group. This white rectangle will act as the background of our barcode.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;create_svg_object&lt;/code&gt;: Uses the &lt;a href=&#34;https://docs.python.org/3/library/xml.dom.html&#34;&gt;&lt;code&gt;xml.dom&lt;/code&gt;&lt;/a&gt; package to set up a DOM with proper doctype and attributes&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;create_module&lt;/code&gt;: I am not currently using it. It is going to create a &lt;code&gt;rect&lt;/code&gt; for each black/white bar with the appropriate size and style and append that to our SVG.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;h3 id=&#34;packing-the-encoded-upc&#34;&gt;Packing the encoded UPC&lt;/h3&gt;&#xA;&lt;p&gt;We can use the encoded UPC and the SVG generation code we have so far to create an SVG but let&amp;rsquo;s create one more method to pack the encoded UPC. Packing means that it will turn a group of 0s and 1s into a single digit. For example:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;#34;001101&amp;#34; -&amp;gt; [-2, 2, -1, 1]&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The digit value tells us how many same characters it saw before coming across a different character. And if the digit is negative then we know that it is referring to a 0 and if it is positive then we know it is referring to a 1. This will help us in figuring out what color to use to create the corresponding rectangle (black vs white).&lt;/p&gt;&#xA;&lt;p&gt;The benefit of packing is that instead of creating 6 rectangles for &lt;code&gt;001101&lt;/code&gt;, we can only create 4 rectangles with varying widths. In total, we will only have to make 59 rectangles or bars (3 + 3 + 5 for the guards and 4*12 for the 12 digits). The packing code would look like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;UPC&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;packed&lt;/span&gt;(self, encoded_upc):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Pack the encoded UPC to a list. Ex:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;            &amp;#34;001101&amp;#34; -&amp;gt; [-2, 2, -1, 1]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        encoded_upc &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        extended_bars &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;28&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;29&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;31&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;32&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;53&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;54&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;55&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;56&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;57&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;58&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;59&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        count &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        bar_count &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; i &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; range(&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;, len(encoded_upc) &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; encoded_upc[i] &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; encoded_upc[i &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;]:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                count &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; encoded_upc[i] &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1&amp;#34;&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#66d9ef&#34;&gt;yield&lt;/span&gt; count, bar_count &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; extended_bars&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#66d9ef&#34;&gt;yield&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt;count, bar_count &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; extended_bars&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                bar_count &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                count &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I have also added an &lt;code&gt;extended_bars&lt;/code&gt; list. This contains the (1 numbered) indices of bars that should be extended (the three guards and the first and last digit).&lt;/p&gt;&#xA;&lt;h3 id=&#34;creating-the-barcode-svg&#34;&gt;Creating the barcode SVG&lt;/h3&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s edit the &lt;code&gt;create_barcode&lt;/code&gt; method to generate the full SVG code for our UPC-A barcode:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;UPC&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;create_barcode&lt;/span&gt;(self):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;prepare_svg()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# Quiet zone is automatically added as the background is white We will&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# simply skip the space for 9 modules and start the guard from there&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x_position &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;9&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MODULE_WIDTH&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; count, extended &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;packed(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;encoded_upc):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; count &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                color &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;white&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                color &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;black&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            config &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;xpos&amp;#34;&lt;/span&gt;: x_position,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;ypos&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;color&amp;#34;&lt;/span&gt;: color,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;width&amp;#34;&lt;/span&gt;: abs(count) &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MODULE_WIDTH,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;height&amp;#34;&lt;/span&gt;: self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;EXTENDED_MODULE_HEIGHT &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; extended &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MODULE_HEIGHT,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;create_module(&lt;span style=&#34;color:#f92672&#34;&gt;**&lt;/span&gt;config)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            x_position &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; abs(count) &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MODULE_WIDTH&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We first prepare the skeleton of the SVG. Then we skip 9 module widths. This is the quiet zone that is required for the barcode scanners to accurately identify a barcode. It is at least 9 module widths according to Wikipedia and exists on either side of the barcode. Our background is already white so we don&amp;rsquo;t have to draw any rectangle to represent the quiet zone.&lt;/p&gt;&#xA;&lt;p&gt;Then we loop over the packed encoding. For each return value from the &lt;code&gt;packed&lt;/code&gt; method, we calculate the width and height of the rectangle. The calculation is simple. For the width, we take the absolute value of &lt;code&gt;count&lt;/code&gt; and multiply that with &lt;code&gt;MODULE_WIDTH&lt;/code&gt;. For the height, if &lt;code&gt;extended&lt;/code&gt; is &lt;code&gt;True&lt;/code&gt; we set it to &lt;code&gt;EXTENDED_MODULE_HEIGHT&lt;/code&gt;, otherwise, we set it to &lt;code&gt;MODULE_HEIGHT&lt;/code&gt;. After creating a dictionary with this config, we pass it to &lt;code&gt;create_module&lt;/code&gt;. At the end of each loop, we adjust the x position of the next rectangle based on how wide the current rectangle is.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The &lt;code&gt;**&lt;/code&gt; in &lt;code&gt;self.create_module(**config)&lt;/code&gt; converts the items in the config dict into &lt;a href=&#34;https://book.pythontips.com/en/latest/args_and_kwargs.html&#34;&gt;keyword arguments&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;saving-the-svg&#34;&gt;Saving the SVG&lt;/h3&gt;&#xA;&lt;p&gt;The only two things left now are a method to dump the SVG code to a file and to tie everything together in the &lt;code&gt;__init__&lt;/code&gt; method. Let&amp;rsquo;s first add a &lt;code&gt;save&lt;/code&gt; method:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; os&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;UPC&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;save&lt;/span&gt;(self, filename):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Dump the final SVG XML code to a file&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        output &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;toprettyxml(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            indent&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt;, newl&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;os&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;linesep, encoding&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;UTF-8&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;with&lt;/span&gt; open(filename, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;wb&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; f:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            f&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;write(output)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;xml.dom&lt;/code&gt; provides us with a nice &lt;code&gt;toprettyxml&lt;/code&gt; method to dump a nicely formatted XML document into a string which we can then save to a file.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s finish the code by modifying the &lt;code&gt;__init__&lt;/code&gt; method and adding some driver code at the end of the file:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;UPC&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;__init__&lt;/span&gt;(self, upc):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; list(str(upc))[:&lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; len(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc) &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;raise&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;Exception&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;The UPC has to be of length 11 or 12 (with check digit)&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;calculate_check_digit()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        encoded_code &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;encode()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;create_barcode()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;save(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;upc_custom.svg&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#x9;&#x9;&lt;span style=&#34;color:#75715e&#34;&gt;# ...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; __name__ &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;__main__&amp;#34;&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; UPC(&lt;span style=&#34;color:#ae81ff&#34;&gt;12345678910&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Save the file and try running it. It should generate a &lt;code&gt;upc_custom.svg&lt;/code&gt; file in the same directory as your Python code.&lt;/p&gt;&#xA;&lt;h3 id=&#34;complete-code&#34;&gt;Complete code&lt;/h3&gt;&#xA;&lt;p&gt;The complete code is available below and on &lt;a href=&#34;https://gist.github.com/yasoob/f970de335a99a542461977033b8b0a02&#34;&gt;GitHub&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; xml.dom&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; os&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;UPC&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    The all-in-one class that represents the UPC-A&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    barcode.&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;    &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    QUIET &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;000000000&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    EDGE &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;101&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    MIDDLE &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;01010&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    CODES &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;L&amp;#34;&lt;/span&gt;: (&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0001101&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0011001&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0010011&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0111101&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0100011&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0110001&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0101111&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0111011&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0110111&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;0001011&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        ),&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;R&amp;#34;&lt;/span&gt;: (&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1110010&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1100110&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1101100&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1000010&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1011100&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1001110&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1010000&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1000100&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1001000&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1110100&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        ),&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    SIZE &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{0:.3f}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;mm&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    MODULE_WIDTH &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0.33&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    MODULE_HEIGHT &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;25.9&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    EXTENDED_MODULE_HEIGHT &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; MODULE_HEIGHT &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt;MODULE_WIDTH&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    BARCODE_HEIGHT &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; EXTENDED_MODULE_HEIGHT&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    TOTAL_MODULES &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;113&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;__init__&lt;/span&gt;(self, upc):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; list(str(upc))[:&lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; len(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc) &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;raise&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;Exception&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;f&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;The UPC has to be of length 11 or 12 (with check digit)&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;calculate_check_digit()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        encoded_code &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;encode()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;create_barcode()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;save(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;upc_custom.svg&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;calculate_check_digit&lt;/span&gt;(self):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Calculate the check digit&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [int(digit) &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; digit &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc[:&lt;span style=&#34;color:#ae81ff&#34;&gt;11&lt;/span&gt;]]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        oddsum &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; sum(upc[::&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        evensum &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; sum(upc[&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;::&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;])&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        check &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; (evensum &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; oddsum &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;) &lt;span style=&#34;color:#f92672&#34;&gt;%&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;10&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; check &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; [&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; [&lt;span style=&#34;color:#ae81ff&#34;&gt;10&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; check]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;encode&lt;/span&gt;(self):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Encode the UPC based on the mapping defined above&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        code &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;EDGE[:]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; _i, number &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; enumerate(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc[&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;:&lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt;]):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            code &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CODES[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;L&amp;#34;&lt;/span&gt;][int(number)]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        code &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MIDDLE&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; number &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;upc[&lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt;:]:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            code &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;CODES[&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;R&amp;#34;&lt;/span&gt;][int(number)]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        code &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;EDGE&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;encoded_upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; code&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;create_barcode&lt;/span&gt;(self):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;prepare_svg()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# Quiet zone is automatically added as the background is white We will&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;# simply skip the space for 9 modules and start the guard from there&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        x_position &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;9&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MODULE_WIDTH&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; count, extended &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;packed(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;encoded_upc):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; count &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                color &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;white&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                color &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;black&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            config &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;xpos&amp;#34;&lt;/span&gt;: x_position,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;ypos&amp;#34;&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;color&amp;#34;&lt;/span&gt;: color,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;width&amp;#34;&lt;/span&gt;: abs(count) &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MODULE_WIDTH,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;height&amp;#34;&lt;/span&gt;: self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;EXTENDED_MODULE_HEIGHT &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; extended &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MODULE_HEIGHT,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;create_module(&lt;span style=&#34;color:#f92672&#34;&gt;**&lt;/span&gt;config)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            x_position &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; abs(count) &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MODULE_WIDTH&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;packed&lt;/span&gt;(self, encoded_upc):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Pack the encoded UPC to a list. Ex:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;            &amp;#34;001101&amp;#34; -&amp;gt; [-2, 2, -1, 1]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        encoded_upc &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        extended_bars &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; [&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;3&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;7&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;28&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;29&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;30&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;31&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;32&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;53&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;54&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;55&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;56&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;57&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;58&lt;/span&gt;,&lt;span style=&#34;color:#ae81ff&#34;&gt;59&lt;/span&gt;]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        count &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        bar_count &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; i &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; range(&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;, len(encoded_upc) &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; encoded_upc[i] &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; encoded_upc[i &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;]:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                count &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; encoded_upc[i] &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1&amp;#34;&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#66d9ef&#34;&gt;yield&lt;/span&gt; count, bar_count &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; extended_bars&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#66d9ef&#34;&gt;yield&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt;count, bar_count &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; extended_bars&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                bar_count &lt;span style=&#34;color:#f92672&#34;&gt;+=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                count &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;prepare_svg&lt;/span&gt;(self):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Create the complete boilerplate SVG for the barcode&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;create_svg_object()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_root &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;documentElement&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        group &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;createElement(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;g&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        group&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;id&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;barcode_group&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_group &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_root&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;appendChild(group)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        background &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;createElement(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;rect&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        background&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;width&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;100%&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        background&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;height&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;100%&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        background&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;style&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;fill: white&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_group&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;appendChild(background)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;create_svg_object&lt;/span&gt;(self):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Create an SVG object&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        imp &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; xml&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;dom&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;getDOMImplementation()&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        doctype &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; imp&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;createDocumentType(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;svg&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;-//W3C//DTD SVG 1.1//EN&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd&amp;#34;&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        document &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; imp&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;createDocument(&lt;span style=&#34;color:#66d9ef&#34;&gt;None&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;svg&amp;#34;&lt;/span&gt;, doctype)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;documentElement&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;version&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;1.1&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;documentElement&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;xmlns&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;http://www.w3.org/2000/svg&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;documentElement&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;width&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;TOTAL_MODULES &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;MODULE_WIDTH)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;documentElement&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;height&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;BARCODE_HEIGHT)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; document&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;create_module&lt;/span&gt;(self, xpos, ypos, width, height, color):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Create a module and append a corresponding rect to the SVG group&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;createElement(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;rect&amp;#34;&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;x&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(xpos))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;y&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(ypos))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;width&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(width))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;height&amp;#34;&lt;/span&gt;, self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;SIZE&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(height))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        element&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;setAttribute(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;style&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;fill:&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;{}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;format(color))&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_group&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;appendChild(element)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;save&lt;/span&gt;(self, filename):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        Dump the final SVG XML code to a file&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        &amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        output &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; self&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;_document&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;toprettyxml(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            indent&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;4&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt;, newl&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;os&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;linesep, encoding&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;UTF-8&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;with&lt;/span&gt; open(filename, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;wb&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; f:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            f&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;write(output)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; __name__ &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;__main__&amp;#34;&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    upc &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; UPC(&lt;span style=&#34;color:#ae81ff&#34;&gt;12345678910&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h3&gt;&#xA;&lt;p&gt;Thank you so much for reading this article. I know it was fairly long so thanks for sticking around. If you enjoyed this article and would love to see a much more cleaner implementation of barcode generator in Python, I recommend you check out &lt;a href=&#34;https://github.com/WhyNotHugo/python-barcode&#34;&gt;this repo&lt;/a&gt;. I have shamelessly borrowed ideas and code from Hugo&amp;rsquo;s repo for this article. It contains implementations for other barcode formats as well such as the EAN13 (EuropeanArticleNumber13) and JapanArticleNumber.&lt;/p&gt;&#xA;&lt;p&gt;If you want to read more about barcodes, &lt;a href=&#34;https://www.linkedin.com/in/boonepeter/&#34;&gt;Peter&lt;/a&gt; has written &lt;a href=&#34;https://boonepeter.github.io/posts/2020-11-10-spotify-codes/&#34;&gt;a wonderful post&lt;/a&gt; about Spotify codes work.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/barcode/spotify-code.png&#34; alt=&#34;Spotify barcode&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://boonepeter.github.io/imgs/spotify/spotify_track_6vQN2a9QSgWcm74KEZYfDL.jpg&#34;&gt;Image source&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I really enjoyed diving deeper into barcodes and learning more about their history and implementation. This is a very fascinating field and I do plan on exploring it more in the future. I will probably try to tackle QR codes next as they are slowly replacing barcodes everywhere and can encode a lot more information in a much smaller space. It would be fun to try and implement a QR code generator in Python.&lt;/p&gt;&#xA;&lt;h3 id=&#34;next-steps&#34;&gt;Next steps&lt;/h3&gt;&#xA;&lt;p&gt;If you want to continue working on this, you are more than welcome to copy and modify my code. I am releasing it under the MIT license. A couple of things you can add are:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Add support for text underneath the barcode&lt;/li&gt;&#xA;&lt;li&gt;Add support for more symbology&lt;/li&gt;&#xA;&lt;li&gt;Add stricter error checking&lt;/li&gt;&#xA;&lt;li&gt;Add a PNG/JPG output&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;I hope you enjoyed reading this article. If you have any questions, comments, suggestions, or feedback, please write a comment below or send me an email. I would love to hear from you.&lt;/p&gt;&#xA;&lt;p&gt;Take care &amp;#x2764;&amp;#xfe0f;&amp;#x1f44b;&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>How to Self-Host listmonk, an Open-Source Newsletter Manager</title>
				<link>https://yasoob.me/posts/setting-up-listmonk-opensource-newsletter-mailing/</link>
				<pubDate>Fri, 12 Mar 2021 00:00:53 -0500</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/setting-up-listmonk-opensource-newsletter-mailing/</guid>
				<category>programming</category>
				<category>devops</category>
				<category>self-hosted</category>
				<description>Set up listmonk, a free self-hosted alternative to Mailchimp, with docker-compose, NGINX and certbot SSL, import your subscribers, and send for $0.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/listmonk/listmonk-header.png&#34; alt=&#34;How to Self-Host listmonk, an Open-Source Newsletter Manager&#34;&gt;&lt;/p&gt;&lt;p&gt;Hi everyone! 👋&lt;/p&gt;&#xA;&lt;p&gt;I have been using Mailchimp for my mailing list for a while and even though it is great, it is super expensive. I have 5000+ people in my list and that puts me in their $78 plan. I send the newsletter very rarely and don&amp;rsquo;t really earn anything from the mailing list so it was really hard for me to justify the $78. I had recently integrated Amazon SES with a project and found out that SES gives you a free 50,000 email sending quota per month. That sounded more than enough for my purposes and I thought that surely someone must have made an open-source mailing list management system on top of SES. To my surprise, there weren&amp;rsquo;t a ton of options out there.&lt;/p&gt;&#xA;&lt;p&gt;During my search, I came across &lt;a href=&#34;https://sendy.co/&#34;&gt;Sendy&lt;/a&gt; and &lt;a href=&#34;https://listmonk.app/&#34;&gt;listmonk&lt;/a&gt;. Sendy is mature but closed source and paid. On the other hand, listmonk is opensource but is slightly rough around the edges and lacks certain important features like email bounce tracking. It was tough to decide between these two but I eventually figured I should give listmonk a try before investing in Sendy.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; There is also  &lt;a href=&#34;https://mailtrain.org/&#34;&gt;Mailtrain&lt;/a&gt; out there but I didn&amp;rsquo;t go ahead with it because the recommended requirements for the v2 are higher than the free ec2 instance Amazon offers and I wanted to keep everything free if possible&lt;/p&gt;&#xA;&lt;p&gt;I only wanted basic features in a mailing list package:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Email open rate&lt;/li&gt;&#xA;&lt;li&gt;Link click-through rate&lt;/li&gt;&#xA;&lt;li&gt;Mailing list/Subscribers management&lt;/li&gt;&#xA;&lt;li&gt;Subscribe/Unsubscribe form&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Listmonk checked all of these boxes. There were a couple of rough edges but it mostly fits the bill. I was not too confident with my choice listmonk but then again listmonk is being used in production by the fine folks at &lt;a href=&#34;https://zerodha.com/&#34;&gt;Zerodha&lt;/a&gt; to send millions of emails each month. A major drawback for listmonk is that there aren&amp;rsquo;t detailed instructions about production setup. Considering that it is open-source software, I decided to document my journey and show you how I set it up.&lt;/p&gt;&#xA;&lt;p&gt;For this tutorial, I am assuming that you are running an ubuntu machine and already have it up and going. And I am also assuming that you have docker installed.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt; You can get the final setup code from &lt;a href=&#34;https://github.com/yasoob/listmonk-setup&#34;&gt;this repository&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;setting-up-docker-compose&#34;&gt;Setting up docker-compose&lt;/h2&gt;&#xA;&lt;p&gt;Listmonk helpfully has an image up on Dockerhub that we can use. The &lt;a href=&#34;https://github.com/knadh/listmonk&#34;&gt;GitHub repository&lt;/a&gt; contains a sample &lt;a href=&#34;https://github.com/knadh/listmonk/blob/master/docker-compose.yml&#34;&gt;docker-compose.yml&lt;/a&gt; file for us:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# NOTE: This docker-compose.yml is meant to be just an example guideline&#xA;# on how you can achieve the same. It is not intended to run out of the box&#xA;# and you must edit the below configurations to suit your needs.&#xA;&#xA;version: &amp;#34;3.7&amp;#34;&#xA;&#xA;x-app-defaults: &amp;amp;app-defaults&#xA;  restart: unless-stopped&#xA;  image: listmonk/listmonk:latest&#xA;  ports:&#xA;    - &amp;#34;9000:9000&amp;#34;&#xA;  networks:&#xA;    - listmonk&#xA;&#xA;x-db-defaults: &amp;amp;db-defaults&#xA;    image: postgres:11&#xA;    ports:&#xA;      - &amp;#34;9432:5432&amp;#34;&#xA;    networks:&#xA;      - listmonk&#xA;    environment:&#xA;      - POSTGRES_PASSWORD=listmonk&#xA;      - POSTGRES_USER=listmonk&#xA;      - POSTGRES_DB=listmonk&#xA;    restart: unless-stopped&#xA;&#xA;services:&#xA;  db:&#xA;    &amp;lt;&amp;lt;: *db-defaults&#xA;    volumes:&#xA;      - type: volume&#xA;        source: listmonk-data&#xA;        target: /var/lib/postgresql/data&#xA;&#xA;  app:&#xA;    &amp;lt;&amp;lt;: *app-defaults&#xA;    depends_on:&#xA;      - db&#xA;&#xA;  demo-db:&#xA;    &amp;lt;&amp;lt;: *db-defaults&#xA;&#xA;  demo-app:&#xA;    &amp;lt;&amp;lt;: *app-defaults&#xA;    command: [sh, -c, &amp;#34;yes | ./listmonk --install --config config-demo.toml &amp;amp;&amp;amp; ./listmonk --config config-demo.toml&amp;#34;]&#xA;    depends_on: &#xA;      - demo-db&#xA;&#xA;networks:&#xA;  listmonk:&#xA;&#xA;volumes:&#xA;  listmonk-data:&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If we simply save this file and run &lt;code&gt;docker-compose up -d demo-app&lt;/code&gt;, we can access the demo-app at localhost:9000. However, we don&amp;rsquo;t want the demo-app. We want to supply our custom config file. We can do that by modifying the &lt;code&gt;docker-compose.yml&lt;/code&gt; file like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  app:&#xA;    &amp;lt;&amp;lt;: *app-defaults&#xA;    depends_on:&#xA;      - db&#xA;    volumes:&#xA;      - ./config.toml/:/listmonk/config.toml&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Afterward, we need to create a &lt;code&gt;config.toml&lt;/code&gt; file and save it in the same directory as the &lt;code&gt;docker-compose.yml&lt;/code&gt; file. A sample &lt;code&gt;config.toml&lt;/code&gt; file looks like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[app]&#xA;    # Interface and port where the app will run its webserver.&#xA;    address = &amp;#34;0.0.0.0:9000&amp;#34;&#xA;&#xA;    # BasicAuth authentication for the admin dashboard. This will eventually&#xA;    # be replaced with a better multi-user, role-based authentication system.&#xA;    # IMPORTANT: Leave both values empty to disable authentication on admin&#xA;    # only where an external authentication is already setup.&#xA;    admin_username = &amp;#34;listmonk&amp;#34;&#xA;    admin_password = &amp;#34;listmonk&amp;#34;&#xA;&#xA;# Database.&#xA;[db]&#xA;    host = &amp;#34;db&amp;#34;&#xA;    port = 5432&#xA;    user = &amp;#34;listmonk&amp;#34;&#xA;    password = &amp;#34;listmonk&amp;#34;&#xA;    database = &amp;#34;listmonk&amp;#34;&#xA;    ssl_mode = &amp;#34;disable&amp;#34;&#xA;    max_open = 25&#xA;    max_idle = 25&#xA;    max_lifetime = &amp;#34;300s&amp;#34;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Make sure you replace the admin user/pass in the config file and use something unique. Now we can run &lt;code&gt;docker-compose up -d app&lt;/code&gt; and have listmonk up and running on port 9000 with our custom config.&lt;/p&gt;&#xA;&lt;h2 id=&#34;custom-static-files&#34;&gt;Custom static files&lt;/h2&gt;&#xA;&lt;p&gt;By default listmonk sends out this email when someone tries signing up to a newsletter/mailing list:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Without the logo&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/listmonk/default-optin.png&#34; alt=&#34;Default Opt in email&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;With the logo&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/listmonk/optin-with-logo.png&#34; alt=&#34;image-20210311104410480&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;I did not like this opt-in email. I wanted to give it more character and freshen it up a little bit. The solution is pretty simple. The listmonk GitHub repo contains a &lt;a href=&#34;https://github.com/knadh/listmonk/tree/master/static&#34;&gt;&lt;code&gt;static&lt;/code&gt; directory&lt;/a&gt; with these templates. Download the static directory and place it right next to the &lt;code&gt;docker-compose.yml&lt;/code&gt; file. Now go ahead and make whatever changes you want to the templates.&lt;/p&gt;&#xA;&lt;p&gt;I updated the &lt;code&gt;subscriber-optin.html&lt;/code&gt; file and the result was this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/listmonk/modified-optin.png&#34; alt=&#34;image-20210311105857013&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;That looks much nicer than the original optin email. But how do we tell listmonk to use these custom templates? Listmonk can take a &lt;code&gt;--static-dir&lt;/code&gt; argument that specifies a custom static files directory. We can modify the &lt;code&gt;docker-compose.yml&lt;/code&gt; file and update the &lt;code&gt;app&lt;/code&gt; service definition like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  app:&#xA;    &amp;lt;&amp;lt;: *app-defaults&#xA;    depends_on:&#xA;      - db&#xA;    command: &amp;#34;./listmonk --static-dir=/listmonk/static&amp;#34;&#xA;    volumes:&#xA;      - ./config.toml/:/listmonk/config.toml&#xA;      - ./static:/listmonk/static&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And now we can ask docker to restart &lt;code&gt;app&lt;/code&gt; service. This will make sure that listmonk picks up our custom templates:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;docker-compose up --force-recreate -d app&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The current directory structure would look something like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;.&#xA;├── config.toml&#xA;├── docker-compose.yml&#xA;└── static&#xA;    ├── email-templates&#xA;    │   ├── base.html&#xA;    │   ├── campaign-status.html&#xA;    │   ├── default.tpl&#xA;    │   ├── import-status.html&#xA;    │   ├── subscriber-data.html&#xA;    │   ├── subscriber-optin-campaign.html&#xA;    │   └── subscriber-optin.html&#xA;    └── public&#xA;        ├── static&#xA;        │   ├── favicon.png&#xA;        │   ├── logo.png&#xA;        │   ├── logo.svg&#xA;        │   ├── script.js&#xA;        │   └── style.css&#xA;        └── templates&#xA;            ├── index.html&#xA;            ├── message.html&#xA;            ├── optin.html&#xA;            ├── subscription-form.html&#xA;            └── subscription.html&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;importing-old-subscribers&#34;&gt;Importing old subscribers&lt;/h2&gt;&#xA;&lt;p&gt;If you are migrating from another mailing list solution like &lt;a href=&#34;https://mailchimp.com/&#34;&gt;Mailchimp&lt;/a&gt; or &lt;a href=&#34;https://substack.com/&#34;&gt;Substack&lt;/a&gt;, you might already have a ton of subscribers. It is painful to think that you will have to gather all of those subscribers again or ask them for consent. They have already given you their consent to email them and you want to change your mailing list provider without any effect on your old subscribers.&lt;/p&gt;&#xA;&lt;p&gt;Thankfully, listmonk supports subscriber import. You have the option to either create a new subscriber using the GUI or import a CSV file that contains names, emails, and attributes (extra information) of subscribers.&lt;/p&gt;&#xA;&lt;p&gt;The GUI looks like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/listmonk/subscriber-input.png&#34; alt=&#34;image-20210311124400371&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;If you add a subscriber via the online wizard, they will receive an opt-in email. Their status in the GUI will look like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/listmonk/unconfirmed.png&#34; alt=&#34;image-20210311124512796&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Notice the &amp;ldquo;Unconfirmed&amp;rdquo;. That just tells us that the user hasn&amp;rsquo;t clicked on &amp;ldquo;confirm&amp;rdquo; in the opt-in email they received. As far as I know, we can&amp;rsquo;t currently add a user via the wizard and have listmonk not send them an opt-in email. So what&amp;rsquo;s the alternative? CSV imports!&lt;/p&gt;&#xA;&lt;p&gt;A sample CSV looks like this:&lt;/p&gt;&#xA;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;name&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;email&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;Yasoob&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;&lt;a href=&#34;mailto:hi@yasoob.me&#34;&gt;hi@yasoob.me&lt;/a&gt;&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;p&gt;We can import this CSV via the GUI and by-default listmonk will not send anyone an opt-in email. However, listmonk will also not mark them as &amp;ldquo;confirmed&amp;rdquo; either. And you can not send the unconfirmed people a newsletter. We have two options at this point.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Send an opt-in email campaign to everyone you just imported&lt;/li&gt;&#xA;&lt;li&gt;Manually mark them as confirmed in the DB&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s talk about the second option. For manually marking the subscribers as confirmed, we will have to run a sql query. I am assuming that you were able to get listmonk working using &lt;code&gt;docker-compose&lt;/code&gt; and you are currently on the same server as where listmonk is running. The default &lt;code&gt;docker-compose.yml&lt;/code&gt; file runs a postgresql container and &lt;code&gt;docker-compose&lt;/code&gt; names it &lt;code&gt;listmonk_db_1&lt;/code&gt; on first run. You can check out the list of currently running containers by running:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ docker-compose ps&#xA;&#xA;CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                                      NAMES&#xA;f020015005a1        listmonk/listmonk:latest   &amp;#34;./listmonk --static…&amp;#34;   33 hours ago        Up 33 hours         0.0.0.0:9000-&amp;gt;9000/tcp                     listmonk_app_1&#xA;623c84d3d072        postgres:11                &amp;#34;docker-entrypoint.s…&amp;#34;   33 hours ago        Up 33 hours         0.0.0.0:9432-&amp;gt;5432/tcp                     listmonk_db_1&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can run &lt;code&gt;bash&lt;/code&gt; in the &lt;code&gt;listmonk_db_1&lt;/code&gt; container and run &lt;code&gt;psql&lt;/code&gt; (Postgresql command-line tool)&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ docker exec -it listmonk_db_1 /bin/bash&#xA;root@623c84d3d072:/# psql -d listmonk  -U listmonk -W&#xA;Password:&#xA;psql (11.11 (Debian 11.11-1.pgdg90+1))&#xA;Type &amp;#34;help&amp;#34; for help.&#xA;&#xA;listmonk=#&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The above commands just connected us to the listmonk db. We can list all the tables in the db by typing:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;\dt&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;              List of relations&#xA; Schema |       Name       | Type  |  Owner&#xA;--------+------------------+-------+----------&#xA; public | campaign_lists   | table | listmonk&#xA; public | campaign_views   | table | listmonk&#xA; public | campaigns        | table | listmonk&#xA; public | link_clicks      | table | listmonk&#xA; public | links            | table | listmonk&#xA; public | lists            | table | listmonk&#xA; public | media            | table | listmonk&#xA; public | settings         | table | listmonk&#xA; public | subscriber_lists | table | listmonk&#xA; public | subscribers      | table | listmonk&#xA; public | templates        | table | listmonk&#xA;(11 rows)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The table that we want to look into is the &lt;code&gt;subscriber_lists&lt;/code&gt;. We can look at the contents of this table by typing this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT * from subscriber_lists;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;subscriber_id&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;list_id&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;status&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;created_at&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;updated_at&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11180&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;unconfirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11181&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;unconfirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11182&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;unconfirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11183&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;unconfirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11184&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;unconfirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11185&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;unconfirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11186&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;unconfirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11187&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;unconfirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;p&gt;We can update the status of all the subscribers to &lt;code&gt;confirmed&lt;/code&gt; by running the following query:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;UPDATE subscriber_lists SET status=&amp;#39;confirmed&amp;#39; WHERE list_id=4;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Sweet! Running the &lt;code&gt;SELECT&lt;/code&gt; query again should reflect the change in the status:&lt;/p&gt;&#xA;&lt;table&gt;&#xA;&#x9;&lt;thead&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;subscriber_id&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;list_id&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;status&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;created_at&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;th&gt;updated_at&lt;/th&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/thead&gt;&#xA;&#x9;&lt;tbody&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11180&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;confirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11181&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;confirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11182&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;confirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11183&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;confirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11184&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;confirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11185&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;confirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11186&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;confirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&#x9;&#x9;&lt;tr&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;11187&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;3&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;confirmed&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&lt;td&gt;2021-03-10 18:38:52.022231+00&lt;/td&gt;&#xA;&#x9;&#x9;&#x9;&lt;/tr&gt;&#xA;&#x9;&lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;p&gt;Now we can go ahead and send emails to all of these people without asking them to opt-in first.&lt;/p&gt;&#xA;&lt;h2 id=&#34;setting-up-ssl&#34;&gt;Setting up SSL&lt;/h2&gt;&#xA;&lt;p&gt;By default, listmonk runs over HTTP and doesn&amp;rsquo;t implement SSL. It is kinda required if you are running any service these days. So the next thing we need to do is to set up SSL support. I will be showing you how to do that by incorporating NGINX and certbot to listmonk via the &lt;code&gt;docker-compose.yml&lt;/code&gt;. I was able to set NGINX up by following &lt;a href=&#34;https://pentacent.medium.com/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71&#34;&gt;this helpful guide&lt;/a&gt; by Philipp and by going through &lt;a href=&#34;https://github.com/wmnnd/nginx-certbot&#34;&gt;this accompanying repo&lt;/a&gt; on GitHub.&lt;/p&gt;&#xA;&lt;p&gt;The first step is to create a &lt;code&gt;data/nginx&lt;/code&gt; folder in the same folder that contains the &lt;code&gt;docker-compose.yml&lt;/code&gt; file.&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;mkdir -p data/nginx&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now create a &lt;code&gt;nginx.conf&lt;/code&gt; file in this folder with the following content:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;server {&#xA;    listen 80;&#xA;    server_name example.com;&#xA;    server_tokens off;&#xA;&#xA;    location /.well-known/acme-challenge/ {&#xA;        root /var/www/certbot;&#xA;    }&#xA;&#xA;    location / {&#xA;        return 301 https://$host$request_uri;&#xA;    }&#xA;}&#xA;&#xA;server {&#xA;    listen 443 ssl;&#xA;    server_name example.com;&#xA;    server_tokens off;&#xA;&#xA;    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;&#xA;    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;&#xA;    include /etc/letsencrypt/options-ssl-nginx.conf;&#xA;    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;&#xA;&#xA;    location / {&#xA;        proxy_pass  http://app:9000;&#xA;        proxy_set_header    Host                $http_host;&#xA;        proxy_set_header    X-Real-IP           $remote_addr;&#xA;        proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Make sure you replace &lt;code&gt;example.com&lt;/code&gt; with your custom domain that you will be running this on. This can also be a CNAME.&lt;/p&gt;&#xA;&lt;p&gt;Now we have to download an init script from GitHub. You can get it &lt;a href=&#34;https://github.com/wmnnd/nginx-certbot/blob/62a1c61f54244859d33d5697bb954960f130901d/init-letsencrypt.sh&#34;&gt;from here&lt;/a&gt;. Download it and replace the domain name with your domain name and the sample email with your own email. I had to make one additional change to this file to make it work: comment out &lt;code&gt;nginx&lt;/code&gt; from  &lt;a href=&#34;https://github.com/wmnnd/nginx-certbot/blob/62a1c61f54244859d33d5697bb954960f130901d/init-letsencrypt.sh#L42&#34;&gt;line 42&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The resulting &lt;code&gt;init-letsencrypt.sh&lt;/code&gt; file will look something like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;#!/bin/bash&#xA;&#xA;if ! [ -x &amp;#34;$(command -v docker-compose)&amp;#34; ]; then&#xA;  echo &amp;#39;Error: docker-compose is not installed.&amp;#39; &amp;gt;&amp;amp;2&#xA;  exit 1&#xA;fi&#xA;&#xA;domains=(custom.yasoob.me)&#xA;rsa_key_size=4096&#xA;data_path=&amp;#34;./data/certbot&amp;#34;&#xA;email=&amp;#34;newsletter@yasoob.me&amp;#34; # Adding a valid address is strongly recommended&#xA;staging=0 # Set to 1 if you&amp;#39;re testing your setup to avoid hitting request limits&#xA;&#xA;if [ -d &amp;#34;$data_path&amp;#34; ]; then&#xA;  read -p &amp;#34;Existing data found for $domains. Continue and replace existing certificate? (y/N) &amp;#34; decision&#xA;  if [ &amp;#34;$decision&amp;#34; != &amp;#34;Y&amp;#34; ] &amp;amp;&amp;amp; [ &amp;#34;$decision&amp;#34; != &amp;#34;y&amp;#34; ]; then&#xA;    exit&#xA;  fi&#xA;fi&#xA;&#xA;&#xA;if [ ! -e &amp;#34;$data_path/conf/options-ssl-nginx.conf&amp;#34; ] || [ ! -e &amp;#34;$data_path/conf/ssl-dhparams.pem&amp;#34; ]; then&#xA;  echo &amp;#34;### Downloading recommended TLS parameters ...&amp;#34;&#xA;  mkdir -p &amp;#34;$data_path/conf&amp;#34;&#xA;  curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf &amp;gt; &amp;#34;$data_path/conf/options-ssl-nginx.conf&amp;#34;&#xA;  curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem &amp;gt; &amp;#34;$data_path/conf/ssl-dhparams.pem&amp;#34;&#xA;  echo&#xA;fi&#xA;&#xA;echo &amp;#34;### Creating dummy certificate for $domains ...&amp;#34;&#xA;path=&amp;#34;/etc/letsencrypt/live/$domains&amp;#34;&#xA;mkdir -p &amp;#34;$data_path/conf/live/$domains&amp;#34;&#xA;docker-compose run --rm --entrypoint &amp;#34;\&#xA;  openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\&#xA;    -keyout &amp;#39;$path/privkey.pem&amp;#39; \&#xA;    -out &amp;#39;$path/fullchain.pem&amp;#39; \&#xA;    -subj &amp;#39;/CN=localhost&amp;#39;&amp;#34; certbot&#xA;echo&#xA;&#xA;&#xA;echo &amp;#34;### Starting nginx ...&amp;#34;&#xA;docker-compose up --force-recreate -d # nginx&#xA;echo&#xA;&#xA;echo &amp;#34;### Deleting dummy certificate for $domains ...&amp;#34;&#xA;docker-compose run --rm --entrypoint &amp;#34;\&#xA;  rm -Rf /etc/letsencrypt/live/$domains &amp;amp;&amp;amp; \&#xA;  rm -Rf /etc/letsencrypt/archive/$domains &amp;amp;&amp;amp; \&#xA;  rm -Rf /etc/letsencrypt/renewal/$domains.conf&amp;#34; certbot&#xA;echo&#xA;&#xA;&#xA;echo &amp;#34;### Requesting Let&amp;#39;s Encrypt certificate for $domains ...&amp;#34;&#xA;#Join $domains to -d args&#xA;domain_args=&amp;#34;&amp;#34;&#xA;for domain in &amp;#34;${domains[@]}&amp;#34;; do&#xA;  domain_args=&amp;#34;$domain_args -d $domain&amp;#34;&#xA;done&#xA;&#xA;# Select appropriate email arg&#xA;case &amp;#34;$email&amp;#34; in&#xA;  &amp;#34;&amp;#34;) email_arg=&amp;#34;--register-unsafely-without-email&amp;#34; ;;&#xA;  *) email_arg=&amp;#34;--email $email&amp;#34; ;;&#xA;esac&#xA;&#xA;# Enable staging mode if needed&#xA;if [ $staging != &amp;#34;0&amp;#34; ]; then staging_arg=&amp;#34;--staging&amp;#34;; fi&#xA;&#xA;docker-compose run --rm --entrypoint &amp;#34;\&#xA;  certbot certonly --webroot -w /var/www/certbot \&#xA;    $staging_arg \&#xA;    $email_arg \&#xA;    $domain_args \&#xA;    --rsa-key-size $rsa_key_size \&#xA;    --agree-tos \&#xA;    --force-renewal&amp;#34; certbot&#xA;echo&#xA;&#xA;echo &amp;#34;### Reloading nginx ...&amp;#34;&#xA;docker-compose exec nginx nginx -s reload&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Next, we need to add an NGINX and certbot service in the &lt;code&gt;docker-compose.yml&lt;/code&gt; file. Add the following two services to the &lt;code&gt;docker-compose.yml&lt;/code&gt; file:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;nginx:&#xA;    image: nginx:mainline-alpine&#xA;    restart: unless-stopped&#xA;    ports:&#xA;      - &amp;#34;80:80&amp;#34;&#xA;      - &amp;#34;443:443&amp;#34;&#xA;    volumes:&#xA;      - ./data/nginx:/etc/nginx/conf.d&#xA;      - ./data/certbot/conf:/etc/letsencrypt&#xA;      - ./data/certbot/www:/var/www/certbot&#xA;    networks:&#xA;      - listmonk&#xA;    depends_on:&#xA;      - app&#xA;    command: &amp;#34;/bin/sh -c &amp;#39;while :; do sleep 6h &amp;amp; wait $${!}; nginx -s reload; done &amp;amp; nginx -g \&amp;#34;daemon off;\&amp;#34;&amp;#39;&amp;#34;&#xA;&#xA;  certbot:&#xA;    image: certbot/certbot&#xA;    container_name: certbot&#xA;    volumes:&#xA;      - ./data/certbot/conf:/etc/letsencrypt&#xA;      - ./data/certbot/www:/var/www/certbot&#xA;    networks:&#xA;      - listmonk&#xA;    depends_on:&#xA;      - nginx&#xA;    entrypoint: &amp;#34;/bin/sh -c &amp;#39;trap exit TERM; while :; do certbot renew; sleep 12h &amp;amp; wait $${!}; done;&amp;#39;&amp;#34;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The resulting &lt;code&gt;docker-compose.yml&lt;/code&gt; will look like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;version: &amp;#34;3.7&amp;#34;&#xA;&#xA;x-app-defaults: &amp;amp;app-defaults&#xA;  restart: unless-stopped&#xA;  image: listmonk/listmonk:latest&#xA;  ports:&#xA;    - &amp;#34;9000:9000&amp;#34;&#xA;  networks:&#xA;    - listmonk&#xA;&#xA;x-db-defaults: &amp;amp;db-defaults&#xA;    image: postgres:11&#xA;    ports:&#xA;      - &amp;#34;9432:5432&amp;#34;&#xA;    networks:&#xA;      - listmonk&#xA;    environment:&#xA;      - POSTGRES_PASSWORD=listmonk&#xA;      - POSTGRES_USER=listmonk&#xA;      - POSTGRES_DB=listmonk&#xA;    restart: unless-stopped&#xA;&#xA;services:&#xA;  db:&#xA;    &amp;lt;&amp;lt;: *db-defaults&#xA;    volumes:&#xA;      - type: volume&#xA;        source: listmonk-data&#xA;        target: /var/lib/postgresql/data&#xA;&#xA;  app:&#xA;    &amp;lt;&amp;lt;: *app-defaults&#xA;    depends_on:&#xA;      - db&#xA;    command: &amp;#34;./listmonk --static-dir=/listmonk/static&amp;#34;&#xA;    volumes:&#xA;      - ./config.toml/:/listmonk/config.toml&#xA;      - ./static:/listmonk/static&#xA;  &#xA;  nginx:&#xA;    image: nginx:mainline-alpine&#xA;    restart: unless-stopped&#xA;    ports:&#xA;      - &amp;#34;80:80&amp;#34;&#xA;      - &amp;#34;443:443&amp;#34;&#xA;    volumes:&#xA;      - ./data/nginx:/etc/nginx/conf.d&#xA;      - ./data/certbot/conf:/etc/letsencrypt&#xA;      - ./data/certbot/www:/var/www/certbot&#xA;    networks:&#xA;      - listmonk&#xA;    depends_on:&#xA;      - app&#xA;    command: &amp;#34;/bin/sh -c &amp;#39;while :; do sleep 6h &amp;amp; wait $${!}; nginx -s reload; done &amp;amp; nginx -g \&amp;#34;daemon off;\&amp;#34;&amp;#39;&amp;#34;&#xA;&#xA;  certbot:&#xA;    image: certbot/certbot&#xA;    container_name: certbot&#xA;    volumes:&#xA;      - ./data/certbot/conf:/etc/letsencrypt&#xA;      - ./data/certbot/www:/var/www/certbot&#xA;    networks:&#xA;      - listmonk&#xA;    depends_on:&#xA;      - nginx&#xA;    entrypoint: &amp;#34;/bin/sh -c &amp;#39;trap exit TERM; while :; do certbot renew; sleep 12h &amp;amp; wait $${!}; done;&amp;#39;&amp;#34;&#xA;&#xA;networks:&#xA;  listmonk:&#xA;&#xA;volumes:&#xA;  listmonk-data:&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;At this point your file and directory structure should resemble this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;.&#xA;├── README.md&#xA;├── config.toml&#xA;├── data&#xA;│   └── nginx&#xA;│       └── nginx.conf&#xA;├── docker-compose.yml&#xA;├── init-letsencrypt.sh&#xA;└── static&#xA;    ├── email-templates&#xA;    │   ├── base.html&#xA;    │   ├── campaign-status.html&#xA;    │   ├── default.tpl&#xA;    │   ├── import-status.html&#xA;    │   ├── subscriber-data.html&#xA;    │   ├── subscriber-optin-campaign.html&#xA;    │   └── subscriber-optin.html&#xA;    └── public&#xA;        ├── static&#xA;        │   ├── favicon.png&#xA;        │   ├── logo.png&#xA;        │   ├── logo.svg&#xA;        │   ├── script.js&#xA;        │   └── style.css&#xA;        └── templates&#xA;            ├── index.html&#xA;            ├── message.html&#xA;            ├── optin.html&#xA;            ├── subscription-form.html&#xA;            └── subscription.html&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Everything is in place and we can run the &lt;code&gt;init-letsencrypt.sh&lt;/code&gt; file. It will generate proper SSL certificates for us and will expose listmonk on port 8080.&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;I wanted to contribute to the open-source mailing list ecosystem by writing this article. We need more open source tools in this area. I am currently testing out listmonk in production on this blog. I am not sure if the lack of bounce tracking and granular list management will become an issue in the future but I will try to make sure I give listmonk a proper try before moving on. I hope you all learned something new and I made it a little bit easier for you to set up listmonk. If you have any questions you can head over to the &lt;a href=&#34;https://github.com/knadh/listmonk&#34;&gt;listmonk GitHub page&lt;/a&gt; and open an issue. The developers are super responsive. &lt;a href=&#34;https://nadh.in/&#34;&gt;Kailash Nadh&lt;/a&gt; has done a commendable job with this software.&lt;/p&gt;&#xA;&lt;p&gt;You can also get the final setup code from &lt;a href=&#34;https://github.com/yasoob/listmonk-setup&#34;&gt;this repository&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;If you have any feedback, comments, or suggestions please comment below 😊&lt;/p&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Making a Serverless eBook Stamping &amp; Delivery Service</title>
				<link>https://yasoob.me/posts/serverless-ebook-stamping-delivery-ses-sqs-aws/</link>
				<pubDate>Mon, 08 Mar 2021 03:25:08 -0500</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/serverless-ebook-stamping-delivery-ses-sqs-aws/</guid>
				<category>programming</category>
				<category>aws</category>
				<category>serverless</category>
				<description>I recently had to make a custom ebook stamping and delivery service for Practical Python Projects book. In this article, I will explain why and how I made this service using AWS lambda as the serverless platform. I will also show you how to use S3 for file hosting, SQS for message passing, SES for automated email delivery, and PyPDF2 + Reportlab + pdfrw for PDF stamping.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/serverless/serverless-header.png&#34; alt=&#34;Making a Serverless eBook Stamping &amp;amp; Delivery Service&#34;&gt;&lt;/p&gt;&lt;p&gt;Hi everyone! 👋 I recently launched the release candidate of my &lt;a href=&#34;https://practicalpython.yasoob.me&#34;&gt;Practical Python Projects&lt;/a&gt; book. There were a couple of unique issues I was facing and I decided to write about them and share how I got around most of them. This is not an end-to-end service implementation tutorial but rather a quick walk-through. I will show you most of the important bits and pieces of code for this service. If you are pressed for time, you can go to whatever section sounds interesting and start reading from there.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt; I am using Paddle as my merchant. Paddle sends webhook requests to a service that is hosted on AWS Lambda. This service stamps PDFs, saves them on S3 (Simple Storage Service), and emails a pre-signed URL to customers using Amazon SES (Simple Email Service).&lt;/p&gt;&#xA;&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://practicalpython.yasoob.me&#34;&gt;Practical Python Projects&lt;/a&gt; isn&amp;rsquo;t my first book but it is the first one that I wanted to sell. There are a couple of good options for indie authors: Gumroad, SendOwl, etc. However, most of these services aren&amp;rsquo;t a viable option for people in a few major countries (including Pakistan) as PayPal and Stripe are the only supported payout methods and they aren&amp;rsquo;t available throughout the world. As I couldn&amp;rsquo;t use any of these services, I decided to look around. I expanded the scope of my search by looking for payment processors as well and not simply eBook selling options.&lt;/p&gt;&#xA;&lt;p&gt;After a while, I came across &lt;a href=&#34;https://paddle.com/&#34;&gt;Paddle&lt;/a&gt;. It supported direct bank deposits and Payoneer as payout options. This meant that it could be used in most countries (including Pakistan). However, Paddle also had a problem which I found out only after creating a product listing on the platform. Its eBook publishing features and mailing list management features were severely limited but considering that this was the only viable payment gateway, I still decided to move forward with it.&lt;/p&gt;&#xA;&lt;h3 id=&#34;issues&#34;&gt;Issues&lt;/h3&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s talk about the drawbacks of using Paddle for selling eBooks online. Paddle allows you to upload a product as a digital download on the platform but the link to the product is not scoped to a customer. It is accessible to whoever gets their hands on the link. This would have been fine if there were two other features available:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;PDF stamping with customer name&lt;/li&gt;&#xA;&lt;li&gt;Time based or number of accesses based link expiry&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;However, Paddle didn&amp;rsquo;t have any of these. The links were non-expiring and there was no PDF stamping. If you are an indie author, chances are, you might already know why these features are important. These features help curb piracy. If the links are expiring, a person can&amp;rsquo;t just post them to an online forum and have them stay available for eternity. And if a PDF is stamped with a customer&amp;rsquo;s name, the expectation and hope are that they would not want to put the book online with their name in-tact.&lt;/p&gt;&#xA;&lt;p&gt;Thankfully, Paddle supports webhooks. Being a programmer, there was a possibility for me to hack something together that generated stamped PDFs and emailed them to customers using Paddle&amp;rsquo;s webhooks support. It sounded like a fun side-project.&lt;/p&gt;&#xA;&lt;p&gt;Have you ever spent so much time doing meta hacking and micro-optimizations that you forget the bigger picture? I have been down that rabbit hole before and wanted to stay away from it this time. I promised myself that I would do the least amount of work required to get a service up and running and start selling the book in a week max.&lt;/p&gt;&#xA;&lt;p&gt;If I was to finish this project within a week, I had to figure out the minimum requirements for this service before diving into the code and this also meant I didn&amp;rsquo;t fall into this over-planning trap:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://imgs.xkcd.com/comics/efficiency.png&#34; alt=&#34;XKCD Strategy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;h3 id=&#34;requirements&#34;&gt;Requirements&lt;/h3&gt;&#xA;&lt;p&gt;These were the requirements I managed to come up with:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;File hosting: A cheap and convenient file hosting service with an easy API and support for expiring links.&lt;/li&gt;&#xA;&lt;li&gt;Email delivery: A cheap transactional email service that doesn&amp;rsquo;t break the bank and has good and fast deliverability.&lt;/li&gt;&#xA;&lt;li&gt;Webhook service: A cheap managed server that doesn&amp;rsquo;t require constant upkeep and should be a set &amp;amp; forget type scenario.&lt;/li&gt;&#xA;&lt;li&gt;Cheap: No hard limit on how much I can spend but the whole solution should ideally be free or as least expensive as possible&lt;/li&gt;&#xA;&lt;li&gt;Learning: Bonus points if I can learn something new in the process&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3 id=&#34;solution&#34;&gt;Solution&lt;/h3&gt;&#xA;&lt;p&gt;There were quite a few options that fit the bill and it took me a while to make the final decision.&lt;/p&gt;&#xA;&lt;p&gt;Every major cloud provider has a file hosting service and there are quite a few transactional email delivery services. For file hosting, I ended up going with Amazon S3 (Simple Storage Service) as it had a generous free tier and was fairly cheap even beyond the free quota. As for email delivery, I decided to go with Amazon SES (Simple Email Service) for roughly the same reasons: cheap + generous free quota.&lt;/p&gt;&#xA;&lt;p&gt;For the webhook service, I thought about going the typical route of setting up an API using Flask or a similar Python framework and host it on Digital Ocean. However, there were a couple of issues with this. This wasn&amp;rsquo;t the cheapest option and my attention was being attracted by &amp;ldquo;serverless&amp;rdquo; offerings. By this point, I had been hearing about serverless computing so much that it was kind of hard to ignore. It sounded like a good fit for my situation too. I would not have to worry about updating the infrastructure on which the serverless function would be running and I would not be charged if there were no book sales happening. A win-win situation. I decided to give in to the serverless fad and go with AWS lambda. This was a good decision because it meant I would be learning something new as well. I had used lambda before but that was around 2-3 years ago at a hackathon. It was high time to give it a second look.&lt;/p&gt;&#xA;&lt;p&gt;The PDF stamping turned out to be harder than I thought and led me to a couple of unexpected edge cases. I looked around for a Python library because I wanted to keep all of my code in Python. I came across &lt;code&gt;PyPDF2&lt;/code&gt; and &lt;code&gt;reportlab&lt;/code&gt;. I made the initial version of the stamping program using &lt;code&gt;PyPDF2&lt;/code&gt; but later replaced it with &lt;code&gt;pdfrw&lt;/code&gt;. I will share the reasons later.&lt;/p&gt;&#xA;&lt;h2 id=&#34;solution-in-a-bit-detail&#34;&gt;Solution in a bit detail&lt;/h2&gt;&#xA;&lt;p&gt;Instead of working with each service separately, I decided to use &lt;a href=&#34;https://serverless.com/&#34;&gt;serverless&lt;/a&gt;. It allows you to launch serverless deployments super quickly and also helps make them reproducible. You only need a &lt;code&gt;serverless.yml&lt;/code&gt; file that defines all the services you want to provision and some other code you might want to run on the server. If you are planning on running some Python code on AWS Lambda then this would mean having at least these three files:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;serverless.yml&lt;/code&gt;: Declare the services you need&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;handler.py&lt;/code&gt;: Write the handler code for a Lambda function&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;requirements.txt&lt;/code&gt;: Declare all the dependencies your Python code relies on&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;getting-started-with-serverless&#34;&gt;Getting started with serverless&lt;/h2&gt;&#xA;&lt;p&gt;Serverless has &lt;a href=&#34;https://www.serverless.com/framework/docs/&#34;&gt;decent documentation&lt;/a&gt;. It is really easy to get started and the CLI tool sets up the directory structure for you.&lt;/p&gt;&#xA;&lt;p&gt;You can install serverless using NPM by typing &lt;code&gt;npm install -g serverless&lt;/code&gt; and then set it up by running the &lt;code&gt;serverless&lt;/code&gt; command in the terminal. Choose the appropriate options and you will have it set it up for working with AWS in no time.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You aren&amp;rsquo;t required to use AWS, serverless supports most other major cloud providers as well&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s start a new serverless project by typing this in the terminal:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ serverless create \&#xA;  --template aws-python3 \&#xA;  --name automated-book-delivery \&#xA;  --path automated-book-delivery&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is going to create a serverless project inside the &lt;code&gt;automated-book-delivery&lt;/code&gt; path and name it &lt;code&gt;automated-book-delivery&lt;/code&gt;. Now we can &lt;code&gt;cd&lt;/code&gt; into the folder and set up a virtual environment to do local development.&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ cd automated-book-delivery&#xA;$ python -m venv vevn&#xA;$ source venv/bin/activate&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The directory structure should look like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;.&#xA;├── handler.py&#xA;├── serverless.yml&#xA;└── venv&#xA;    ├...&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After stripping the comments, the &lt;code&gt;serverless.yml&lt;/code&gt; file should resemble this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;service: automated-book-delivery&#xA;frameworkVersion: &amp;#39;2&amp;#39;&#xA;&#xA;provider:&#xA;  name: aws&#xA;  runtime: python3.8&#xA;  lambdaHashingVersion: 20201221&#xA;&#xA;functions:&#xA;  hello:&#xA;    handler: handler.hello&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And the &lt;code&gt;handler.py&lt;/code&gt; file should look like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;import json&#xA;&#xA;&#xA;def hello(event, context):&#xA;    body = {&#xA;        &amp;#34;message&amp;#34;: &amp;#34;Go Serverless v1.0! Your function executed successfully!&amp;#34;,&#xA;        &amp;#34;input&amp;#34;: event&#xA;    }&#xA;&#xA;    response = {&#xA;        &amp;#34;statusCode&amp;#34;: 200,&#xA;        &amp;#34;body&amp;#34;: json.dumps(body)&#xA;    }&#xA;&#xA;    return response&#xA;&#xA;    # Use this code if you don&amp;#39;t use the http event with the LAMBDA-PROXY&#xA;    # integration&#xA;    &amp;#34;&amp;#34;&amp;#34;&#xA;    return {&#xA;        &amp;#34;message&amp;#34;: &amp;#34;Go Serverless v1.0! Your function executed successfully!&amp;#34;,&#xA;        &amp;#34;event&amp;#34;: event&#xA;    }&#xA;    &amp;#34;&amp;#34;&amp;#34;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Depending on how barebones your serverless infra is going to be, you might have to worry about only these two files. You can deploy the service by using this command:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ sls deploy&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;sls&lt;/code&gt; is just an alias for &lt;code&gt;serverless&lt;/code&gt;&lt;/p&gt;&#xA;&lt;h2 id=&#34;exploring-webhook-data-structure&#34;&gt;Exploring webhook data structure&lt;/h2&gt;&#xA;&lt;p&gt;While exploring the response of the Paddle webhook, I made extensive use of online request bin websites. These websites provide you with a public URL where you can send a webhook request and afterwards they allow you to inspect what the request looked like and what data it contained. The one I used was &lt;a href=&#34;https://webhook.site&#34;&gt;webhook.site&lt;/a&gt;. It made it easy to visualize what kind of data Paddle was going to send.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://developer.paddle.com/getting-started/intro&#34;&gt;Paddle docs&lt;/a&gt; do a good job of explaining it but I don&amp;rsquo;t think there is any substitute for live data. It just gives everything a whole lot more context and makes it holistic. This is what the webhook request looked like on webhook.site when I sent a test request using Paddle:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/serverless/webhook-example.png&#34; alt=&#34;Webhook Example&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;I took the raw data from the webhook.site and tried parsing it using Python in the interpreter. I love using the interpreter for these tasks as it makes the feedback loop super quick and I can iterate without losing a lot of precious time.&lt;/p&gt;&#xA;&lt;h2 id=&#34;external-api-endpoint&#34;&gt;External API endpoint&lt;/h2&gt;&#xA;&lt;p&gt;This is the endpoint that receives the webhook request from Paddle. My external API endpoint handling code looks like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;def hello(event, context):&#xA;    paddle_data = dict(parse_qsl(event[&amp;#39;body&amp;#39;], keep_blank_values=True))&#xA;    &#xA;    signature = paddle_data.get(&amp;#34;p_signature&amp;#34;)&#xA;&#xA;    valid, data = verify_signature(paddle_data)&#xA;    &#xA;    if not valid:&#xA;        print(&amp;#34;Signature verification failed&amp;#34;)&#xA;        return&#xA;&#xA;    name = data[&amp;#39;customer_name&amp;#39;]&#xA;    email = data[&amp;#39;email&amp;#39;]&#xA;    order_no = data[&amp;#39;p_order_id&amp;#39;]&#xA;    &#xA;    sqs = boto3.resource(&amp;#39;sqs&amp;#39;, region_name=&amp;#34;us-west-1&amp;#34;)&#xA;    &#xA;    queue = sqs.get_queue_by_name(QueueName=os.environ[&amp;#34;QUEUE_NAME&amp;#34;])&#xA;    response = queue.send_message(MessageBody=f&amp;#39;{name}::{email}::{order_no}&amp;#39;)&#xA;    return {&#xA;        &amp;#34;statusCode&amp;#34;: 200,&#xA;        &amp;#34;body&amp;#34;: json.dumps({&amp;#34;Sent Message&amp;#34;:response})&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The event parameter contains the request that lambda received. &lt;code&gt;event&lt;/code&gt; is a dictionary and the &lt;code&gt;body&lt;/code&gt; key contains the POST data that was sent with the request. I take the &lt;code&gt;body&lt;/code&gt; and parse it using &lt;code&gt;parse_qsl&lt;/code&gt; from the &lt;a href=&#34;https://docs.python.org/3/library/urllib.parse.html#urllib.parse.parse_qsl&#34;&gt;&lt;code&gt;urllib.parse&lt;/code&gt;&lt;/a&gt; package (this is all Python 3). &lt;code&gt;parse_qsl&lt;/code&gt; turns the data into a list of key, value pairs which I later turn into a dictionary.&lt;/p&gt;&#xA;&lt;p&gt;Someone with a keen eye might be wondering why I have &lt;code&gt;keep_blank_values=True&lt;/code&gt; as part of the &lt;code&gt;parse_qsl&lt;/code&gt; function call. This is important because Paddle might send some empty values and the default behavior of &lt;code&gt;parse_qsl&lt;/code&gt; is to just omit them from the returned list. However, I needed to retain those if I wanted to accurately recalculate the signature of the whole payload.&lt;/p&gt;&#xA;&lt;p&gt;When Paddle sends webhook requests, it includes a &lt;code&gt;p_signature&lt;/code&gt; field which is an encrypted signature of all the values in the payload. It is encrypted using public-key crypto and Paddle provides vendors with a public key they can use to encrypt a recalculated signature, match it with the encrypted signature paddle sent, and make sure the request was actually generated by Paddle. This is very useful as it helps make sure we only respond to the webhooks that are actually generated by Paddle and not an impersonator. Most (if not all) webhook services contain a relatively similar feature for verifying the authenticity of webhook calls.&lt;/p&gt;&#xA;&lt;p&gt;After parsing the payload data using &lt;code&gt;parse_qsl&lt;/code&gt;, I verify the signature by making a call to the &lt;code&gt;verify_signature&lt;/code&gt; function. This is a custom function based on the description provided over at &lt;a href=&#34;https://developer.paddle.com/webhook-reference/verifying-webhooks&#34;&gt;Paddle docs&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/serverless/paddle-docs.png&#34; alt=&#34;Paddle docs&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Afterwards, I extract the name, email, and order no from the payload, merge them into a single string by using &lt;code&gt;::&lt;/code&gt; as the separator and push it to an SQS (Simple Queue Service) queue. I could have just set these three (name, email, order no) values as &lt;code&gt;MessageAttributes&lt;/code&gt; but I liked merging them together and keep the message size and processing code shorter.&lt;/p&gt;&#xA;&lt;p&gt;Lastly, I return a 200 status code as expected by Paddle. I have simplified this code a little bit by getting rid of error checking for brevity.&lt;/p&gt;&#xA;&lt;p&gt;You might be wondering why I am pushing a message to the SQS queue and not processing the PDF in the same request. Well, the initial PDF stamping code that I had written was taking closer to 29s to run on lambda and the public API endpoints have a maximum timeout of 30s. This was causing a couple of requests to time out so I had to figure out how to decouple the external API from the actual PDF processing.&lt;/p&gt;&#xA;&lt;p&gt;One solution to this problem was to use SQS. The idea is that you send a message to this queue and as soon as the queue receives a new message, it triggers another lambda function. This second lambda function is not an external API endpoint and so it can have a max timeout of 15 minutes. That was more than enough for my case.&lt;/p&gt;&#xA;&lt;h2 id=&#34;getting-sqs-up-and-running&#34;&gt;Getting SQS up and running&lt;/h2&gt;&#xA;&lt;p&gt;SQS was a bit tricky to get up and running. I was getting a ton of errors that I have now forgotten. I first declared it as a resource in my &lt;code&gt;serverless.yml&lt;/code&gt; file:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;resources:&#xA;  Resources:&#xA;    # ...&#xA;    BookDelivery:&#xA;      Type: &amp;#34;AWS::SQS::Queue&amp;#34;&#xA;      Properties:&#xA;        QueueName: automated-book-delivery&#xA;        VisibilityTimeout: 1800&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then I requested the following permissions for the IAM role:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;- Effect: &amp;#34;Allow&amp;#34;&#xA;  Action:&#xA;    - &amp;#34;sqs:ListQueues&amp;#34;&#xA;    - &amp;#34;sqs:GetQueueUrl&amp;#34;&#xA;    - &amp;#34;sqs:DeleteMessage&amp;#34;&#xA;    - &amp;#34;sqs:ReceiveMessage&amp;#34;&#xA;    - &amp;#34;sqs:SendMessage&amp;#34;&#xA;    - &amp;#34;sqs:SetQueueAttributes&amp;#34;&#xA;    - &amp;#34;sqs:GetQueueAttributes&amp;#34;&#xA;  Resource: &amp;#34;*&amp;#34;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I tried making the &lt;code&gt;Resource&lt;/code&gt; value more granular and target only the queue I made for this service but it was failing. I was getting a ton of access denied errors:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ClientError An error occurred (AccessDenied) when calling the ListQueues operation: Access to the resource https://us-west-1.queue.amazonaws.com/ is denied&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I had given the IAM role, the &lt;code&gt;ListQueues&lt;/code&gt; permission but the &lt;code&gt;Resource&lt;/code&gt; scope was too narrow. I was running out of time so I decided to use this bandaid solution and move on. The queue was successfully sending and receiving messages at this point and that is all that I needed.&lt;/p&gt;&#xA;&lt;p&gt;Lastly, I added this queue as a trigger for a lambda function:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;functions:&#xA;    # --snip--&#xA;    process:&#xA;        handler: handler.process_book&#xA;        environment:&#xA;            REGION: us-west-1&#xA;            QUEUE_NAME: automated-book-delivery&#xA;        events:&#xA;            - sqs:&#xA;                batchSize: 1&#xA;                arn:&#xA;                    Fn::GetAtt:&#xA;                    - BookDelivery&#xA;                    - Arn&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;batchSize: 1&lt;/code&gt; option makes sure that our function is called with only one queue message. This was useful because if a lambda function is called with 10 messages (as a list of messages) and the function fails while processing the 9th message, all messages are re-enqueued. We can either add proper error processing or just use a batchSize of 1. There are actual cost tradeoffs happening but my service wasn&amp;rsquo;t going to be used by a ton of people so I wasn&amp;rsquo;t too concerned about the tradeoffs. Remember, I was aiming to launch this as quickly as possible.&lt;/p&gt;&#xA;&lt;p&gt;The API for sending messages to the queue is fairly simple (&lt;a href=&#34;https://boto3.amazonaws.com/v1/documentation/api/latest/guide/sqs-example-sending-receiving-msgs.html&#34;&gt;boto3 SQS docs&lt;/a&gt;):&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# Sending message&#xA;sqs = boto3.resource(&amp;#39;sqs&amp;#39;, region_name=&amp;#34;us-west-1&amp;#34;)&#xA;queue = sqs.get_queue_by_name(QueueName=&amp;#34;queue-name&amp;#34;)&#xA;response = queue.send_message(MessageBody=f&amp;#39;test message&amp;#39;)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We don&amp;rsquo;t need to worry about receiving messages from the Queue as lambda will call our handler with the queue message as an argument if we set a queue as a trigger for a lambda function.&lt;/p&gt;&#xA;&lt;h2 id=&#34;pdf-processing&#34;&gt;PDF processing&lt;/h2&gt;&#xA;&lt;p&gt;This is the function that is triggered by the queue message. It expects a couple of environment variables:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;BUCKET: name for destination S3 bucket&lt;/li&gt;&#xA;&lt;li&gt;REGION: The region this service is running in&lt;/li&gt;&#xA;&lt;li&gt;SOURCE_BUCKET: S3 bucket that contains source PDF and other source files (EPUB etc)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;These variables are set in the &lt;code&gt;serverless.yml&lt;/code&gt; file as shown in the previous section. Only one S3 bucket is created as a resource with this service. The second S3 bucket is where I will upload the source files and it will just keep the original unstamped files.&lt;/p&gt;&#xA;&lt;p&gt;But before we get into the actual function code, let&amp;rsquo;s take a look at the PDF stamping.&lt;/p&gt;&#xA;&lt;h3 id=&#34;pdf-stamping&#34;&gt;PDF Stamping&lt;/h3&gt;&#xA;&lt;p&gt;In the solution section I mentioned that I started with &lt;a href=&#34;https://github.com/mstamy2/PyPDF2&#34;&gt;&lt;code&gt;PyPDF2&lt;/code&gt;&lt;/a&gt;. This is the kind of PDF stamping I was aiming for:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/serverless/stamp-example.png&#34; alt=&#34;Stamping output&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;There are two steps involved in making this:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Create the watermark&lt;/li&gt;&#xA;&lt;li&gt;Merge the watermark with source PDF&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I ended up using this code for doing the stamping:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;from PyPDF2 import PdfFileWriter, PdfFileReader&#xA;import io&#xA;from reportlab.pdfgen import canvas&#xA;from reportlab.platypus import SimpleDocTemplate&#xA;from reportlab.lib.pagesizes import letter&#xA;&#xA;packet = io.BytesIO()&#xA;&#xA;PAGE_WIDTH  = letter[0]&#xA;&#xA;# Create a PDF using Reportlab&#xA;caption = (&amp;#34;Prepared exclusively for YASOOB KHALID &amp;#34;&#xA;                    &amp;#34;(hi@yasoob.me)  Transaction: 0068830245&amp;#34;)&#xA;can = canvas.Canvas(packet, pagesize=letter)&#xA;can.setFont(&amp;#34;Helvetica&amp;#34;, 10)&#xA;can.setFillColorRGB(0.703125,0.703125,0.703125)&#xA;can.drawCentredString(PAGE_WIDTH/2, 20, caption)&#xA;can.save()&#xA;&#xA;packet.seek(0)&#xA;&#xA;with open(&amp;#34;book.pdf&amp;#34;, &amp;#34;rb&amp;#34;) as input_file:&#xA;    input_pdf = PdfFileReader(input_file)&#xA;    watermark_pdf = PdfFileReader(packet)&#xA;        &#xA;    watermark_page = watermark_pdf.getPage(0)&#xA;    output = PdfFileWriter()&#xA;&#xA;    # Don&amp;#39;t stamp the cover page&#xA;    pdf_page = input_pdf.getPage(0)&#xA;    output.addPage(pdf_page)&#xA;&#xA;    for i in range(1, input_pdf.getNumPages()):&#xA;        pdf_page = input_pdf.getPage(i)&#xA;        pdf_page.mergePage(watermark_page)&#xA;        output.addPage(pdf_page)&#xA;&#xA;    with open(&amp;#34;output.pdf&amp;#34;, &amp;#34;wb&amp;#34;) as merged_file:&#xA;        output.write(merged_file)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We first create a canvas object and then write &amp;ldquo;Prepared exclusively for YASOOB KHALID (&lt;a href=&#34;mailto:hi@yasoob.me&#34;&gt;hi@yasoob.me&lt;/a&gt;)  Transaction: 0068830245&amp;rdquo; as a centered string that is 20 units from the bottom. We then open the source pdf (&lt;code&gt;book.pdf&lt;/code&gt;) and the generated watermark PDF using the &lt;code&gt;PdfFileReader&lt;/code&gt; class of &lt;code&gt;PyPDF2&lt;/code&gt; and merge the watermark with the source.&lt;/p&gt;&#xA;&lt;p&gt;While doing this, we skip over the first page (page no 0) so that the cover of the book isn&amp;rsquo;t watermarked and process the rest of the pages normally by merging them with the watermark.&lt;/p&gt;&#xA;&lt;p&gt;Finally, we save the merged PDF as &lt;code&gt;output.pdf&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This worked. A typical run of the 329 page PDF took around 25-30 seconds. But there was a big issue. After sending out this merged version of the PDF to customers, one person reached out to me and told me about the TOC links not working. I was a bit confused as the original PDF had working links in the TOC.&lt;/p&gt;&#xA;&lt;p&gt;The left image is from the original PDF and the right image is from the stamped PDF. Look at the bookmark list on the left PDF and how it is missing from the right PDF.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/serverless/bookmarks-gone.png&#34; alt=&#34;Bokmarks gone&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;It was only after this issue that I started to look for other options. I spent a long time trying to figure out if &lt;code&gt;PyPDF2&lt;/code&gt; would help me retain the bookmarks but I wasn&amp;rsquo;t able to figure out a solution. Moreover, I had found out about this issue while the book was already selling so I had to figure out a solution quickly.&lt;/p&gt;&#xA;&lt;p&gt;I did some research and came across a pure Python PDF manipulation library &lt;a href=&#34;https://github.com/pmaupin/pdfrw&#34;&gt;&lt;code&gt;pdfrw&lt;/code&gt;&lt;/a&gt;. Turns out, it was super easy to do the PDF stamping using &lt;code&gt;pdfrw&lt;/code&gt; and the library also retained the bookmarks without any special commands. Additionally, the stamping code was quicker and shorter than before. The resulting script looked like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;from pdfrw import PdfReader, PdfWriter, PageMerge&#xA;import io&#xA;from reportlab.pdfgen import canvas&#xA;from reportlab.platypus import SimpleDocTemplate&#xA;from reportlab.lib.pagesizes import letter&#xA;&#xA;packet = io.BytesIO()&#xA;&#xA;PAGE_WIDTH  = letter[0]&#xA;PAGE_HEIGHT = letter[1]&#xA;&#xA;# create a new PDF with Reportlab&#xA;caption = (&amp;#34;Prepared exclusively for YASOOB KHALID &amp;#34;&#xA;                    &amp;#34;(hi@yasoob.me)  Transaction: 0068830245&amp;#34;)&#xA;can = canvas.Canvas(packet, pagesize=letter)&#xA;can.setFont(&amp;#34;Helvetica&amp;#34;, 10)&#xA;can.setFillColorRGB(0.703125,0.703125,0.703125)&#xA;can.drawCentredString(PAGE_WIDTH/2, 20, caption)&#xA;can.save()&#xA;&#xA;packet.seek(0)&#xA;&#xA;with open(&amp;#34;book-bak.pdf&amp;#34;, &amp;#34;rb&amp;#34;) as input_file:&#xA;    input_pdf = PdfReader(input_file)&#xA;    watermark_pdf = PageMerge().add(PdfReader(packet).pages[0])[0]&#xA;&#xA;    for page in input_pdf.pages[6:]:&#xA;        PageMerge(page).add(watermark_pdf).render()&#xA;&#xA;    final_pdf = io.BytesIO()&#xA;    PdfWriter(final_pdf, trailer=input_pdf).write()&#xA;    final_pdf.seek(0)&#xA;    with open(&amp;#34;output.pdf&amp;#34;, &amp;#34;wb&amp;#34;) as merged_file:&#xA;        merged_file.write(final_pdf.read())&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The code was also surprisingly quick. I had never done any automated PDF manipulation before so I had no idea what kind of runtimes I should expect. But &lt;code&gt;pdfrw&lt;/code&gt; code ended up taking only 2-3 seconds to do the stamping as compared to 30 seconds taken by &lt;code&gt;PyPDF2&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h3 id=&#34;turning-pdf-stamping-into-a-lambda-function&#34;&gt;Turning PDF stamping into a lambda function&lt;/h3&gt;&#xA;&lt;p&gt;Lambda only has access to a &lt;code&gt;/tmp&lt;/code&gt; directory and I was really trying not to use it if at all possible. This meant that I had to download the source PDF from S3 to memory and put the rendered PDF in memory before uploading it to S3 . This was fairly straightforward as I had done similar stuff before where I used the &lt;a href=&#34;https://docs.python.org/3/library/io.html#io.BytesIO&#34;&gt;&lt;code&gt;io.BytesIO()&lt;/code&gt;&lt;/a&gt; object as a file. I am only going to show you the stripped down function code that uses &lt;code&gt;pdfrw&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;def process_book(event, context):&#xA;    for record in event[&amp;#39;Records&amp;#39;]:&#xA;       payload=record[&amp;#34;body&amp;#34;]&#xA;&#xA;    message = event[&amp;#39;Records&amp;#39;][0][&amp;#39;body&amp;#39;]&#xA;    name, email, order_no = message.split(&amp;#39;::&amp;#39;)&#xA;    client_ref=f&amp;#34;{name}_{email}_{order_no}&amp;#34;&#xA;&#xA;    packet = io.BytesIO()&#xA;    final_pdf = io.BytesIO()&#xA;&#xA;    PAGE_WIDTH  = letter[0]&#xA;&#xA;    # create a new PDF with Reportlab&#xA;    caption = (f&amp;#34;Prepared exclusively for {name} ({email}) &amp;#34;&#xA;                &amp;#34;Transaction: {order_no}&amp;#34;)&#xA;    can = canvas.Canvas(packet, pagesize=letter)&#xA;    can.setFont(&amp;#34;Helvetica&amp;#34;, 10)&#xA;    can.setFillColorRGB(0.703125,0.703125,0.703125)&#xA;    can.drawCentredString(PAGE_WIDTH/2, 20, caption)&#xA;    can.save()&#xA;&#xA;    packet.seek(0)&#xA;&#xA;    original_pdf = io.BytesIO()&#xA;    s3.download_fileobj(os.environ[&amp;#39;SOURCE_BUCKET&amp;#39;], &#xA;        &amp;#39;PracticalPythonProjects.pdf&amp;#39;, original_pdf)&#xA;    original_pdf.seek(0)&#xA;&#xA;    input_pdf = PdfReader(original_pdf)&#xA;    watermark_pdf = PageMerge().add(PdfReader(packet).pages[0])[0]&#xA;&#xA;    for page in input_pdf.pages[6:]:&#xA;        PageMerge(page).add(watermark_pdf).render()&#xA;&#xA;    PdfWriter(final_pdf, trailer=input_pdf).write()&#xA;    final_pdf.seek(0)&#xA;&#xA;    s3_resource = boto3.resource(&amp;#34;s3&amp;#34;)&#xA;    obj = s3_resource.Object(&#xA;        bucket_name=os.environ[&amp;#34;BUCKET&amp;#34;],&#xA;        key=client_ref,&#xA;    )&#xA;    obj.put(Body=final_pdf, ContentType=&amp;#39;application/pdf&amp;#39;)&#xA;&#xA;    pdf_link, epub_link, mobi_link, kpf_link = generate_links(client_ref, s3_client=s3)&#xA;&#xA;    email_info = {&#xA;        &amp;#34;name&amp;#34;: name,&#xA;        &amp;#34;email&amp;#34;: email,&#xA;        &amp;#34;order_no&amp;#34;: order_no,&#xA;        &amp;#34;pdf_link&amp;#34;: pdf_link,&#xA;        &amp;#34;epub_link&amp;#34;: epub_link,&#xA;        &amp;#34;mobi_link&amp;#34;: mobi_link,&#xA;        &amp;#34;kpf_link&amp;#34;: kpf_link,&#xA;    }&#xA;    &#xA;    # Send email&#xA;    ses_client = boto3.client(&amp;#39;ses&amp;#39;, region_name=region)&#xA;    response = send_email(**email_info, ses_client=ses_client)&#xA;    print(f&amp;#34;SES response: {response}&amp;#34;)&#xA;    return&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I create a stamped PDF and upload it to S3 with the name stored in &lt;code&gt;client_ref&lt;/code&gt; variable. I call a &lt;code&gt;generate_links&lt;/code&gt; function that uses the &lt;code&gt;client_ref&lt;/code&gt; and an s3 client to generate PDF, EPUB, MOBI, and KPF links. And finally, I send an email using a &lt;code&gt;send_mail&lt;/code&gt; function. The current handler code generates &lt;code&gt;client_ref&lt;/code&gt; slightly differently. I talk about it in the Renaming S3 bucket data section.&lt;/p&gt;&#xA;&lt;h3 id=&#34;generating-s3-links&#34;&gt;Generating S3 links&lt;/h3&gt;&#xA;&lt;p&gt;The &lt;code&gt;generate_links&lt;/code&gt; function looks like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;def generate_links(client_ref, s3_client):&#xA;    expiration_time = 604800&#xA;    pdf_link = s3_client.generate_presigned_url(&amp;#39;get_object&amp;#39;,&#xA;        Params={&amp;#39;Bucket&amp;#39;: os.environ[&amp;#34;BUCKET&amp;#34;],&#xA;                &amp;#39;Key&amp;#39;: client_ref},&#xA;        ExpiresIn=expiration_time)&#xA;&#xA;    epub_link = s3_client.generate_presigned_url(&amp;#39;get_object&amp;#39;,&#xA;        Params={&amp;#39;Bucket&amp;#39;: os.environ[&amp;#34;SOURCE_BUCKET&amp;#34;],&#xA;                &amp;#39;Key&amp;#39;: &amp;#34;PracticalPythonProjects.epub&amp;#34;},&#xA;        ExpiresIn=expiration_time)&#xA;    &#xA;    mobi_link = s3_client.generate_presigned_url(&amp;#39;get_object&amp;#39;,&#xA;        Params={&amp;#39;Bucket&amp;#39;: os.environ[&amp;#34;SOURCE_BUCKET&amp;#34;],&#xA;                &amp;#39;Key&amp;#39;: &amp;#34;PracticalPythonProjects.mobi&amp;#34;},&#xA;        ExpiresIn=expiration_time)&#xA;&#xA;    kpf_link = s3_client.generate_presigned_url(&amp;#39;get_object&amp;#39;,&#xA;        Params={&amp;#39;Bucket&amp;#39;: os.environ[&amp;#34;SOURCE_BUCKET&amp;#34;],&#xA;                &amp;#39;Key&amp;#39;: &amp;#34;PracticalPythonProjects.kpf&amp;#34;},&#xA;        ExpiresIn=expiration_time)&#xA;&#xA;    return pdf_link, epub_link, mobi_link, kpf_link&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This function creates 4 links. The PDF link is generated from the file that was just recently stamped and uploaded to S3 and the other links are generated from the source files bucket. The latter isn&amp;rsquo;t stamped so we can simply make use of the files from the source bucket rather than regenerating them for each customer.&lt;/p&gt;&#xA;&lt;p&gt;I am setting the expiration date for these pre-signed URLs to the maximum value allowed by S3 which is 604800s. These equal 7 days or a week. (the resulting links were still expiring in a couple of hours. I discuss this in the &lt;a href=&#34;https://yasoob.me/posts/serverless-ebook-stamping-delivery-ses-sqs-aws/#expiring-links&#34;&gt;Expiring links&lt;/a&gt; section)&lt;/p&gt;&#xA;&lt;p&gt;I also had to make sure that the S3 client object was created with these parameters:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;from botocore.client import Config&#xA;import boto3&#xA;&#xA;# ...&#xA;&#xA;region = &amp;#34;us-west-1&amp;#34;&#xA;s3 = boto3.client(&amp;#39;s3&amp;#39;,&#xA;    region_name=region,&#xA;    endpoint_url=f&amp;#39;https://s3.{region}.amazonaws.com&amp;#39;,&#xA;    config=Config(signature_version=&amp;#39;s3v4&amp;#39;, s3={&amp;#39;addressing_style&amp;#39;: &amp;#39;virtual&amp;#39;})&#xA;)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This was necessary for me to make my pre-signed URLs work. I also had to move my bucket from &lt;code&gt;us-east-2&lt;/code&gt; to &lt;code&gt;us-west-1&lt;/code&gt; as the former region was causing some weird errors while accessing the pre-signed URLs.&lt;/p&gt;&#xA;&lt;p&gt;I will cover the &lt;code&gt;send_email&lt;/code&gt; function in the next section.&lt;/p&gt;&#xA;&lt;h2 id=&#34;getting-ses-up-and-running&#34;&gt;Getting SES up and running&lt;/h2&gt;&#xA;&lt;p&gt;SES is fairly straightforward. You go to &lt;a href=&#34;https://us-west-1.console.aws.amazon.com/ses/home?region=us-west-1#verified-senders-domain:&#34;&gt;AWS SES console&lt;/a&gt; (assuming you already have an AWS account) and verify a new Domain. This is required to send emails via SES. You enter the domain information and SES generates some TXT and CNAME records for you. You go and put them on your website via the DNS management interface of whichever host you are using.&lt;/p&gt;&#xA;&lt;p&gt;This is what the SES console looks like when you have a verified domain.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/serverless/SES-verified-domain.png&#34; alt=&#34;SES Verified domain&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;After you get a domain verified, the initial SES sending quota is fairly limited and your application is still in sandbox. This means that you can only send emails to people on the same domain as the one you verified or the people whose email had been verified via the &amp;ldquo;Email Addresses tab&amp;rdquo; under &amp;ldquo;Identity Management&amp;rdquo;. In order to increase your sending quota and permission to send to people outside of verified domains, you need to submit a request.&lt;/p&gt;&#xA;&lt;p&gt;You need to go to the &amp;ldquo;Sending Statistics&amp;rdquo; tab, click on &amp;ldquo;Edit your account details&amp;rdquo; and enter information regarding how you will be using SES in production. AWS people will review your application and approve your request within a day and increase the number of emails you can send within a second and within a day.&lt;/p&gt;&#xA;&lt;p&gt;The domain verification takes anywhere from a couple of mins to a few hours and the DKIM status change usually takes longer than the normal verification. In my case, both were done within a few hours. As for the production request application, mine got approved in around a day.&lt;/p&gt;&#xA;&lt;p&gt;Once I had SES all set up, I could get the &lt;code&gt;boto3&lt;/code&gt; library and play with it. The code I use for sending an email looks like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;def send_email(name, email, pdf_link, epub_link, &#xA;            mobi_link, kpf_link, order_no, ses_client):&#xA;    final_body = (f&amp;#34;Hi {name}!&amp;#34;&#xA;                    &amp;#34;Thank you so much for ordering my book. I am really excited &amp;#34;&#xA;                    # ...&#xA;                    f&amp;#34;- PDF: {pdf_link}\r\n&amp;#34;&#xA;                    f&amp;#34;- EPUB: {epub_link}\r\n&amp;#34;&#xA;                    f&amp;#34;- MOBI: {mobi_link}\r\n&amp;#34;&#xA;                    f&amp;#34;- KPF: {kpf_link}\r\n\n&amp;#34;&#xA;                    # ...&#xA;                    &amp;#34;Take care,\r\n&amp;#34;&#xA;                    &amp;#34;Yasoob&amp;#34;)&#xA;    SENDER = &amp;#34;Yasoob Khalid &amp;lt;hi@yasoob.me&amp;gt;&amp;#34;&#xA;    CHARSET = &amp;#34;UTF-8&amp;#34;&#xA;    SUBJECT = f&amp;#34;Your copy of Practical Python Projects 🚀 | Order {order_no}&amp;#34;&#xA;    email_info = {&#xA;        &amp;#34;name&amp;#34;: name,&#xA;        &amp;#34;email&amp;#34;: email,&#xA;        &amp;#34;order_no&amp;#34;: order_no,&#xA;        &amp;#34;pdf_link&amp;#34;: pdf_link,&#xA;        &amp;#34;epub_link&amp;#34;: epub_link,&#xA;        &amp;#34;mobi_link&amp;#34;: mobi_link,&#xA;        &amp;#34;kpf_link&amp;#34;: kpf_link,&#xA;    }&#xA;    response = ses_client.send_email(&#xA;        Destination={&#xA;            &amp;#39;ToAddresses&amp;#39;: [&#xA;                email,&#xA;            ],&#xA;        },&#xA;        Message={&#xA;            &amp;#39;Body&amp;#39;: {&#xA;                &amp;#39;Html&amp;#39;: {&#xA;                    &amp;#39;Charset&amp;#39;: CHARSET,&#xA;                    &amp;#39;Data&amp;#39;: email_head + email_body.format(**email_info),&#xA;                },&#xA;                &amp;#39;Text&amp;#39;: {&#xA;                    &amp;#39;Charset&amp;#39;: CHARSET,&#xA;                    &amp;#39;Data&amp;#39;: final_body,&#xA;                },&#xA;            },&#xA;            &amp;#39;Subject&amp;#39;: {&#xA;                &amp;#39;Charset&amp;#39;: CHARSET,&#xA;                &amp;#39;Data&amp;#39;: SUBJECT,&#xA;            },&#xA;        },&#xA;        Source=SENDER,&#xA;        ReplyToAddresses=[&#xA;            &amp;#39;hi@yasoob.me&amp;#39;,&#xA;        ],&#xA;    )&#xA;    return response&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;email_head&lt;/code&gt; and &lt;code&gt;email_body&lt;/code&gt; are just two multiline strings containing the HTML email. The &lt;code&gt;email_body&lt;/code&gt; contains a couple of placeholders that I fill in using the &lt;code&gt;email_info&lt;/code&gt; dict.&lt;/p&gt;&#xA;&lt;p&gt;I call this function like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;import boto3&#xA;&#xA;email_info = {&#xA;  &amp;#34;name&amp;#34;: name,&#xA;  &amp;#34;email&amp;#34;: email,&#xA;  &amp;#34;order_no&amp;#34;: order_no,&#xA;  &amp;#34;pdf_link&amp;#34;: pdf_link,&#xA;  &amp;#34;epub_link&amp;#34;: epub_link,&#xA;  &amp;#34;mobi_link&amp;#34;: mobi_link,&#xA;  &amp;#34;kpf_link&amp;#34;: kpf_link,&#xA;}&#xA;&#xA;ses_client = boto3.client(&amp;#39;ses&amp;#39;, region_name=&amp;#39;us-west-1&amp;#39;)&#xA;response = send_email(**email_info, ses_client=ses_client)&#xA;print(f&amp;#34;SES response: {response}&amp;#34;)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The resulting email looks like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/serverless/order-link-email.png&#34; alt=&#34;Order Link Email&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;This is all that you need to send a custom email using SES and this is how I integrated SES with the &lt;code&gt;process&lt;/code&gt; function.&lt;/p&gt;&#xA;&lt;h2 id=&#34;custom-domain&#34;&gt;Custom domain&lt;/h2&gt;&#xA;&lt;p&gt;Now that I had all the parts up and running, I had to figure out how to deploy the service on a custom domain. All the original serverless documentation pointed to either registering a new domain with AWS Route 53 or transfer the DNS of an existing domain to Route 53. I didn&amp;rsquo;t want to do either as Route 53 is expensive for a new domain (+ I already owned 1 that I wanted to use) and I had already custom-configured a ton of CNAME and TXT records for my old domain with my other domain registrar (Namecheap) that I was in no mood to copy over.&lt;/p&gt;&#xA;&lt;p&gt;The solution was simpler than I thought. I followed the &lt;a href=&#34;https://www.serverless.com/blog/serverless-api-gateway-domain&#34;&gt;main serverless tutorial&lt;/a&gt; with a few changes. Here are the steps I followed:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Go to the &lt;a href=&#34;https://us-west-1.console.aws.amazon.com/acm/home?region=us-west-1#/&#34;&gt;AWS Certificate Manager&lt;/a&gt; and request a certificate for a pre-existing domain&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/serverless/AWS-certificate-manager.png&#34; alt=&#34;Certificate manager&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;ol start=&#34;2&#34;&gt;&#xA;&lt;li&gt;Install the serverless domain manager using NPM &lt;code&gt;$ npm install serverless-domain-manager --save-dev&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;Edit the &lt;code&gt;serverless.yml&lt;/code&gt; file to add the domain manager plugin and define my domain&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;plugins:&#xA;  - serverless-python-requirements&#xA;  - serverless-domain-manager&#xA;&#xA;custom:&#xA;    # ...&#xA;  customDomain:&#xA;    domainName: ____.yasoob.me&#xA;    certificateName: &amp;#34;*.yasoob.me&amp;#34;&#xA;    basePath: &amp;#39;&amp;#39;&#xA;    stage: ${self:provider.stage}&#xA;    endpointType: &amp;#39;regional&amp;#39;&#xA;    createRoute53Record: false&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;(Replace the &lt;code&gt;_____&lt;/code&gt; with the actual subdomain that will be pointing to this service)&lt;/p&gt;&#xA;&lt;ol start=&#34;4&#34;&gt;&#xA;&lt;li&gt;Run the domain manager plugin &lt;code&gt;sls create_domain&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;Deploy &lt;code&gt;sls deploy&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The deployment will show output similar to this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Serverless Domain Manager Summary&#xA;Domain Name&#xA;  api.example.com&#xA;Distribution Domain Name&#xA;  a19cneopjuq1t1.cloudfront.net&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&#34;6&#34;&gt;&#xA;&lt;li&gt;Set up a CNAME record in the DNS from the custom subdomain to the CloudFront URL the deploy command outputted.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://csdcorp.com/blog/coding/custom-domains-for-aws-api-gateway-without-route-53/&#34;&gt;This blog&lt;/a&gt; by Stephen Owens was super helpful.&lt;/p&gt;&#xA;&lt;h2 id=&#34;fun-post-launch-issues&#34;&gt;Fun post-launch issues&lt;/h2&gt;&#xA;&lt;p&gt;I have already shared quite a few issues in this article but let me describe a couple more.&lt;/p&gt;&#xA;&lt;h3 id=&#34;expiring-links&#34;&gt;Expiring links&lt;/h3&gt;&#xA;&lt;p&gt;After releasing the book, I got an email from a customer that the links I emailed them were already expired after a day as compared to a week (this is what I had told them). Turns out they were right. The pre-signed URL did contain the &lt;code&gt;X-Amz-Expires=604800&lt;/code&gt; parameter but for some reason, Amazon was not respecting it. 604800 is in seconds and that equals a week. It took some searching around to find out that the AWS role that was generating these pre-signed URLs was tied to the Lambda function identity. It is impossible to generate pre-signed URLs that take more than a couple of hours to expire by using this identity.&lt;/p&gt;&#xA;&lt;p&gt;If you are a long-time AWS/Lambda user, you might have already known this but I am a new user and this &amp;ldquo;feature&amp;rdquo; isn&amp;rsquo;t well documented anywhere. I had to come up with a solution to this problem. I couldn&amp;rsquo;t just manually generate the URLs each time a customer wants to download their copy. Either the URLs shouldn&amp;rsquo;t expire or there should be a self-service system where the customers can generate the URLs on demand. I decided to go with the latter solution.&lt;/p&gt;&#xA;&lt;p&gt;I set up a new Lambda function whose job was to only generate pre-signed URLs for pre-existing resources and send an email to the customer. The code is fairly similar to the handler code I showed in one of the previous sections.&lt;/p&gt;&#xA;&lt;p&gt;This is what the public page for this looks like:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/serverless/download-links.png&#34; alt=&#34;Download Links Page&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;!-- Lambda dynamic URL generation code --&gt;&#xA;&lt;h3 id=&#34;cors-issue&#34;&gt;CORS issue&lt;/h3&gt;&#xA;&lt;p&gt;&lt;code&gt;Access to XMLHttpRequest at &#39;&amp;lt;Lambda Endpoint&amp;gt;&#39; from origin &#39;https://practicalpython.yasoob.me&#39; has been blocked by CROS policy: No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource.&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;If you are seeing this error for the first time, it is tough to wrap your head around the root cause. &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS&#34;&gt;Mozilla&lt;/a&gt; does a good job at explaining it. For the new API endpoint for generating pre-signed URLs on demand, I had a similar issue and had to set up CORS.&lt;/p&gt;&#xA;&lt;p&gt;This is required if you are serving your API from a different domain and your front-end is at a different domain. It is easy to fix this issue. I had to modify my &lt;code&gt;serverless.yml&lt;/code&gt; file like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;events:&#xA;    - http:&#xA;        path: /&#xA;        method: post&#xA;        cors: true&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice the &lt;code&gt;cors: true&lt;/code&gt; statement in the event trigger definition. I also had to make sure that when I was returning the response from my handler, I added the appropriate headers as well:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;return {&#xA;            &amp;#34;statusCode&amp;#34;: 200,&#xA;            &amp;#39;headers&amp;#39;: {&#xA;                &amp;#39;Content-Type&amp;#39;: &amp;#39;application/json&amp;#39;,&#xA;                &amp;#39;Access-Control-Allow-Origin&amp;#39;: &amp;#39;*&amp;#39;,&#xA;                &amp;#39;Access-Control-Allow-Credentials&amp;#39;: True&#xA;            },&#xA;            &amp;#34;body&amp;#34;: json.dumps(message)&#xA;        }&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It is also important to note that if your handler function&amp;rsquo;s return value doesn&amp;rsquo;t include &lt;code&gt;statusCode&lt;/code&gt;, you will see weird return responses that are hard to debug. I am an avid Flask user so I was simply returning from the function like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;return message, 200&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It took me a while to realize that lambda doesn&amp;rsquo;t work the same way as Flask. The API gateway was unable to understand my response and so instead of returning a 200 status, it was returning some 5xx error. I wasn&amp;rsquo;t able to track this error using CloudWatch either. Thankfully that is all in the past now.&lt;/p&gt;&#xA;&lt;h3 id=&#34;rename-s3-bucket-data&#34;&gt;Rename S3 bucket data&lt;/h3&gt;&#xA;&lt;p&gt;During the initial launch, I was saving the generated PDF files in S3 with the following naming convention:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Name_Email_OrderNo&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This worked out well initially but later on, I found that the report that Paddle generates doesn&amp;rsquo;t include the user&amp;rsquo;s name. I wanted a naming convention where I can easily cross-reference a file against the Paddle report. The main reason for using this naming convention was to make sure that files were unique. I realized that even if I drop the &lt;code&gt;name&lt;/code&gt;, the files would still be unique. I modified my new pre-signed URL generation endpoint in such a way that if a file with the key &lt;code&gt;Email_OrderNo&lt;/code&gt; didn&amp;rsquo;t exist, it would copy the &lt;code&gt;Name_Email_OrderNo&lt;/code&gt; to &lt;code&gt;Email_OrderNo&lt;/code&gt;, delete the old file, and generate pre-signed URLs for this new file (&lt;code&gt;Email_OrderNo&lt;/code&gt;). The reason for doing a copy instead of a rename is that S3 doesn&amp;rsquo;t support renaming so you have to create a copy with a new name and then delete the old file.&lt;/p&gt;&#xA;&lt;p&gt;It seemed pretty straightforward. The &lt;code&gt;boto3&lt;/code&gt; method calls for copying and deleting the file roughly look like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;old_client_ref = &amp;#34;Name_Email_OrderNo&amp;#34;&#xA;client_ref = &amp;#34;Email_OrderNo&amp;#34;&#xA;BUCKET = &amp;#34;customer-files&amp;#34;&#xA;s3_resource.Object(BUCKET, client_ref).copy_from(&#xA;    CopySource=&amp;#34;/&amp;#34;.join([BUCKET, old_client_ref])&#xA;)&#xA;s3_resource.Object(BUCKET,old_client_ref).delete()&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The IAM role policy in &lt;code&gt;serverless.yml&lt;/code&gt; looked like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;- Effect: &amp;#34;Allow&amp;#34;&#xA;    Action:&#xA;    - &amp;#34;s3:PutObject&amp;#34;&#xA;    - &amp;#34;s3:ListBucket&amp;#34;&#xA;    - &amp;#34;s3:GetObject&amp;#34;&#xA;    - &amp;#34;s3:GetObjectAcl&amp;#34;&#xA;    - &amp;#34;s3:DeleteObject&amp;#34;&#xA;    Resource: &amp;#34;arn:aws:s3:::customer-files/*&amp;#34;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I tested the boto3 code locally and deployed the code. To my surprise, the code failed in production. The logs showed this error:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the CopyObject operation: Access Denied&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;I was a bit confused. The S3 policy code looked perfectly fine. I turned to Google and even Google wasn&amp;rsquo;t able to help me. Turns out, I had to add the following permissions to the IAM role as well:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;- Effect: &amp;#34;Allow&amp;#34;&#xA;    Action:&#xA;    - &amp;#34;s3:ListBucket&amp;#34;&#xA;    - &amp;#34;s3:GetObject&amp;#34;&#xA;    - &amp;#34;s3:GetObjectAcl&amp;#34;&#xA;    Resource: &amp;#34;arn:aws:s3:::*/*&amp;#34;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I am not sure why S3 requires these extra permissions for copying files as the boto3 code shouldn&amp;rsquo;t be interfacing with any other S3 bucket. I will write a separate post on how I debugged this policy issue as it took me quite a while.&lt;/p&gt;&#xA;&lt;h2 id=&#34;serverless-monitoring&#34;&gt;Serverless monitoring&lt;/h2&gt;&#xA;&lt;p&gt;The best part about using serverless is that you can sign up for a free &lt;a href=&#34;https://app.serverless.com/&#34;&gt;serverless.com&lt;/a&gt; account. The serverless command will prompt you to sign up when you initially start a brand new serverless project. This dashboard allows you to monitor your serverless functions easily and for free. This has been really helpful during my initial and ongoing deployments. This is the main dashboard that I keep an eye on to make sure my functions aren&amp;rsquo;t failing for any reason.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/serverless/serverless-monitoring.png&#34; alt=&#34;Serverless dashboard&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;h2 id=&#34;things-to-watch-out-for&#34;&gt;Things to watch out for&lt;/h2&gt;&#xA;&lt;p&gt;Here are a couple of things that might be good to keep in mind:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Lambda:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Time limit for public API endpoints is 30s&lt;/li&gt;&#xA;&lt;li&gt;Does a cold start if a function is rarely used but not really an issue as the cold start is super quick&lt;/li&gt;&#xA;&lt;li&gt;Might get expensive if service is used super frequently&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;S3&#xA;&lt;ul&gt;&#xA;&lt;li&gt;pre-signed URLs have a max expiry of 1 week&lt;/li&gt;&#xA;&lt;li&gt;You can enable file retention config to delete files after 30 days to prevent extra cost&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;SES&#xA;&lt;ul&gt;&#xA;&lt;li&gt;You need to verify the domain in each zone you want to send email from e.g &lt;code&gt;us-west-1&lt;/code&gt; vs &lt;code&gt;us-east-2&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;PDF processing&#xA;&lt;ul&gt;&#xA;&lt;li&gt;PyPDF2 is slow and not maintained anymore&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;pdfrw&lt;/code&gt; is pure Python but not as full-featured&lt;/li&gt;&#xA;&lt;li&gt;PDF spec doesn&amp;rsquo;t change frequently so libraries don&amp;rsquo;t need to be updated super often&lt;/li&gt;&#xA;&lt;li&gt;Test different PDF processing libraries and use whichever one suits your use case as there is no one size fits all&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;Paddle&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Takes a big chunk from the sale but there aren&amp;rsquo;t too many viable options for a major group of people&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2 id=&#34;next-steps&#34;&gt;Next Steps&lt;/h2&gt;&#xA;&lt;p&gt;I plan on fleshing out this service to add a couple more features. Maybe turn it into a full-fledged service like &lt;a href=&#34;https://sendowl.com/&#34;&gt;SendOwl&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I was always skeptical of self-hosted email newsletter services like &lt;a href=&#34;https://sendy.co&#34;&gt;Sendy&lt;/a&gt; as I had heard too many horror stories around deliverability issues but this experience and another tangential experience with SES has made me more confident that Sendy is the way to go. I am currently using Mailchimp and that costs me $78 for the base package for 5000+ subscribers. Sendy can bring that down to around $0-5 after initial payment for the software. I also don&amp;rsquo;t send enough emails to justify the $78 price tag.&lt;/p&gt;&#xA;&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;I was able to test and launch this service within 3 days. I started developing it on Monday and it was in production on Thursday. I did this all without any prior experience with serverless.com or PDF stamping. Focus played a huge role in this and forcing myself to keep my eye on the target at all times helped me do this. Were there a couple of issues post-launch? Sure. Were they big enough to prevent the launch? Heck no.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://media.giphy.com/media/4xpB3eE00FfBm/giphy.gif&#34; alt=&#34;Success&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;So what was the most tiring+critical bug? The time when a customer reached out and informed me about the bookmarks not working. That was a completely unforeseen issue and the more I searched for how to fix the problem using &lt;code&gt;PyPDF2&lt;/code&gt;, the more frustrated I became. Finding a super quick solution using &lt;code&gt;pdfrw&lt;/code&gt; is a reminder that sometimes the library you are using might not be the best for the job and it is always okay to look around a little bit.&lt;/p&gt;&#xA;&lt;p&gt;Another important learning from this exercise is that customers are sympathetic if you keep them updated about an issue. I sent an email to all the customers after the link expiry and the PDF stamping issue and got a few encouraging responses. There is a reason people say: &amp;ldquo;just ship it!&amp;rdquo;. You can always fix the lingering bugs with time if they aren&amp;rsquo;t too serious 🤞&lt;/p&gt;&#xA;&lt;p&gt;I hope you learned something new from this article. If you have any questions, comments, or concerns, please write a comment below or send me an email. I love hearing from you all! ❤️&lt;/p&gt;&#xA;&lt;h2 id=&#34;useful-links&#34;&gt;Useful links&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://github.com/pmaupin/pdfrw&#34;&gt;pdfrw&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://github.com/mstamy2/PyPDF2&#34;&gt;PyPDF2&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://serverless.com/&#34;&gt;Serverless&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://paddle.com/&#34;&gt;Paddle&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://webhook.site/&#34;&gt;Webhook testing&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://csdcorp.com/blog/coding/custom-domains-for-aws-api-gateway-without-route-53/&#34;&gt;Custom Domains for AWS API Gateway Without Route 53&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>How to Prerender a React App for SEO with Prerender.io</title>
				<link>https://yasoob.me/posts/how-to-prerender-react-apps-using-prerender-io-seo/</link>
				<pubDate>Fri, 08 Jan 2021 01:29:50 +0500</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/how-to-prerender-react-apps-using-prerender-io-seo/</guid>
				<category>Python</category>
				<category>React</category>
				<category>NGINX</category>
				<category>prerender</category>
				<description>Self-host the open-source prerender.io service and serve prerendered pages to Googlebot and other crawlers via NGINX to fix SEO for a React SPA.</description>
				<content:encoded>&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/prerender/header.png&#34; alt=&#34;How to Prerender a React App for SEO with Prerender.io&#34;&gt;&lt;/p&gt;&lt;p&gt;Hi everyone! &amp;#x1f44b; I have been working on a sports analytics startup and the whole front-end is made using React. I haven&amp;rsquo;t had to work on such a big React project before this and so it brought along some unique challenges. In the past, SEO hasn&amp;rsquo;t been a big issue for the web projects I have worked on. I could always just add relevant data to the meta tags, define the navigation using semantic HTML tags and Google would show the website correctly on its result pages. However, this time, the whole website was being generated using client-side Javascript. On initial load, there is close to nothing on the web page and the navigation becomes available only when JavaScript is executed.&lt;/p&gt;&#xA;&lt;p&gt;Even though Google crawler can execute Javascript, it is a better SEO practice to serve it a rendered application instead of relying on it to render the application on its own. Moreover, if the rendering takes longer than some set time, the crawler would simply move on. In this article, I will show you how to get the prerender service up and running on your server and serve it via NGINX to different bots and boost your SEO.&lt;/p&gt;&#xA;&lt;h2 id=&#34;looking-for-a-solution&#34;&gt;Looking for a solution&lt;/h2&gt;&#xA;&lt;p&gt;I searched around and found multiple solutions to this problem. &lt;a href=&#34;https://medium.com/superhighfives/an-almost-static-stack-6df0a2791319&#34;&gt;Certain node scripts&lt;/a&gt; could be run as a post-processing step and they would output a rendered React app. I tried using them but none worked flawlessly without requiring me to tweak the app code significantly. It is easier to incorporate such tools at the start of a project. Adding them later just leads to a lot of pain. I was looking for a plug-and-play solution so I kept looking.&lt;/p&gt;&#xA;&lt;p&gt;I soon came across &lt;a href=&#34;https://prerender.io/&#34;&gt;prerender&lt;/a&gt;. This service acts as a middleware between your application and the end-user. It uses Headless Chrome to render HTML. If the end-user is a human, the server will return HTML + JS and the React code will be rendered on the client-side. However, if the end-user is a bot then the server will send the HTML + JS to the prerender service and return the rendered static HTML page to the bot. There are multiple similar services. I could have just as easily used &lt;a href=&#34;https://github.com/GoogleChrome/rendertron&#34;&gt;renderton&lt;/a&gt; but prerender just seemed more popular so I went ahead with that.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; It goes without saying that this might not be the most efficient solution but it works for my use case. Your mileage may vary so try at your own risk &amp;#x1f604;&lt;/p&gt;&#xA;&lt;p&gt;This is how a typical flow with the prerender service looks like:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/prerender/prerender-flow.png&#34; alt=&#34;prerender-flow&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;The prerender service will cache the static HTML for a while before requesting a new copy from the server. This method did not require me to change anything on my React app and only required me to make some adjustments to the NGINX server configuration.&lt;/p&gt;&#xA;&lt;p&gt;This is how my application was being served before prerender came into the mix:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/flask-react-login/server-arch.png&#34; alt=&#34;server-arch&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;After adding prerender, the flow looked something like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://yasoob.me/images/prerender/final-flow.png&#34; alt=&#34;final-flow&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34;&gt;&#xA;&lt;/p&gt;&#xA;&lt;h2 id=&#34;setting-up-prerender-service&#34;&gt;Setting up prerender service&lt;/h2&gt;&#xA;&lt;p&gt;There are two ways you can make use of the prerender service. You can either make use of the &lt;a href=&#34;https://prerender.io/&#34;&gt;paid hosted service&lt;/a&gt; (contains a free plan as well) or you can run the &lt;a href=&#34;https://github.com/prerender/prerender&#34;&gt;open source service&lt;/a&gt; on your server and interface with that. I decided to opt for the latter. The first step was to install prerender on the server. It was fairly straightforward to do so using npm:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ npm install prerender&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The next step was to create a new node script that ran the service. These 3 lines are enough to get the service up and running:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;const prerender = require(&amp;#39;prerender&amp;#39;);&#xA;const server = prerender();&#xA;server.start();&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Save this code to a &lt;code&gt;server.js&lt;/code&gt; file and run it using node:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ node server.js&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;At this point you can go ahead and test whether the prerender service is working correctly or not by opening &lt;a href=&#34;http://localhost:3000/render/?url=https://google.com/&#34;&gt;http://localhost:3000/render/?url=https://google.com/&lt;/a&gt;. This should display the Google homepage. If the images don&amp;rsquo;t show up correctly, don&amp;rsquo;t worry. The issue will be fixed when we serve the prerender service via NGINX.&lt;/p&gt;&#xA;&lt;h2 id=&#34;run-prerender-on-system-start&#34;&gt;Run prerender on system start&lt;/h2&gt;&#xA;&lt;p&gt;The next step is to run prerender on system start and make sure it keeps running in case of crash or system restart. We will make this happen by creating a systemd service file. I am assuming that you saved the &lt;code&gt;server.js&lt;/code&gt; file in your home folder. My home folder is &lt;code&gt;yasoob&lt;/code&gt; but yours might be different so make sure you edit the &lt;code&gt;WorkingDirectory&lt;/code&gt; path. Create a &lt;code&gt;prerender.service&lt;/code&gt; file in &lt;code&gt;/etc/systemd/system&lt;/code&gt; folder with the following contents:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[Unit]&#xA;Description=Prerender server for bot crawling&#xA;After=network.target&#xA;&#xA;[Service]&#xA;User=yasoob&#xA;WorkingDirectory=/home/yasoob/&#xA;ExecStart=/usr/bin/node server.js&#xA;Restart=always&#xA;&#xA;[Install]&#xA;WantedBy=multi-user.target&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In this file, we are telling &lt;code&gt;systemd&lt;/code&gt; to start &lt;code&gt;server.js&lt;/code&gt; when the network is up and running. The service would launch under the user &lt;code&gt;yasoob&lt;/code&gt; and the command it needs to run is &lt;code&gt;/usr/bin/node server.js&lt;/code&gt;. The script would also automatically restart in case of a crash or system restart.&lt;/p&gt;&#xA;&lt;p&gt;After saving this file, let&amp;rsquo;s make sure &lt;code&gt;systemd&lt;/code&gt; can recognize it:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ sudo service prerender status&#xA;&#xA;● prerender.service - Prerender server for bot crawling&#xA;     Loaded: loaded (/etc/systemd/system/prerender.service; disabled; vendor preset: enabled)&#xA;     Active: inactive (dead)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Perfect! Now let&amp;rsquo;s start the service and then check the status:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ sudo service prerender start&#xA;$ sudo service prerender status&#xA;&#xA;● prerender.service - Prerender server for bot crawling&#xA;     Loaded: loaded (/etc/systemd/system/prerender.service; disabled; vendor preset: enabled)&#xA;     Active: active (running) since Thu 2021-01-07 19:59:46 UTC; 2s ago&#xA;   Main PID: 589168 (node)&#xA;      Tasks: 7 (limit: 1137)&#xA;     Memory: 41.8M&#xA;     CGroup: /system.slice/prerender.service&#xA;             └─589168 /usr/bin/node server.js&#xA;&#xA;Jan 07 19:59:46 systemd[1]: Started Prerender server for bot crawling.&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;integrating-prerender-with-nginx&#34;&gt;Integrating prerender with NGINX&lt;/h2&gt;&#xA;&lt;p&gt;Now that our prerender service is running, we can go ahead and integrate it with NGINX. What we want to do is that the normal user should be sent the normal HTML + JS response but a bot should be sent a response by the prerender service.&lt;/p&gt;&#xA;&lt;p&gt;The original NGINX configuration file for my React app looked like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;server {&#xA;    server_name example.com;&#xA;    root /home/yasoob/example/build;&#xA;    index index.html;&#xA;&#xA;    location / {&#xA;  &#x9;    try_files $uri /index.html;&#xA;        add_header Cache-Control &amp;#34;no-cache&amp;#34;;&#xA;    }&#xA;&#xA;    location /static {&#xA;        expires 1y;&#xA;        add_header Cache-Control &amp;#34;public&amp;#34;;&#xA;    }&#xA;&#xA;    location /api {&#xA;        include proxy_params;&#xA;        proxy_pass http://localhost:5000;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is a fairly generic configuration file. We add some cache headers to certain path responses and pass the &lt;code&gt;/api&lt;/code&gt; route traffic to the gunicorn server running on port 5000. Now we just need to make sure that all requests made by a bot are responded to by the prerender service that is running on port 3000. The template file for these changes is &lt;a href=&#34;https://gist.github.com/thoop/8165802&#34;&gt;conveniently provided&lt;/a&gt; by the prerender folks. I took the same file and tweaked it a bit to make it work for my setup. The major thing I changed in the template was to edit the prerender service URL and remove the proxy header part. As I am using a self-hosted service, I replaced &lt;code&gt;service.prerender.io&lt;/code&gt; with &lt;code&gt;127.0.0.1:3000&lt;/code&gt; and because this is our service, we don&amp;rsquo;t need to pass any authentication headers.&lt;/p&gt;&#xA;&lt;p&gt;The resulting NGINX configuration file looks like this:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;server {&#xA;    server_name shotquality.com;&#xA;    root /home/yasoob/shotqenterprise/REACT/build;&#xA;    index index.html;&#xA;&#xA;    location / {&#xA;  &#x9;    try_files $uri @prerender;&#xA;        add_header Cache-Control &amp;#34;no-cache&amp;#34;;&#xA;    }&#xA;&#xA;    location /static {&#xA;        expires 1y;&#xA;        add_header Cache-Control &amp;#34;public&amp;#34;;&#xA;    }&#xA;&#xA;    location /api {&#xA;        include proxy_params;&#xA;        proxy_pass http://localhost:5000;&#xA;    }&#xA;&#xA;    location @prerender {&#xA;        set $prerender 0;&#xA;        if ($http_user_agent ~* &amp;#34;googlebot|bingbot|yandex|baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp&amp;#34;) {&#xA;            set $prerender 1;&#xA;        }&#xA;        if ($args ~ &amp;#34;_escaped_fragment_&amp;#34;) {&#xA;            set $prerender 1;&#xA;        }&#xA;        if ($http_user_agent ~ &amp;#34;Prerender&amp;#34;) {&#xA;            set $prerender 0;&#xA;        }&#xA;        if ($uri ~* &amp;#34;\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg|eot)&amp;#34;) {&#xA;            set $prerender 0;&#xA;        }&#xA;&#xA;        if ($prerender = 1) {&#xA;            set $prerender &amp;#34;127.0.0.1:3000&amp;#34;;&#xA;            rewrite .* /$scheme://$host$request_uri? break;&#xA;            proxy_pass http://$prerender;&#xA;        }&#xA;        if ($prerender = 0) {&#xA;            rewrite .* /index.html break;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I removed the SSL support and redirection from this configuration file for the sake of simplicity.&lt;/p&gt;&#xA;&lt;h2 id=&#34;testing-nginx-configuration&#34;&gt;Testing NGINX configuration&lt;/h2&gt;&#xA;&lt;p&gt;In order to test whether our NGINX config changes did not break anything, we can run:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ sudo nginx -t&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If everything seems correct, we can restart NGINX:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ sudo service nginx restart&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To test whether our service is working the way it is supposed to, we can run the following CURL command:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ curl -A googlebot https://example.com&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Replace example.com with your React-based app URL and see if the output of this command is different from if you run &lt;code&gt;curl&lt;/code&gt; without &lt;code&gt;-A googlebot&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;If you have reached this step then chances are that your prerender service is working fine. In case there are errors, please write about them in the comments below and I will try to help.&lt;/p&gt;&#xA;&lt;p&gt;You all have a wonderful day and a fulfilling new year :)&lt;/p&gt;&#xA;&lt;h2 id=&#34;further-study&#34;&gt;Further study:&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files&#34;&gt;Understanding Systemd Units and Unit Files&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&#34;https://unix.stackexchange.com/questions/506347/why-do-most-systemd-examples-contain-wantedby-multi-user-target&#34;&gt;Why do most systemd examples contain WantedBy=multi-user.target?&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;</content:encoded>
			</item>
			<item>
				<title>Setting up &amp; Deploying JWT based auth using Flask &amp; React</title>
				<link>https://yasoob.me/posts/how-to-setup-and-deploy-jwt-auth-using-react-and-flask/</link>
				<pubDate>Wed, 14 Oct 2020 02:10:02 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/how-to-setup-and-deploy-jwt-auth-using-react-and-flask/</guid>
				<category>Python</category>
				<category>Flask</category>
				<description>I recently had to implement JWT based auth in a React and Flask based web app. In this post, I will show you how to implement login functionality step by step and deploy the resulting web app using NGINX and Gunicorn. We will be using flask-praetorian for JWT token generation.</description>
			</item>
			<item>
				<title>Using Python to Post Stories on Instagram</title>
				<link>https://yasoob.me/posts/using-python-to-post-stories-on-instagram/</link>
				<pubDate>Tue, 22 Sep 2020 00:24:49 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/using-python-to-post-stories-on-instagram/</guid>
				<category>programming</category>
				<category>python</category>
				<description>Have you ever wanted to post stories on Instagram in an automated fashion? In this article, I will show you how to use Python and the Instagram-API-python library to do exactly that. Fasten your seatbelts and let&amp;#39;s get started!</description>
			</item>
			<item>
				<title>How to Listen to Trunked Police Radio Using SDRTrunk</title>
				<link>https://yasoob.me/posts/listen-to-trunked-police-radio-sdrtrunk-rtl-sdr/</link>
				<pubDate>Sun, 30 Aug 2020 14:42:02 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/listen-to-trunked-police-radio-sdrtrunk-rtl-sdr/</guid>
				<category>radio</category>
				<description>Step-by-step guide to listening to trunked P25 and DMR police radio with a cheap RTL-SDR dongle and the free SDRTrunk software on Windows, Mac and Linux.</description>
			</item>
			<item>
				<title>Alpha Version of Practical Python Projects Book Released!</title>
				<link>https://yasoob.me/posts/practical-python-projects-book-released/</link>
				<pubDate>Wed, 19 Aug 2020 19:52:52 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/practical-python-projects-book-released/</guid>
				<category>book</category>
				<category>python</category>
				<category>practical-python</category>
				<description>I just released the alpha version of my much anticipated Practical Python Projects book! It has been two years in the making and I am super excited about its release. In 320+ pages we will implement 12 different projects. I wish I had access to a similar book when I started learning Python.</description>
			</item>
			<item>
				<title>How to Use a Baofeng Radio as a Police Scanner</title>
				<link>https://yasoob.me/posts/using-baofeng-ht-radio-as-police-scanner/</link>
				<pubDate>Mon, 17 Aug 2020 01:36:31 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/using-baofeng-ht-radio-as-police-scanner/</guid>
				<category>amateur-radio</category>
				<category>ham</category>
				<description>Can a Baofeng listen to police? Yes, if they still use analog radio. Find your local police and fire frequencies and program them into a Baofeng UV-5X3.</description>
			</item>
			<item>
				<title>Working With Messy Data Using Pandas in Python</title>
				<link>https://yasoob.me/posts/working-with-messy-data-using-pandas-python/</link>
				<pubDate>Sun, 16 Aug 2020 02:08:42 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/working-with-messy-data-using-pandas-python/</guid>
				<category>python</category>
				<category>pandas</category>
				<description>Have you ever had to process some messy data? I recently worked on a project where I had to tame some messy data using Pandas in Python. In this short tutorial, I will teach you some data wrangling basics that will help you process most datasets you will ever encounter in the wild.</description>
			</item>
			<item>
				<title>5 Lessons From my Microsoft Internship</title>
				<link>https://yasoob.me/posts/5-lessons-from-microsoft-internship/</link>
				<pubDate>Thu, 13 Aug 2020 14:03:01 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/5-lessons-from-microsoft-internship/</guid>
				<category>internship</category>
				<category>personal</category>
				<description>My Microsoft internship ended on 31st August. I had a wonderful time there and learned a lot of useful tips/lessons. In this article, I share 5 lessons that helped me the most. If you want to improve your internship/job experience make sure you read this.</description>
			</item>
			<item>
				<title>Interview With Justin Duke</title>
				<link>https://yasoob.me/posts/interview-with-justin-duke-stripe-engineer-buttondown/</link>
				<pubDate>Tue, 04 Aug 2020 16:53:32 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/interview-with-justin-duke-stripe-engineer-buttondown/</guid>
				<category>interview</category>
				<description>I sat down with Justin Duke, an engineer at Stripe, and talked about tech, startups and time management. Justin runs two startups and manages two weekly newsletters (along with a plethora of other things). Come learn about how he does it all!</description>
			</item>
			<item>
				<title>JPEG File Format Explained: Writing a JPEG Decoder in Python</title>
				<link>https://yasoob.me/posts/understanding-and-writing-jpeg-decoder-in-python/</link>
				<pubDate>Tue, 14 Jul 2020 00:00:00 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/understanding-and-writing-jpeg-decoder-in-python/</guid>
				<category>programming</category>
				<category>python</category>
				<description>How the JPEG format works: file headers and markers, Huffman coding, quantization, zigzag and the DCT, explained by writing a JPEG decoder in Python.</description>
			</item>
			<item>
				<title>Reverse Engineering Nike Run Club Android App Using Frida</title>
				<link>https://yasoob.me/posts/reverse-engineering-nike-run-club-using-frida-android/</link>
				<pubDate>Sun, 05 Jul 2020 17:08:46 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/reverse-engineering-nike-run-club-using-frida-android/</guid>
				<category>reverse-engineering</category>
				<category>programming</category>
				<category>frida</category>
				<description>After using apktool for reverse-engineering android apps I learned about Frida. Ever wondered how you can use Frida to snoop around Android apps? Learn how to do that in this step-by-step tutorial where we take a look at the Nike Run Club app.</description>
			</item>
			<item>
				<title>How to Reverse Engineer an Android APK with apktool and jadx</title>
				<link>https://yasoob.me/posts/reverse-engineering-android-apps-apktool/</link>
				<pubDate>Mon, 22 Jun 2020 00:00:00 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/reverse-engineering-android-apps-apktool/</guid>
				<category>reverse-engineering</category>
				<category>programming</category>
				<description>Step-by-step guide to reverse engineering an Android APK: decompile it with apktool and jadx, edit the smali code, then rebuild, sign, and install the app.</description>
			</item>
			<item>
				<title>Help! My browser isn&#39;t connecting to public WiFi!</title>
				<link>https://yasoob.me/posts/connecting-public-wifi-login-page/</link>
				<pubDate>Sun, 14 Jun 2020 00:01:05 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/connecting-public-wifi-login-page/</guid>
				<category>random-tip</category>
				<description>Have you ever found yourself unable to connect to a public WiFi just because your browser couldn&amp;#39;t open the login page? Learn a simple trick which always works.</description>
			</item>
			<item>
				<title>Privacy Preserving Google Analytics Alternatives</title>
				<link>https://yasoob.me/posts/privacy-preserving-analytics-solutions/</link>
				<pubDate>Sat, 13 Jun 2020 04:11:51 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/privacy-preserving-analytics-solutions/</guid>
				<category>privacy</category>
				<category>analytics</category>
				<description>Learn about the potential Google Analytics alternatives that you can use to track useful metric without invading your user&amp;#39;s privacy</description>
			</item>
			<item>
				<title>9 Tips For Better Scripting Experience</title>
				<link>https://yasoob.me/posts/tips-for-better-scripting/</link>
				<pubDate>Fri, 12 Jun 2020 00:17:55 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/tips-for-better-scripting/</guid>
				<category>python</category>
				<category>sysadmin</category>
				<category>programming</category>
				<description>Learn about some general scripting tips that will help you level up your scripting game. I learned them the hard-way but you don&amp;#39;t have to.</description>
			</item>
			<item>
				<title>How to Deploy old Django project using NGINX, Docker and UWSGI</title>
				<link>https://yasoob.me/posts/deploying-django-docker-nginx-uwsgi/</link>
				<pubDate>Thu, 11 Jun 2020 02:01:59 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/deploying-django-docker-nginx-uwsgi/</guid>
				<category>sysadmin</category>
				<category>python</category>
				<category>django</category>
				<category>nginx</category>
				<category>docker</category>
				<description>I talk about the steps I took to migrate a Django 1.7 (Python 2.8) project to Docker, UWSGI and NGINX on a new server. The steps for new Django projects are also similar.</description>
			</item>
			<item>
				<title> Why I Moved Away From Wordpress.com</title>
				<link>https://yasoob.me/posts/why-i-moved-from-wordpress-com/</link>
				<pubDate>Mon, 08 Jun 2020 00:00:04 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/why-i-moved-from-wordpress-com/</guid>
				<category>wordpress</category>
				<category>migration</category>
				<category>hugo</category>
				<description>I recently moved pythontips.com from Wordpress to Hugo. I talk about the rationale for doing so and what benefits (if any) I have observed after this migration.</description>
			</item>
			<item>
				<title>Migrating from Wordpress.com to Hugo With Comments</title>
				<link>https://yasoob.me/posts/migrating-wordpress-com-to-hugo-with-comments/</link>
				<pubDate>Sat, 06 Jun 2020 03:16:17 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/migrating-wordpress-com-to-hugo-with-comments/</guid>
				<category>wordpress</category>
				<category>migration</category>
				<category>hugo</category>
				<description>If you are thinking about migrating from WordPress to Hugo (or any other static site generator) you can learn from my experience. I talk about the steps I took. You will be able to preserve the comments and SEO.</description>
			</item>
			<item>
				<title>Docker attach vs exec &amp; When to Use What</title>
				<link>https://yasoob.me/posts/docker-attach-vs-exec-when-to-use-what/</link>
				<pubDate>Thu, 04 Jun 2020 00:00:16 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/docker-attach-vs-exec-when-to-use-what/</guid>
				<category>sysadmin</category>
				<category>internship</category>
				<category>docker</category>
				<description>I have been working quite a lot with Docker for my current project. If attach &amp;amp; exec have been giving you some trouble then this post will teach you the difference b/w both. You will also learn about when to use what.</description>
			</item>
			<item>
				<title>Account Hacked, Send $2000 in Bitcoin</title>
				<link>https://yasoob.me/posts/account_hacked_send_2000_dollar_bitcoin/</link>
				<pubDate>Tue, 02 Jun 2020 01:37:18 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/account_hacked_send_2000_dollar_bitcoin/</guid>
				<category>random</category>
				<category>hacking</category>
				<category>bitcoin</category>
				<description>A friend recently received an email from a Hacker demanding $2000 in Bitcoin. In this article you will learn how the hackers get the emails and passwords of unsuspecting users and whether you should actually send them $2000 or not.</description>
			</item>
			<item>
				<title>Software Engineering Within SpaceX</title>
				<link>https://yasoob.me/posts/software_engineering_within_spacex_launch/</link>
				<pubDate>Mon, 01 Jun 2020 15:51:39 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/software_engineering_within_spacex_launch/</guid>
				<category>spacex</category>
				<category>random</category>
				<category>programming</category>
				<description>Have you ever been curious about how Software engineering within SpaceX works? I did some research and compiled my notes in this article. There are also some insightful comments from the readers at the bottom.</description>
			</item>
			<item>
				<title>How to Create an SSH Alias and Set Up Passwordless SSH Login</title>
				<link>https://yasoob.me/posts/setting-up-passwordless-ssh-and-alias/</link>
				<pubDate>Wed, 20 May 2020 19:29:32 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/setting-up-passwordless-ssh-and-alias/</guid>
				<category>programming</category>
				<category>devops</category>
				<description>Create an SSH alias in ~/.ssh/config so you can type ssh myserver instead of user@host, and set up key-based passwordless login with ssh-keygen.</description>
			</item>
			<item>
				<title>Benedict Cumberbatch Digital Portrait (Procreate)</title>
				<link>https://yasoob.me/posts/benedict-cumberbatch-portrait/</link>
				<pubDate>Wed, 01 Apr 2020 00:59:22 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/benedict-cumberbatch-portrait/</guid>
				<category>art</category>
				<category>procreate</category>
				<description>I recently started doing digital portraits a bit more seriously. Look at a portrait of Benedict Cumberbatch that I made in ProCreate using a borrowed iPad.</description>
			</item>
			<item>
				<title>Making Generative Portraits Using Processing</title>
				<link>https://yasoob.me/posts/generative-art-portrait-advanced-studio-projects/</link>
				<pubDate>Wed, 05 Feb 2020 13:35:26 -0500</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/generative-art-portrait-advanced-studio-projects/</guid>
				<category>generative-art</category>
				<category>processing</category>
				<category>algorithmic-art</category>
				<category>portrait</category>
				<description>Do you know what generative algorithms are? I talk about how I used generative algorithms and Processing to make portraits for my advanced studio projects class.</description>
			</item>
			<item>
				<title>First Step into the World of Generative Art</title>
				<link>https://yasoob.me/posts/art-graphics-processing-p5js/</link>
				<pubDate>Wed, 02 Oct 2019 23:07:50 +0200</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/art-graphics-processing-p5js/</guid>
				<category>art</category>
				<category>processing</category>
				<category>p5js</category>
				<description>Have you used Processing before? It allows you to create sketches using programming. Take a look at some looping GIFs I made using Processing. I will share some resources that you can use to make your own perfectly looping GIFs.</description>
			</item>
			<item>
				<title>Filtering &amp; Closing Pull Requests on GitHub using the API</title>
				<link>https://yasoob.me/2019/09/18/filtering-closing-pull-requests-on-github-using-the-api/</link>
				<pubDate>Wed, 18 Sep 2019 06:00:11 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2019/09/18/filtering-closing-pull-requests-on-github-using-the-api/</guid>
				<category>python</category>
				<description>My blog uses Staticman for comments and recently got a lot of fake comments. I used the GitHub API to filter out and mass-delete comments. Learn about how you can do something similar.</description>
			</item>
			<item>
				<title>Looking for an internship for Summer 2020</title>
				<link>https://yasoob.me/2019/09/17/looking-for-an-internship-for-summer-2020/</link>
				<pubDate>Tue, 17 Sep 2019 20:27:49 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2019/09/17/looking-for-an-internship-for-summer-2020/</guid>
				<category>Personal</category>
				<description>I wrote this article when I was looking for new internship opportunities. I got one with the Azure Cloud Networking team at Microsoft.</description>
			</item>
			<item>
				<title>Project Greenhouse Using Arduino, Raspberry Pi &amp; Sensors</title>
				<link>https://yasoob.me/posts/project-greenhouse-arduino-raspberry-pi-sensors/</link>
				<pubDate>Tue, 17 Sep 2019 01:01:01 +0200</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/project-greenhouse-arduino-raspberry-pi-sensors/</guid>
				<category>arduino</category>
				<category>electronics</category>
				<description>Take a look at the final project I made using Arduino, Raspberry Pi &amp;amp; a couple of sensors for a digital studio class. I have also written some in-process articles about this project in the past.</description>
			</item>
			<item>
				<title>My Internship Experience at ASAPP</title>
				<link>https://yasoob.me/posts/internship-experience-at-asapp/</link>
				<pubDate>Mon, 16 Sep 2019 13:21:13 +0200</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/internship-experience-at-asapp/</guid>
				<category>internship</category>
				<category>personal</category>
				<description>In summer 2019, I interned at a communication startup called ASAPP in NYC. I talk about my experience and what I learned during my time there.</description>
			</item>
			<item>
				<title>Python mind-teaser: Make the function return True</title>
				<link>https://yasoob.me/2019/07/30/python-mind-teaser-make-the-function-return-true/</link>
				<pubDate>Tue, 30 Jul 2019 22:43:13 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2019/07/30/python-mind-teaser-make-the-function-return-true/</guid>
				<category>python</category>
				<description>I came across this teaser on Reddit. It took me some time to figure out the solution. Look at the question and see if you can figure it out on your own before looking at my detailed writeup.</description>
			</item>
			<item>
				<title>Staticman Comment Notifications Setup Using Mailgun</title>
				<link>https://yasoob.me/posts/staticman_comment_notifications_mailgun/</link>
				<pubDate>Wed, 26 Jun 2019 17:54:58 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/staticman_comment_notifications_mailgun/</guid>
				<category>programming</category>
				<description>We all like receiving email notifications whenever someone replies to our comments. Learn about how to setup email notifications for Staticman comments using Mailgun.</description>
			</item>
			<item>
				<title>Running Staticman on Hugo Blog With Nested Comments</title>
				<link>https://yasoob.me/posts/running_staticman_on_static_hugo_blog_with_nested_comments/</link>
				<pubDate>Mon, 24 Jun 2019 17:32:59 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/running_staticman_on_static_hugo_blog_with_nested_comments/</guid>
				<category>programming</category>
				<description>No blog is complete without comments. There are a lot of options out there which allow you to add comments to your static blog. In this article, I talk about how to setup Staticman for your Hugo blog. Process is similar for other static site generators.</description>
			</item>
			<item>
				<title>Setting up dev environment for SciPy</title>
				<link>https://yasoob.me/2019/06/21/setting-up-dev-environment-for-scipy/</link>
				<pubDate>Fri, 21 Jun 2019 21:03:25 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2019/06/21/setting-up-dev-environment-for-scipy/</guid>
				<category>python</category>
				<description>Someone recently reached out and asked me how to setup a dev environment for SciPy. Read this article to find out how.</description>
			</item>
			<item>
				<title>Golang: Check if a key exists in map</title>
				<link>https://yasoob.me/posts/golang_maps_check_if_exists/</link>
				<pubDate>Tue, 18 Jun 2019 18:55:05 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/golang_maps_check_if_exists/</guid>
				<category>programming</category>
				<category>golang</category>
				<description>I have been working with Golang quite a lot. This is my first time working with it professionally. I share some methods for checking key existance in maps in Golang.</description>
			</item>
			<item>
				<title>Speeding up Python code using multithreading</title>
				<link>https://yasoob.me/2019/05/29/speeding-up-python-code-using-multithreading/</link>
				<pubDate>Wed, 29 May 2019 17:44:13 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2019/05/29/speeding-up-python-code-using-multithreading/</guid>
				<category>python</category>
				<description>Oftentimes people complain about Python being slow without realizing that there are simple solutions to their problems. Learn about how to leverage multiprocessing in Python and speed up some of your scripts by 10x or more.</description>
			</item>
			<item>
				<title>Running Python in the Browser</title>
				<link>https://yasoob.me/2019/05/22/running-python-in-the-browser/</link>
				<pubDate>Wed, 22 May 2019 17:49:45 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2019/05/22/running-python-in-the-browser/</guid>
				<category>python</category>
				<description>I wasn&amp;#39;t aware about the different solutions for running Python in the browser so I invited Shaun from Anvil to give us a run-down of what is available out there.</description>
			</item>
			<item>
				<title>Looking for a Single in New York City</title>
				<link>https://yasoob.me/posts/room-search-new-york/</link>
				<pubDate>Thu, 09 May 2019 00:21:58 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/room-search-new-york/</guid>
				<category>personal</category>
				<description>I am moving to New York for the summer and, therefore, I am looking for a single in the city. If you have any leads please send them my way!</description>
			</item>
			<item>
				<title>Extracting Data from Nike Run Club &amp; Visualizing It</title>
				<link>https://yasoob.me/posts/nike-run-club-data-visualization/</link>
				<pubDate>Wed, 01 May 2019 00:00:00 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/nike-run-club-data-visualization/</guid>
				<category>running</category>
				<category>programming</category>
				<description>I have been using Nike Run Club for years. I liked using it but was super unhappy with the fact that I wasn&amp;#39;t officially allowed to export my data. I went ahead and reversed their API. Learn about how you too can extract your data from NRC.</description>
			</item>
			<item>
				<title>Creating Offline Custom Style Maps With tileserver-gl</title>
				<link>https://yasoob.me/posts/custom-map-with-tileserver-gl/</link>
				<pubDate>Sat, 27 Apr 2019 14:33:31 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/custom-map-with-tileserver-gl/</guid>
				<category>programming</category>
				<category>maps</category>
				<description>Tileserver-gl is an amazing project that allows you to make custom styles for maps. Learn about how to make beautiful styled map posters using tileserver-gl. The best part? It is completely open source!</description>
			</item>
			<item>
				<title>6 Tips Before You Write Your Next Bash Cronjob</title>
				<link>https://yasoob.me/posts/6-tips-before-you-write-your-next-bash-cronjob/</link>
				<pubDate>Mon, 22 Apr 2019 19:59:49 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/6-tips-before-you-write-your-next-bash-cronjob/</guid>
				<category>sysadmin</category>
				<description>I spent the full summer writing Bash cronjobs for a research project. I had to learn far too many things the hard way. I am hoping that this article will help you spend less time stumbling around and more time producing useful results.</description>
			</item>
			<item>
				<title>🌿 Greenhouse Part 3: Connecting LCD With Arduino</title>
				<link>https://yasoob.me/posts/connecting-lcd-with-arduino/</link>
				<pubDate>Sun, 21 Apr 2019 01:11:12 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/connecting-lcd-with-arduino/</guid>
				<category>arduino</category>
				<category>electronics</category>
				<category>LCD</category>
				<description>Third part of my three part series about Arduinos and sensors. Learn how to conenct an LCD with Arduino and how to display data on it.</description>
			</item>
			<item>
				<title>🌿 Greenhouse Part 2: Measuring Temperature &amp; Light Intensity</title>
				<link>https://yasoob.me/posts/temperature-light-intensity-sensor-arduino/</link>
				<pubDate>Sat, 20 Apr 2019 20:12:17 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/temperature-light-intensity-sensor-arduino/</guid>
				<category>arduino</category>
				<category>electronics</category>
				<category>sensor</category>
				<description>Second part from my three part series about Arduinos and sensors. Learn about how to connect temperature and photo sensors with Arduino and extract useful data from them.</description>
			</item>
			<item>
				<title>🌿 Greenhouse Part 1: Using Yl-69 Soil Sensor With Arduino</title>
				<link>https://yasoob.me/posts/yl-69-soil-sensor-arduino/</link>
				<pubDate>Sat, 20 Apr 2019 19:34:33 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/yl-69-soil-sensor-arduino/</guid>
				<category>arduino</category>
				<category>electronics</category>
				<category>sensor</category>
				<description>First part from my three part series about Arduinos and sensors. Learn about how to connect the Yl-69 soil sensor with Arduino and get useful data from it.</description>
			</item>
			<item>
				<title>Connecting and Interfacing Raspberry Pi with Arduino</title>
				<link>https://yasoob.me/posts/interfacing-raspberry-pi-arduino/</link>
				<pubDate>Wed, 17 Apr 2019 11:28:41 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/interfacing-raspberry-pi-arduino/</guid>
				<category>electronics</category>
				<category>raspberry-pi</category>
				<description>Hi lovely people! 👋 I am working on a greenhouse monitoring project and I had to connect my Arduino to the internet over WiFi. I wanted to push some sensor data to my server. I could have bought a WiFi shield for the Arduino but why spend more money when you already have a Pi with WiFi card? I ended up connecting Arduino with my Pi and pushing sensor data to my server through the Pi. The process was super simple.</description>
			</item>
			<item>
				<title>Headless Interfacing with Raspberry Pi 3 over UART using CP210x</title>
				<link>https://yasoob.me/posts/headless-raspberry-pi-3/</link>
				<pubDate>Tue, 16 Apr 2019 12:04:57 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/headless-raspberry-pi-3/</guid>
				<category>electronics</category>
				<category>raspberry-pi</category>
				<description>Hi people! If you read the last article you might be aware that I am exploring raspberry pi right now. I have Pi 3B+ and I am using it to work on some remote sensors. The biggest issue I have with the Pi is that I don’t have an external monitor, mouse, and keyboard handy to use with the Pi. I wanted to have a headless interface with the Raspberry pi.</description>
			</item>
			<item>
				<title>Connecting Raspberry Pi to Eduroam Wifi</title>
				<link>https://yasoob.me/posts/raspberry-pi-eduroam-wifi/</link>
				<pubDate>Sun, 14 Apr 2019 17:34:40 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/raspberry-pi-eduroam-wifi/</guid>
				<category>sysadmin</category>
				<category>raspberry-pi</category>
				<description>Hi people! 👋 I was working with Raspberry Pi lately and was trying to connect it to eduroam. If you are not familiar with eduroam, it is a service used by most universities to provide Wifi on their campuses. It uses Enterprise WPA and Raspberry Pi does not connect to it automatically out of the box. I actually found these instructions on a different website but that website is down now. I am putting these instructions here for all of you who might be stuck in the same situation.</description>
			</item>
			<item>
				<title>Revolution OS</title>
				<link>https://yasoob.me/posts/revolution-os/</link>
				<pubDate>Wed, 10 Apr 2019 11:48:52 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/revolution-os/</guid>
				<category>review</category>
				<description>I had already seen the video about the History of Unix by Rob Pike (do watch it if this kind of stuff interests you. It is available on YouTube) so I didn’t think I would learn a lot of new stuff from this movie but oh boy was I wrong. This was an interesting deep dive into the history of the GNU project and Free &amp;amp; Open Source Software movement. We take free stuff for granted nowadays. Companies like Mozilla are championing the web we can all enjoy without being walled in by any one corporation’s products.</description>
			</item>
			<item>
				<title>Art Projects</title>
				<link>https://yasoob.me/arts/</link>
				<pubDate>Wed, 10 Apr 2019 02:37:20 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/arts/</guid>
				<description>I spend considerable time doing arts and creative projects. I used to do it as a hobby but now I am taking drawing and digital studio classes at Colgate University. We have been making a lot of interesting projects and have been trying to push the limits of creativity. Here are some of the projects I have done so far: Processing/Digital Sketches I recently started exploring the world of generative art and this is the result of that. I used processing/p5js to make these. I hope you like them. I might write some articles in the future about how I made some of these. In the meantime you should definitely check out Daniel Shiffman’s videos. He publishes on “The Coding Train” channel on YouTube.</description>
			</item>
			<item>
				<title>About</title>
				<link>https://yasoob.me/about/</link>
				<pubDate>Tue, 09 Apr 2019 19:50:04 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/about/</guid>
				<description>During the last couple of years I have completed numerous projects, authored a widely read programming book, Intermediate Python, and written 150+ programming articles. My work has benefitted people at: My book and articles have been read by 5+ Million people in 189+ countries. If you are interested in learning more about how I got into programming please read this article. I am currently working on some cool stuff at Microsoft with the Azure Cloud Networking team. You can check out my infrequently updated résumé here if you want.</description>
			</item>
			<item>
				<title>New blog new me</title>
				<link>https://yasoob.me/posts/welcome/</link>
				<pubDate>Tue, 09 Apr 2019 12:23:27 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/welcome/</guid>
				<category>personal</category>
				<description>Hi everyone! I have been thinking about starting a blog on my personal website for quite a while now. Previously I just blogged on Python Tips. Even stuff which did not relate with Python found its way to Python Tips. I think some distinction is important. I always had to do some mental struggle to justify posting some non-python content on Python Tips. Having this blog will surely mean that I will give even less time to Python Tips but it also means that I will be able to write more. It is a net gain for me personally. I have already given up on so many article ideas just because they did not align with the theme of Python Tips. Hopefully, now I won’t have to do that.</description>
			</item>
			<item>
				<title>Python dis module and constant folding</title>
				<link>https://yasoob.me/2019/02/26/python-dis-module-and-constant-folding/</link>
				<pubDate>Tue, 26 Feb 2019 05:40:49 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2019/02/26/python-dis-module-and-constant-folding/</guid>
				<category>python</category>
				<description>Hi people! Recently, I was super confused when I found out that: &amp;gt;&amp;gt;&amp;gt; pow(3,89) runs slower than: &amp;gt;&amp;gt;&amp;gt; 3**89 I tried to think of a suitable answer but couldn’t find any. I timed the execution of both of these statements using the timeit module in Python3: $ python3 -m timeit &amp;#39;pow(3,89)&amp;#39; 500000 loops, best of 5: 688 nsec per loop $ python3 -m timeit &amp;#39;3**89&amp;#39; 500000 loops, best of 5: 519 nsec per loop The difference is not big. It is only 0.1µs but it was still bugging me. If I can’t explain something in programming, I usually end up having sleepless nights 😅</description>
			</item>
			<item>
				<title>Issues with how we teach</title>
				<link>https://yasoob.me/2019/02/05/issues-with-how-we-teach/</link>
				<pubDate>Tue, 05 Feb 2019 05:55:26 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2019/02/05/issues-with-how-we-teach/</guid>
				<category>Personal</category>
				<description>Throughout my life, I used to ask myself, “How do people invent something?”. In my case, I was specifically concerned with Maths, Physics, and Computer Science. I would ask myself, “I know how to use these formulas but how did someone come up with these formulas?”. My teachers’ responses were always the same: “Don’t worry you will understand how it works later on. For now, just learn how to use this formula”. Okay, that was simple. I was already doing it. Learning a bunch of formulas without realizing “what” or “who” they were.</description>
			</item>
			<item>
				<title>Research Writeup: Deanonymization and Proximity Detection Using Wi-Fi</title>
				<link>https://yasoob.me/2018/12/13/research-writeup-deanonymization-and-proximity-detection-using-wi-fi/</link>
				<pubDate>Thu, 13 Dec 2018 05:54:12 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/12/13/research-writeup-deanonymization-and-proximity-detection-using-wi-fi/</guid>
				<category>Personal</category>
				<description>Hi everyone! If you have been following my blog for a while you will know that I did research at Colgate University over the summers. My research was on Wi-Fi and how I can do some interesting stuff using it. The university just published its annual catalogue of all the research projects which happened over the summer. My research was done under the mentorship of Aaron Gember-Jacobson. I could not have asked for a better advisor. Here is the writeup of my project:</description>
			</item>
			<item>
				<title>Email Security &amp; Privacy</title>
				<link>https://yasoob.me/2018/12/01/email-security-privacy/</link>
				<pubDate>Sat, 01 Dec 2018 20:00:55 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/12/01/email-security-privacy/</guid>
				<category>Personal</category>
				<description>Hi everyone! I hope all of you are doing well. Things have been super exciting on my side. Just got done with a file system checker project in C for my Operating Systems class. It was mentally draining but equally rewarding. This blog post is not about Python but rather about Emails. This week I also gave a department wide talk at Colgate University on Email security and privacy and some of the SMTP features which are available at your disposal. It went fairly successful. This was a result of my own independent research on the topic. I tried to cover as much base as possible while also trying to keep the talk engaging.</description>
			</item>
			<item>
				<title>Review: The History of Unix Video</title>
				<link>https://yasoob.me/2018/11/10/review-history-of-unix-video/</link>
				<pubDate>Sat, 10 Nov 2018 23:41:42 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/11/10/review-history-of-unix-video/</guid>
				<category>Personal</category>
				<description>Hi everyone! If you have been following my blog for a while, you will know how much I love computers. I recently watched this video about the history of Unix and decided to write a short post about it. It’s a one hour presented by Rob Pike who joined Bell labs and worked on Unix in the 70’s. I got to know about the video via Hacker News (you should definitely follow it if you don’t!).</description>
			</item>
			<item>
				<title>Privacy &amp; Why it Matters</title>
				<link>https://yasoob.me/2018/10/04/privacy-why-it-matters/</link>
				<pubDate>Fri, 05 Oct 2018 01:42:07 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/10/04/privacy-why-it-matters/</guid>
				<category>Personal</category>
				<description>⚠️ Long post about privacy. Doesn’t relate to Python at all. Do read if you care and want to learn more about how your privacy is being violated. Last couple of weeks have totally changed my whole viewpoint on privacy. I was also a part of that bandwagon in which people say that “Why should I be worried about privacy when I don’t have anything to hide or I don’t do anything illegal?”. You start taking it seriously only when your privacy is breached. Let me reiterate, privacy is a fundamental right and should be granted to everyone.</description>
			</item>
			<item>
				<title>Sending &amp; Sniffing WLAN Beacon Frames using Scapy</title>
				<link>https://yasoob.me/2018/09/08/sending-sniffing-wlan-beacon-frames-using-scapy/</link>
				<pubDate>Sat, 08 Sep 2018 16:48:21 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/09/08/sending-sniffing-wlan-beacon-frames-using-scapy/</guid>
				<category>python</category>
				<description>Hi everyone! Over the summers I did research on Wi-Fi and part of my research involved sending and receiving different kinds of IEEE 802.11 packets. I did most of this stuff using Scapy so I thought why not create a tutorial about it? When I started my research I had to look through multiple online articles/tutorials in order to get started with Scapy. In order to save you time I am going to bring you up-to speed by running you through a short tutorial.</description>
			</item>
			<item>
				<title>Practical Python Projects Book</title>
				<link>https://yasoob.me/2018/07/02/practical-python-projects-book/</link>
				<pubDate>Mon, 02 Jul 2018 22:17:48 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/07/02/practical-python-projects-book/</guid>
				<category>python</category>
				<description>Hi everyone! I am super proud to announce that my second book 🎉🎉&amp;#34;Practical Python Projects&amp;#34;🎉🎉 is alhamdulillah almost halfway done content-wise. This book is a direct result of a market gap which I found when I started programming a couple of years back. Most programming beginners have access to multiple resources to teach themselves the basics of Python (or any other language) but they don’t have access to those books/tutorials where they are taught to create end-to-end projects in a specific language. A fair amount of online tutorials and beginner textbooks teach the reader only the basics of a language without real-life concrete project development.</description>
			</item>
			<item>
				<title>A FIFA 2018 World Cup SMS bot using Twilio, Heroku and Flask</title>
				<link>https://yasoob.me/2018/06/25/a-fifa-world-cup-sms-bot-using-twilio-heroku-and-flask/</link>
				<pubDate>Mon, 25 Jun 2018 05:53:07 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/06/25/a-fifa-world-cup-sms-bot-using-twilio-heroku-and-flask/</guid>
				<category>python</category>
				<description>Hi everyone! I am back with yet another tutorial. Its World Cup season and every other person is rooting for his/her favorite team. I was thinking about the next blog post idea and I thought why not create a project which can help you stay updated with how the world cup is progressing? And along the way, I might be able to teach myself (and you) something new. The end product is this tutorial. The project we are going to be developing is a Twilio application, hosted on Heroku. It is a chat (SMS) bot or sorts. You will be able to send various special messages to this bot and it will respond with the latest World cup updates.</description>
			</item>
			<item>
				<title>An Intro to Web Scraping With lxml and Python</title>
				<link>https://yasoob.me/2018/06/20/an-intro-to-web-scraping-with-lxml-and-python/</link>
				<pubDate>Wed, 20 Jun 2018 07:46:48 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/06/20/an-intro-to-web-scraping-with-lxml-and-python/</guid>
				<category>python</category>
				<description>Hello everyone! I hope you are doing well. In this article, I’ll teach you the basics of web scraping using lxml and Python. I also recorded this tutorial in a screencast so if you prefer to watch me do this step by step in a video please go ahead and watch it below. However, if for some reason you decide that you prefer text, just scroll a bit more and you will find the text of that same screencast.</description>
			</item>
			<item>
				<title>Top 14 MOST famous Python libraries &amp; frameworks</title>
				<link>https://yasoob.me/2018/06/03/top-14-most-famous-python-libraries-frameworks/</link>
				<pubDate>Sun, 03 Jun 2018 04:47:33 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/06/03/top-14-most-famous-python-libraries-frameworks/</guid>
				<category>python</category>
				<description>Hi everyone! I recently decided to step into YouTube video making. This is my first video about 14 of my most favourite and most famous Python libraries and frameworks. Please take a look and if you have ANY suggestions as to how I can improve the quality of the videos in the future please let me know in the comments below. </description>
			</item>
			<item>
				<title>Python local/global scopes</title>
				<link>https://yasoob.me/2018/05/18/python-local-global-scopes/</link>
				<pubDate>Fri, 18 May 2018 20:47:14 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/05/18/python-local-global-scopes/</guid>
				<category>python</category>
				<description>How’s everyone? I am back with another tip/gotcha which might trip beginner programmers. This one relates to Python scopes so if you are already familiar with them then this article might not be very informative for you. If you are not very well versed in Python scopes then keep reading. Lets start with a code sample. Save the following code in a file and run it: command = &amp;#34;You are a LOVELY person!&amp;#34; def shout(): print(command) shout() print(command) Output:</description>
			</item>
			<item>
				<title>Reverse Engineering Facebook API: Private Video Downloader</title>
				<link>https://yasoob.me/2018/04/23/reverse-engineering-facebook-api-private-video-downloader/</link>
				<pubDate>Mon, 23 Apr 2018 22:08:14 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/04/23/reverse-engineering-facebook-api-private-video-downloader/</guid>
				<category>python</category>
				<description>Welcome back! This is the third post in the reverse engineering series. The first post was reverse engineering Soundcloud API and the second one was reverse engineering Facebook API to download public videos. In this post we will take a look at downloading private videos. We will reverse engineer the API calls made by Facebook and will try to figure out how we can download videos in the HD format (when available).</description>
			</item>
			<item>
				<title>Reverse Engineering Facebook: Public Video Downloader</title>
				<link>https://yasoob.me/2018/04/23/reverse-engineering-facebook-video/</link>
				<pubDate>Mon, 23 Apr 2018 13:47:07 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/04/23/reverse-engineering-facebook-video/</guid>
				<category>python</category>
				<description>In the last post we took a look at downloading songs from Soundcloud. In this post we will take a look at Facebook and how we can create a downloader for Facebook videos. It all started with me wanting to download a video from Facebook which I had the copyrights to. I wanted to automate the process so that I could download multiple videos with just one command.</description>
			</item>
			<item>
				<title>Reverse Engineering Soundcloud API</title>
				<link>https://yasoob.me/2018/04/15/reverse-engineering-soundcloud-api/</link>
				<pubDate>Sun, 15 Apr 2018 06:19:49 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/04/15/reverse-engineering-soundcloud-api/</guid>
				<category>python</category>
				<description>Hi guys, in this post we will learn how to bypass downloading restrictions on Soundcloud. We will create a Python script which will allow us to download even those songs which are not enabled for downloading. We will work on this project in a step by step basis where we will tackle each problem as we encounter it. I will try to make it as universal in nature as possible so that you can follow this project even if Soundcloud has changed its website layout or the way it serves media files. So without any further ado let’s get started:</description>
			</item>
			<item>
				<title>Monthly Roundup: February 2018</title>
				<link>https://yasoob.me/2018/03/05/monthly-roundup-february-2018/</link>
				<pubDate>Mon, 05 Mar 2018 23:07:05 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/03/05/monthly-roundup-february-2018/</guid>
				<category>python</category>
				<description>Hi guys! I hope you are all doing well! I am back with the a curation of the best articles, news and trending GitHub projects from February 2018. If you come across any articles, news, projects in March which you feel like should be a part of the next newsletter please reach out to me. I will love to add them to the list! I hope you enjoy this issue. If you do please share it with your social circle!</description>
			</item>
			<item>
				<title>Controlling Your System Using Alexa (Tutorial)</title>
				<link>https://yasoob.me/2018/02/15/controlling-your-system-using-alexa-tutorial/</link>
				<pubDate>Thu, 15 Feb 2018 18:25:26 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/02/15/controlling-your-system-using-alexa-tutorial/</guid>
				<category>python</category>
				<description>Hi guys! I hope you are all doing fine. I have started working on a small compilation of projects which you can do under 24 hours. I will be publishing these projects in the form of tutorials on my blog. This is the first project and I hope you will enjoy doing it. Keep these two things in mind: You don’t need an actual Alexa to follow this tutorial. Amazon provides an online simulator which you can use I will be omitting the instructions on how to get a virtual environment up and running just so that I can keep this tutorial concise and to the point. You should use a virtualenv and execute all of these pip instructions in a virtualenv. I did this project at BrickHack 4. This was the very first time I was using Alexa. I had never been in its proximity before. I wanted to develop such a skill which was not available online and which contained a certain level of twists so that it wasn’t boring. In the end I settled on an idea to control my system using Alexa. The main idea is that you can tell Alexa to carry out different commands on your system remotely. This will work even if your system/computer is in your office and you and your Alexa are at home. So without any further ado lets get started.</description>
			</item>
			<item>
				<title>DocRaptor review</title>
				<link>https://yasoob.me/2018/01/25/docraptor-review/</link>
				<pubDate>Fri, 26 Jan 2018 01:51:59 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/01/25/docraptor-review/</guid>
				<category>Sponsored</category>
				<description>Hi everyone, I was recently contacted by the folks at DocRaptor telling me about their service so I decided to take it for a test drive and see for myself what it actually is. DocRaptor provides you with an API to generate PDF and XLS files from HTML and CSS files. Today we will take a look at how we can use it to generate the PDF for a payment receipt.</description>
			</item>
			<item>
				<title>2017 was good, 2018 will be even better</title>
				<link>https://yasoob.me/2018/01/03/2017-was-good-2018-will-be-even-better/</link>
				<pubDate>Wed, 03 Jan 2018 18:51:24 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2018/01/03/2017-was-good-2018-will-be-even-better/</guid>
				<category>Personal</category>
				<description>This is not a programming or Python related post. This is more of my personal reflection on the year 2017. I decided to reflect and evaluate my year and see what I got done and what could have been better. Below I have listed some of the stuff which I was able to get done this year. Visited UK and Bahrain 🇬🇧🇧🇭 I love travelling and exploring new places. This year I got a chance to visit UK (Cambridge, Newcastle and London) and Bahrain (Manama). I visited these places in January 2017 and learned a ton about both of these places. Next year (2018) I plan on exploring USA.</description>
			</item>
			<item>
				<title>How I got into programming</title>
				<link>https://yasoob.me/2017/12/01/how-i-got-into-programming/</link>
				<pubDate>Fri, 01 Dec 2017 07:46:47 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2017/12/01/how-i-got-into-programming/</guid>
				<category>python</category>
				<description>Hi everyone! I hope all of you are doing great. If you have been following my blog for a while and keeping a lookout at the comments then you might know a bit about me. If you don’t then today I am going to share my story. That’s me 🙂 I am freshman at Colgate university in upstate New York (more on this later). I have been programming since I was 12 years old and it all began because of an online multiplayer game called Club Penguin. I used to play that game and like every 12 year old I wanted to excel in it; the only problem was that you had to pay in order to get ahead of everyone else. I wanted to buy stuff without paying and that is how I came across a software called Penguin Storm. That software allowed a person to buy anything without paying a dime. Everything was well and good until I found that all of the stuff which I was buying was being displayed only in that software and wasn’t actually affecting the real game. This led me on a quest to figure out how that software worked.</description>
			</item>
			<item>
				<title>Introduction to Machine Learning and its Usage in Remote Sensing</title>
				<link>https://yasoob.me/2017/11/11/introduction-to-machine-learning-and-its-usage-in-remote-sensing/</link>
				<pubDate>Sat, 11 Nov 2017 21:34:35 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2017/11/11/introduction-to-machine-learning-and-its-usage-in-remote-sensing/</guid>
				<category>python</category>
				<description>Hey guys! I recently wrote a review paper regarding the use of Machine Learning in Remote Sensing. I thought that some of you might find it interesting and insightful. It is not strictly a Python focused research paper but is interesting nonetheless. Introduction to Machine Learning and its Usage in Remote Sensing 1. Introduction Machines have allowed us to do complex computations in short amounts of time. This has given rise to an entirely different area of research which was not being explored: teaching machines to predict a likely outcome by looking at patterns. Machine Learning is being used to solve almost all kinds of problems ranging from Stock Market predictions to medical formulae synthesis.</description>
			</item>
			<item>
				<title>Weird Comparison Issue in Python</title>
				<link>https://yasoob.me/2017/10/15/weird-comparison-issue-in-python/</link>
				<pubDate>Sun, 15 Oct 2017 03:23:41 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2017/10/15/weird-comparison-issue-in-python/</guid>
				<category>python</category>
				<description>Hi guys! I am back with a new article. This time I will tackle a problem which seems easy enough at first but will surprize some of you. Suppose you have the following piece of code: a = 3 b = False c = &amp;#34;&amp;#34;&amp;#34;12&amp;#34;&amp;#34;&amp;#34; d = 4.7 and you have to evaluate this: d + 2 * a &amp;gt; int(c) == b Before reading the rest of the post please take a minute to solve this statement in your head and try to come up with the answer.</description>
			</item>
			<item>
				<title>Intermediate Python Book Anniversary</title>
				<link>https://yasoob.me/2017/09/27/intermediate-python-book-anniversary/</link>
				<pubDate>Wed, 27 Sep 2017 04:59:43 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2017/09/27/intermediate-python-book-anniversary/</guid>
				<category>python</category>
				<description>🙌 Hopefully this will be the last update regarding my book for a while. It has been 2 years ⏱ since I self-published my “Intermediate Python” book 📖. In just a short span of 2 years I can not thank Allah enough for the level of success the book has achieved. It has been translated into Chinese, Russian, Portuguese and Korean. A couple of days ago it hit the 🎉 🎉 520,000 readers mark 🎉🎉. Yes, you read that right! The book has been read by half a million people to date. This is just for the English version and I am pretty sure that Chinese version has been read by a lot more people.</description>
			</item>
			<item>
				<title>13 Python libraries to keep you busy</title>
				<link>https://yasoob.me/2017/09/19/13-python-libraries-to-keep-you-busy/</link>
				<pubDate>Tue, 19 Sep 2017 01:22:39 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2017/09/19/13-python-libraries-to-keep-you-busy/</guid>
				<category>python</category>
				<description>Hi guys! I was recently contacted by folks from AppDynamics (a part of CISCO). They shared an infographic with me which listed 13 Python libraries. These libraries were categorized in sections. I loved going through that infographic. I hope you guys will enjoy it too. Source: AppDynamics</description>
			</item>
			<item>
				<title>PyCon Pakistan &amp; The First Meetup in Lahore</title>
				<link>https://yasoob.me/2017/08/02/pycon-pakistan-the-first-meetup-in-lahore/</link>
				<pubDate>Wed, 02 Aug 2017 06:28:13 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2017/08/02/pycon-pakistan-the-first-meetup-in-lahore/</guid>
				<category>python</category>
				<description>Hi there guys! I will be starting my bachelors at Colgate University in Hamilton, US from this month. I have been pretty busy lately with making all of the required arrangements. However, during this time I got a chance to attend the first ever Python meetup in Lahore, Pakistan. It was hosted on July 22nd. I am a bit late with this write-up so without any further ado let’s get right into it.</description>
			</item>
			<item>
				<title>Making a Reddit &#43; Facebook Messenger Bot</title>
				<link>https://yasoob.me/2017/04/13/making-a-reddit-facebook-messenger-bot/</link>
				<pubDate>Wed, 12 Apr 2017 20:31:41 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2017/04/13/making-a-reddit-facebook-messenger-bot/</guid>
				<category>python</category>
				<description>Hi guys! I haven’t been programming a lot lately because of exams. However, on the past weekend I managed to get a hold of my laptop and crank out something useful. It was a Facebook messenger bot which servers you fresh memes, motivational posts, jokes and shower thoughts. It was the first time I had delved into bot creation. In this post I will teach you most of the stuff you need to know in order to get your bot off the ground.</description>
			</item>
			<item>
				<title>Recovering lost Python source code if it’s still resident in-memory</title>
				<link>https://yasoob.me/2017/03/12/recovering-lost-python-source-code-if-its-still-resident-in-memory/</link>
				<pubDate>Sun, 12 Mar 2017 18:38:04 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2017/03/12/recovering-lost-python-source-code-if-its-still-resident-in-memory/</guid>
				<category>python</category>
				<description>I read this on GitHub Gist the other day. I don’t know whether I will ever use it but I am still putting this on my blog for the sake of bookmarking it. Who knows? Someone from the audience might end up using it! I screwed up using git (git checkout – on the wrong file) and managed to delete the code I had just written… but it was still running in a process in a docker container. Here’s how I got it back, using pyrasite and uncompyle6</description>
			</item>
			<item>
				<title>Importing with ctypes in Python: fighting overflows</title>
				<link>https://yasoob.me/2017/03/10/importing-with-ctypes-in-python-fighting-overflows/</link>
				<pubDate>Fri, 10 Mar 2017 11:31:41 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2017/03/10/importing-with-ctypes-in-python-fighting-overflows/</guid>
				<category>python</category>
				<description>Introduction On some cold winter night, we’ve decided to refactor a few examples and tests for Python wrapper in Themis, because things have to be not only efficient and useful, but elegant as well. One thing after another, and we ended up revamping Themis error codes a bit. Internal error and status flags sometimes get less attention than crypto-related code: they are internals for internal use. Problem is, when they fail, they might break something more crucial in a completely invisible way.</description>
			</item>
			<item>
				<title>Your first talk</title>
				<link>https://yasoob.me/2016/10/17/your-first-talk/</link>
				<pubDate>Mon, 17 Oct 2016 08:55:06 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2016/10/17/your-first-talk/</guid>
				<category>python</category>
				<category>Uncategorized</category>
				<description>Hi there folks. It’s been a long time since I wrote on this blog. I have been very busy with university applications. A lot has happened recently which I will love to share with you. Firstly, I got a news from a friend that my book is being used in McGill University to teach Python programming. That is something I have always wanted, write a book which is used by well-known universities to teach programming. But this post is not about that. I wanted to share how to deliver a good first talk. People dread sharing their first talk with the world because it is mostly filled with “aaahhh&amp;#34;s and fast paced speech but I am</description>
			</item>
			<item>
				<title>Interesting Python Tutorials</title>
				<link>https://yasoob.me/2016/08/19/interesting-python-tutorials/</link>
				<pubDate>Fri, 19 Aug 2016 16:58:01 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2016/08/19/interesting-python-tutorials/</guid>
				<category>python</category>
				<description>Hi there folks! I have read some interesting Python tutorials lately. I would love to share them with you. Without any further ado let me list them over here: 1. Composing Music With Recurrent Neural Networks I loved this tutorial. It is a bit old but still worth a read. The author has explained the theory behind his implementation. You will enjoy this tutorial if you are interested in signal processing, machine learning and/or music.</description>
			</item>
			<item>
				<title>Intermediate Python conquers the World! (Almost)</title>
				<link>https://yasoob.me/2016/08/10/intermediate-python-conquers-the-world-almost/</link>
				<pubDate>Wed, 10 Aug 2016 18:51:01 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2016/08/10/intermediate-python-conquers-the-world-almost/</guid>
				<category>python</category>
				<description>Hi there folks! I hope you are all fine. It’s been almost a year since I published Intermediate Python. It was my life goal to publish a book which really helps people. Today I saw the stats of the book after a long time. I was pretty ecstatic to know that the English version (It is also available in Chinese and Russian) of the book has been read in 181 countries. Just 15 countries short of the whole world.</description>
			</item>
			<item>
				<title>This Month I Inspired 40 Teens to Start Programming</title>
				<link>https://yasoob.me/2016/05/31/this-month-i-inspired-40-teens-to-start-programming/</link>
				<pubDate>Tue, 31 May 2016 15:10:44 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2016/05/31/this-month-i-inspired-40-teens-to-start-programming/</guid>
				<category>python</category>
				<description>Hi there folks! I have been wanting to write a post on this blog for quite some time now but life always gets in the way. This time it was my exams. Hopefully I will get free after the 4th of June and would get more time to write posts and do stuff which I love and care about. So enough with the rant now. I wanted to write about my latest endeavor. This month, with the help of two people (whom i had never met before), I got a chance to inspire 40 teens into taking their first step into programming. This whole event was planned and organized by one badass lady, Elena Sinel, who managed almost everything by herself.</description>
			</item>
			<item>
				<title>Python SortedList and SortedDict: Using sortedcontainers</title>
				<link>https://yasoob.me/2016/04/24/python-sorted-collections/</link>
				<pubDate>Sun, 24 Apr 2016 05:57:47 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2016/04/24/python-sorted-collections/</guid>
				<category>python</category>
				<description>Python has no built-in sorted list or dict. Learn how SortedList, SortedDict and SortedSet from sortedcontainers work and how they compare to OrderedDict.</description>
			</item>
			<item>
				<title>Intermediate Python is now Available in Chinese</title>
				<link>https://yasoob.me/2016/04/05/intermediate-python-is-now-available-in-chinese/</link>
				<pubDate>Tue, 05 Apr 2016 18:37:00 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2016/04/05/intermediate-python-is-now-available-in-chinese/</guid>
				<category>python</category>
				<description>Hi there folks! I am sure you all are fine. It’s been a long time since I wrote on this blog. I have some very important exams coming up due to which I was/am not able to provide the required time to this blog. I am happy to inform you that Intermediate Python is now available in Chinese! A small group of dedicated Chinese Pythonistas took it upon themselves to translate it. Another important bit of information/achivement is that the Chinese version crossed the 1000 stars mark on GitHub much more quickly than the English one.</description>
			</item>
			<item>
				<title>Learning Python For Data Science</title>
				<link>https://yasoob.me/2016/02/27/learning-python-for-data-science/</link>
				<pubDate>Sat, 27 Feb 2016 13:49:12 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2016/02/27/learning-python-for-data-science/</guid>
				<category>python</category>
				<description>For those of you who wish to begin learning Python for Data Science, here is a list of various resources that will get you up and running. Included are things like online tutorials and short interactive course, MOOCs, newsletters, books, useful tools and more. We decided to put this together so that you can begin learning Data Science with Python right of the bat, without having to spend hours surfing the web in search of resources. Please note that while we believe the list is comprehensive, it is by no means exhaustive. We probably have missed out on a couple of nice resources so feel free to mention them in the comments if you are so inclined. 🙂</description>
			</item>
			<item>
				<title>OCR on PDF files using Python</title>
				<link>https://yasoob.me/2016/02/25/ocr-on-pdf-files-using-python/</link>
				<pubDate>Wed, 24 Feb 2016 19:28:57 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2016/02/25/ocr-on-pdf-files-using-python/</guid>
				<category>python</category>
				<description>Hi there folks! You might have heard about OCR using Python. The most famous library out there is tesseract which is sponsored by Google. It is very easy to do OCR on an image. The issue arises when you want to do OCR over a PDF document. I am working on a project where I want to input PDF files, extract text from them and then add the text to the database. I had to search a lot before I stumbled over the final solution. So without wasting any time, lets begin.</description>
			</item>
			<item>
				<title>Implementing Email Sending Functionality in a Django App</title>
				<link>https://yasoob.me/2016/01/28/implementing-email-sending-functionality-in-a-django-app/</link>
				<pubDate>Wed, 27 Jan 2016 19:58:03 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2016/01/28/implementing-email-sending-functionality-in-a-django-app/</guid>
				<category>python</category>
				<description>Hi there folks! Recently I was doing a task for fossasia which required me to make a Django web app which allowed users to submit their email addresses and receive a welcome email in return. I was able to complete the project in a couple of hours. Most of the time was spent in making the UI look good. I am going to show you how you can easily make a similar app.</description>
			</item>
			<item>
				<title>My Google Code-In Experience with FOSSASIA</title>
				<link>https://yasoob.me/posts/codein-fossasia-experience/</link>
				<pubDate>Sat, 23 Jan 2016 00:36:22 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/codein-fossasia-experience/</guid>
				<category>personal</category>
				<description>Hi folks. In two days Google Code-in is going to end. Now is a good time to look back and reflect upon what I learned and achieved through this event. In this post I will try to share my experience regarding Google Code-in and especially FOSSASIA (this is the organization which I worked with). This was/is my first Code-in. I didn’t have any experience before so I was not sure what to expect. I was not aware of how this competition will turn out and what the organization/mentors’ behaviors will be. Well, I am more than happy to say that this competition fulfilled all my expectations and I thoroughly enjoyed it. What made it more enjoyable was the organization and mentors which I worked with!</description>
			</item>
			<item>
				<title>Scraping Euro Parliament Website Using Python</title>
				<link>https://yasoob.me/posts/scraping-euro-parliament/</link>
				<pubDate>Fri, 22 Jan 2016 00:53:21 -0400</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/posts/scraping-euro-parliament/</guid>
				<category>programming</category>
				<description>Hi guys! I hope you are fine. In this post I will show you how you can scrape public parliament data from the European Parliament website. In the European Parliament Members may pose written and oral questions to the European Institutions. Our task is to extract the answers to these questions. We will be using Python to accomplish this task. Let’s set up our directory and the app.py file. Setting up the directories</description>
			</item>
			<item>
				<title>Python for Scientists</title>
				<link>https://yasoob.me/2016/01/06/python-for-scientists/</link>
				<pubDate>Wed, 06 Jan 2016 17:58:39 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2016/01/06/python-for-scientists/</guid>
				<category>python</category>
				<description>This is a guest post by Brian David Hall from codenhance.com. He develops tutorials and resources to help scientists learn to code, including his latest Kickstarter project, Learn the Command Line … for Science! Spoiler alert: in this post, I will argue that Python is the best programming language for scientists to learn. Forget Perl, Java, FORTRAN, IDL, or whatever else they were pushing when you got your degree. This type of discussion is usually emotionally charged – many a flame war has been fought over programming languages. Feelings will get hurt. Heads will roll. But first …</description>
			</item>
			<item>
				<title>Looking for guest bloggers</title>
				<link>https://yasoob.me/2015/11/02/looking-for-guest-bloggers/</link>
				<pubDate>Mon, 02 Nov 2015 12:32:06 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/11/02/looking-for-guest-bloggers/</guid>
				<category>python</category>
				<category>Uncategorized</category>
				<description>Hi there folks! I am very busy now-a-days. You might already be aware of that due to the long pauses between posts. Therefore, I am searching for guest bloggers who would like to write about Python, it’s frameworks or literally anything interesting and informative related to Python. If you believe that you can do this then kindly drop me an email or post a comment below. I would love to hear from you. 🙂</description>
			</item>
			<item>
				<title>Nice tutorials I bumped into recently</title>
				<link>https://yasoob.me/2015/09/08/nice-tutorials-i-bumped-into-recently/</link>
				<pubDate>Mon, 07 Sep 2015 23:53:48 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/09/08/nice-tutorials-i-bumped-into-recently/</guid>
				<category>python</category>
				<description>Hi guys! I am in the USA right now. I am here to attend a Hackathon at the University of Michigan called MHacks 6. This is my first ever Hackathon so I am very excited. So now without wasting any time let’s get down to business. I recently came across a lot of nice tutorials which I believe might be useful for you guys. I am listing them below in no particular order:</description>
			</item>
			<item>
				<title>Free Python GUI development course</title>
				<link>https://yasoob.me/2015/08/25/free-python-gui-development-course/</link>
				<pubDate>Tue, 25 Aug 2015 07:51:38 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/08/25/free-python-gui-development-course/</guid>
				<category>Uncategorized</category>
				<description>Hi there folks! 👋 I have a good news for you. I have got two coupons for a video course on Udemy. The name of the course is “Learn Python GUI programming using Qt framework” and costs $79. It is taught by Bogdan Milanovich. I have taken this course previously when I was just getting started with GUI development in Python. At the time when I took this course it was incomplete but now it appears as if the instructor has completed the course.</description>
			</item>
			<item>
				<title>Intermediate Python Released!</title>
				<link>https://yasoob.me/2015/08/17/intermediate-python-released/</link>
				<pubDate>Mon, 17 Aug 2015 06:15:18 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/08/17/intermediate-python-released/</guid>
				<category>Uncategorized</category>
				<description>Hey folks! I am feeling really proud to announce the completion of my very own book. After a lot of hard-work and sheer determination this became possible and “Intermediate Python” saw the light of day. It will receive updates over time 🙂 Python is an amazing language with a strong and friendly community of programmers. However, there is a lack of documentation on what to learn after getting the basics of Python down your throat. Through this book I aim to solve this problem. I would give you bits of information about some interesting topics which you can further explore.</description>
			</item>
			<item>
				<title>My Story</title>
				<link>https://yasoob.me/2015/07/26/my-story/</link>
				<pubDate>Sun, 26 Jul 2015 12:48:41 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/07/26/my-story/</guid>
				<category>Uncategorized</category>
				<description>Hi guys. Recently my interview was published over at Mouse vs Python blog which is run by Mike. I am glad that I was able to become a part of Mike’s PyDev of the week series. This post is not going to be technical. I am going to use my time to clear up my mind through this post. Firstly, a lot of new programmers ask me how to learn Python. They want to reach my level of competence. They are much more fascinated by my skills when they come to know that I have learned it using the web and not any book or University course. Now I am going to jot down the steps which I follow to learn any new programming language.</description>
			</item>
			<item>
				<title>4 Command-line tools for more Python productivity</title>
				<link>https://yasoob.me/2015/06/21/4-command-line-tools-for-more-python-productivity/</link>
				<pubDate>Sat, 20 Jun 2015 21:02:19 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/06/21/4-command-line-tools-for-more-python-productivity/</guid>
				<category>python</category>
				<description>Hi there folks. In this post I would be sharing a couple of command-line tools which can help to increase your python productivity. These tools have helped me a lot and might help you as well! This post is inspired by another post. IPython IPython is the Python REPL on steroids. It has some really nice editions on top of the standard REPL. I am sure that if you use it once you will fall in love with it. The easiest way to install IPython is using pip:</description>
			</item>
			<item>
				<title>The Bite Python Newsletter is now official</title>
				<link>https://yasoob.me/2015/06/09/the-bite-python-newsletter-is-now-official/</link>
				<pubDate>Tue, 09 Jun 2015 08:17:12 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/06/09/the-bite-python-newsletter-is-now-official/</guid>
				<category>python</category>
				<description>Hi there guys! If you have been following my recent posts then you might know that I have started a newsletter. This newsletter covers everything related to Python which I come across every week. It was just a part time project. I used to send emails without any schedule. Now I have decided to give it the focus and energy which it demands. For that I have made a schedule. The newsletter will be sent out every Sunday if everything goes well. This makes it a weekly newsletter. It even has it’s own homepage now! I suggest you to signup for the newsletter as it would allow you to stay upto-date with the happenings in the Python community.</description>
			</item>
			<item>
				<title>Why should you use namedtuple instead of a tuple?</title>
				<link>https://yasoob.me/2015/06/06/why-should-you-use-namedtuple-instead-of-a-tuple/</link>
				<pubDate>Fri, 05 Jun 2015 19:21:31 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/06/06/why-should-you-use-namedtuple-instead-of-a-tuple/</guid>
				<category>python</category>
				<description>Hi there guys! You might already be acquainted with tuples. A tuple is a lightweight object type which allows to store a sequence of immutable Python objects. They are just like lists but have a few key differences. The major one is that unlike lists, you can not change a value in a tuple. In order to access the value in a tuple you use integer indexes like: man = (&amp;#39;Ali&amp;#39;, 30) print(man[0]) # Output: Ali Well, so now what are namedtuples? They turn tuples into convenient containers for simple tasks. With namedtuples you don’t have to use integer indexes for accessing members of a tuple. You can think of namedtuples like dictionaries but unlike dictionaries they are immutable.</description>
			</item>
			<item>
				<title>My very own book in the making</title>
				<link>https://yasoob.me/2015/04/29/my-very-own-book-in-the-making/</link>
				<pubDate>Tue, 28 Apr 2015 21:10:30 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/04/29/my-very-own-book-in-the-making/</guid>
				<category>Uncategorized</category>
				<description>Hi there folks. I am writing a book on Python tips, tricks and patterns. This will be a short book of nearly 100 pages. I have already written about 56 pages. I would be self-publishing it in July or August. I am pretty sure that you would love this book. Here is an unsorted list of content which I have already written about: args_and_kwargs debugging generators map_&amp;amp;_filter set_-_data_structure ternary_operators decorators global_&amp;amp;_return mutation __slots__magic virtual_environment collections enumerate object_introspection comprehensions exceptions lambdas one_liners for_-_else open_function targeting_python_2_3 coroutines function_caching Do note that this list of included content is subject to change as it is just a rough draft right now. I am planning on including a lot more topics.</description>
			</item>
			<item>
				<title>Books</title>
				<link>https://yasoob.me/books/</link>
				<pubDate>Mon, 20 Apr 2015 07:45:48 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/books/</guid>
				<description>I have listed the books in an ascending level of difficulty. Check them out and enjoy :). How to Think Like a Computer Scientist: Second Interactive Edition Author: B. Miller &amp;amp; D. Ranum Difficulty: Beginner This interactive book teaches you Python the interactive way, right in the browser. Learn Python The Hard Way Author: Zed A. Shaw Difficulty: Beginner Have you always wanted to learn how to code but never thought you could? Do you want to challenge your brain in a new way?</description>
			</item>
			<item>
				<title>Nifty Python tricks</title>
				<link>https://yasoob.me/2015/04/19/nifty-python-tricks/</link>
				<pubDate>Sun, 19 Apr 2015 05:04:08 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/04/19/nifty-python-tricks/</guid>
				<category>python</category>
				<description>Hi there folks. It’s been a long time since I last published a post. I have been busy. However in this post I am going to share some really informative tips and tricks which you might not have known about. So without wasting any time lets get straight to them: Enumerate Instead of doing: i = 0 for item in iterable: print i, item i += 1 We can do: for i, item in enumerate(iterable): print i, item Enumerate can also take a second argument. Here is an example:</description>
			</item>
			<item>
				<title>Month in review – Articles and news</title>
				<link>https://yasoob.me/2015/03/18/month-in-review-articles-and-news/</link>
				<pubDate>Wed, 18 Mar 2015 16:18:29 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/03/18/month-in-review-articles-and-news/</guid>
				<category>python</category>
				<description>Hi folks. In this post I am going to share some great articles which I recently got across. Apart from that I would also be sharing some news relating to Python. Articles Python Descriptors This IPython notebook was really helpful for me to learn about descriptors and properties in Python. It is topic which is greatly shadowed in a lot of Python books. This Notebook would be really beneficial for you if you want to grasp the concept in an effective and understandable manner.</description>
			</item>
			<item>
				<title>A guide to finding books in images using Python and OpenCV.</title>
				<link>https://yasoob.me/2015/03/11/a-guide-to-finding-books-in-images-using-python-and-opencv/</link>
				<pubDate>Wed, 11 Mar 2015 17:30:50 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/03/11/a-guide-to-finding-books-in-images-using-python-and-opencv/</guid>
				<category>python</category>
				<description>This is a guest post by Adrian Rosebrock from PyImageSearch.com, a blog all about computer vision, image processing, and building image search engines. I always tell people that if they want to learn to write well they need to do two things: Practice writing often. Read. A lot. It seems strange, doesn’t it? How reading often can dramatically improve your writing ability. But it’s absolutely true. Reading authors that like you can actually engrain their vernacular into your own writing style. And eventually, with enough practice, you can develop a style and voice of your own.</description>
			</item>
			<item>
				<title>Want suggestions for next post</title>
				<link>https://yasoob.me/2015/01/15/want-suggestions-for-next-post/</link>
				<pubDate>Thu, 15 Jan 2015 11:45:24 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2015/01/15/want-suggestions-for-next-post/</guid>
				<category>Uncategorized</category>
				<description>Hi there guys. I am Yasoob 🙂 As you know that writing quality tutorials take plenty of time so I was thinking that I should take your suggestion about the next article. These days I have been doing quite a lot of projects. Let me share the details of two of these projects. Extracting routes information from Google maps This project was not an ordinary project. As most of you know that Google maps provide an API to programmatically access it, there was a problem with it. The API was not providing complete routes information for Japan. And in this project I particularly wanted information regarding Japan.</description>
			</item>
			<item>
				<title>Best Python IDEs</title>
				<link>https://yasoob.me/2014/10/09/best-python-ides/</link>
				<pubDate>Thu, 09 Oct 2014 12:32:57 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/10/09/best-python-ides/</guid>
				<category>python</category>
				<description>Hi there guys. It is becoming really difficult for me to continue writing quality posts. If anyone of you would like to guest post then feel free to contact me. I get a lot of questions regarding the best IDE for Python so in this post I am going to list some of them for you so that you can stop asking and start working. Quality IDEs PyCharm Sublime Text NinjaIDE Wingware Komodo These are some of the IDEs I had the pleasure of working with.</description>
			</item>
			<item>
				<title>An intro to Deque module</title>
				<link>https://yasoob.me/2014/07/02/an-intro-to-deque-module/</link>
				<pubDate>Tue, 01 Jul 2014 20:40:04 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/07/02/an-intro-to-deque-module/</guid>
				<category>python</category>
				<description>Hi there folks. Recently I got to know about the Python deque module. It is a part of the collections library. It provides you with a double ended queue which means that you can append and delete elements from either side of the list. So without wasting any time lets begin. First of all you have to import the deque module from the collections library. This can be done by typing:</description>
			</item>
			<item>
				<title>[Book review] Python 101</title>
				<link>https://yasoob.me/2014/07/01/book-review-python-101/</link>
				<pubDate>Mon, 30 Jun 2014 19:03:04 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/07/01/book-review-python-101/</guid>
				<category>python</category>
				<description>Hi guys. So I am trying to get up to speed with my blog because lately I have not been posting a lot and due to this my blog is becoming stagnant. In this post I am going to write a book review. My friend Mike from The Mouse Vs The Python Blog recently wrote a book with the name of Python 101. He is a really talented blogger and programmer and I was waiting anxiously to read his brand new book, Python 101.</description>
			</item>
			<item>
				<title>EuroPython 2014 and me</title>
				<link>https://yasoob.me/2014/06/29/europython-2014-and-me/</link>
				<pubDate>Sun, 29 Jun 2014 18:51:09 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/06/29/europython-2014-and-me/</guid>
				<category>Uncategorized</category>
				<description>Hi guys! It’s been really long since I last posted on this blog. I was a little busy these past few days. A lot has been happening. I also got two job offers, although compelling but I still refused, so that I could focus on school for now. However, here I am, back to you guys! I would like to share some huge news with you. Guess what? I will be giving a presentation at EuroPython this year! Anyone of you who is planning to attend to EuroPython is invited to listen to my talk on the 22nd of July at 11 o’clock. I will be speaking about Webscraping in Python.</description>
			</item>
			<item>
				<title>Misconceptions about Skype local database</title>
				<link>https://yasoob.me/2014/04/19/misconceptions-about-skype-local-database/</link>
				<pubDate>Sat, 19 Apr 2014 12:11:25 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/04/19/misconceptions-about-skype-local-database/</guid>
				<category>python</category>
				<description>Hi there guys. Recently I wrote an article with the name of “I didn’t know Skype stores your data in a local database without a password!”. After publishing that article I got a lot of response from people like you and I came to know that it is not a vulnerability. It is so because the database is stored in the “appdata” directory which can only be accessed by the administrator which means that only an administrator account can open it. If you want someone else to use your computer just make a guest account which will restrict their level of access to the main directories only (this excludes the appdata directory). If you want to see your Skype logs then simply log in to your Skype account rather than going the complex way of accessing the local database.</description>
			</item>
			<item>
				<title>I didn’t know Skype stores your data in a local database without a password!</title>
				<link>https://yasoob.me/2014/04/19/i-didnt-know-skype-stores-your-data-in-a-local-database/</link>
				<pubDate>Fri, 18 Apr 2014 19:07:53 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/04/19/i-didnt-know-skype-stores-your-data-in-a-local-database/</guid>
				<category>python</category>
				<description>Hi guys! How are you? I hope you are doing great. Recently I came to know that Skype (video conferencing software) stores a local database with almost all information of a user who has logged on to skype from that computer. You might be thinking “So what? A lot of apps do that, right?”. Yes you are right. This is mostly done to increase speed. It’s like caching the content so that whenever you log in again to your account you don’t have to wait to see your contacts. It is fine but only to this extent.</description>
			</item>
			<item>
				<title>The Heartbleed bug</title>
				<link>https://yasoob.me/2014/04/12/the-heartbleed-bug/</link>
				<pubDate>Sat, 12 Apr 2014 08:11:44 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/04/12/the-heartbleed-bug/</guid>
				<category>python</category>
				<description>Hi guys! I haven’t been posting a lot recently. There are a couple of problems which have joined up and have kept me away from my computer. I will cover those reasons in the next post. So what this post is about? Are you a sys-admin or a web master? If you are one then the chances are that you have already heard of the heartbleed bug. But for those who are unaware of this, let me explain. On 7th April a bug was spotted in OpenSSL (Yes that is the same encryption used by companies like Google, Facebook, Yahoo! etc on their websites). This bug allowed any hacker to send some carefully crafted packets to a server using OpenSSL and the server responded with more data than it should. It is a very serious vulnerability.</description>
			</item>
			<item>
				<title>[Giveaway] 3 copies of Tkinter GUI Application Development Hotshot</title>
				<link>https://yasoob.me/2014/03/08/giveaway-3-copies-of-tkinter-gui-application-development-hotshot/</link>
				<pubDate>Sat, 08 Mar 2014 13:19:16 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/03/08/giveaway-3-copies-of-tkinter-gui-application-development-hotshot/</guid>
				<category>python</category>
				<description>Win Free Copies of new book - Tkinter GUI Application Development Hotshot Hi guys! Welcome back. As I recently told you that I will be holding a giveaway, the day has finally come. You will be pleased to know that I have teamed up with Packt Publishing to organize a Giveaway of the new book that I have reviewed - Tkinter GUI Application Development Hotshot And three lucky winners stand a chance to win 3 digital copies of this book. Keep reading to find out how you can be one of the Lucky Winners.</description>
			</item>
			<item>
				<title>Neckbeard Republic gone completely free!</title>
				<link>https://yasoob.me/2014/03/08/neckbeard-republic-gone-completely-free/</link>
				<pubDate>Fri, 07 Mar 2014 20:00:57 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/03/08/neckbeard-republic-gone-completely-free/</guid>
				<category>python</category>
				<description>So guys I have a good news for you. If you keep up with latest news regarding Python then you might have heard about Neckbeard Republic in the past. If you haven’t then let me tell you that Neckbeard Republic is a series of bite sized Python screen-casts created by the awesome Mahdi. It used to be paid. Only a few screen-casts were free. The paid ones required you to pay $9 monthly membership fee. However Mahdi recently announced that all those screen-casts are now free! Due to some personal problems he was not able to continue the awesome series of screen-casts so he just made them free for all of us.</description>
			</item>
			<item>
				<title>ImportError: No module named resource_rc</title>
				<link>https://yasoob.me/2014/03/08/importerror-no-module-named-resource_rc/</link>
				<pubDate>Fri, 07 Mar 2014 19:40:23 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/03/08/importerror-no-module-named-resource_rc/</guid>
				<category>python</category>
				<description>Hi there folks. How are you? Recently I was using Qt Designer to design a GUI for one of my apps. After doing all the designing I saved my ui file and ran pyuic4 over it. Everything worked fine and I had a Python ui file created in my system. But when I tried to run the Python ui file I was confronted with an error. It read something like this:</description>
			</item>
			<item>
				<title>Using py2exe the right way</title>
				<link>https://yasoob.me/2014/03/03/using-py2exe-the-right-way/</link>
				<pubDate>Mon, 03 Mar 2014 11:58:30 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/03/03/using-py2exe-the-right-way/</guid>
				<category>python</category>
				<description>Hi guys how are you? I hope all of you are fine. Recently I was working on a PyQt project. The project was youtube-dl-GUI. It is a GUI for the ever popular youtube-dl project. After writing all the code I decided to make an exe in order to ease the deployment of my project on windows. For this purpose I decided to use py2exe which suited best to my needs. However it is necessary to know that py2exe is not the only Python to exe compiler out there. Some of the other popular Python exe makers out there are pyinstaller and cx_freeze.</description>
			</item>
			<item>
				<title>[Book review] Tkinter GUI Application Development HOTSHOT</title>
				<link>https://yasoob.me/2014/02/22/book-review-tkinter-gui/</link>
				<pubDate>Sat, 22 Feb 2014 18:49:12 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/02/22/book-review-tkinter-gui/</guid>
				<category>python</category>
				<description>Hi guys. You might have noticed that I am not so active. The reason is that I am developing a couple of my projects as a hobby. Due to that I didn’t have a lot of time to blog. Nevertheless I will continue to write interesting posts once or twice a week. So what this post is about? Well recently I was contacted by Packt Publishers to write a book review. The book was “Tkinter GUI Application Development HOTSHOT” and is recently published. As you probably know that I am not that much proefficient in GUIs and prefer CLIs so this book gave me a good chance to brush up my skills on GUI development. Here is a quick summary for those who want to get a quick overview.</description>
			</item>
			<item>
				<title>If you could change something in Python what would it be?</title>
				<link>https://yasoob.me/2014/02/08/if-you-could-change-something-in-python-what-would-it-be/</link>
				<pubDate>Sat, 08 Feb 2014 18:22:41 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/02/08/if-you-could-change-something-in-python-what-would-it-be/</guid>
				<category>python</category>
				<description>Hi there guys. Recently I posted a question on Reddit. The question was that if you could change something in Python what would it be? I got some really interesting answers from other programmers. Here are some of the top answers till now. Make building a stand alone executable part of the spec. The two main projects that do it are hacks the namespaces in the datetime module. its really annoying to have to remember if I used import datetime # vs. from datetime import datetime optional static typing. as in i would add the ability to statically type things in python, but not make it mandatory. “slef” should be a universal alias for self Get rid of the GIL A good, consistent, Pythonic, cross-platform, batteries-included graphic library. Tkinter is the closest, but the execution loop makes it challenging to do advanced stuff, and the adherence to Tk makes it challenging for a beginner to do basic stuff.I appreciate it’s not easy to design and write such a thing, but I can still wish. Compile to native codeCombine 2 and 3 into one version moving forward If you would like to receive such posts as well as other interesting tutorials then do follow my blog. That’s it for now. Stay tuned for my next post!</description>
			</item>
			<item>
				<title>Free Python books</title>
				<link>https://yasoob.me/2014/02/04/free-python-books/</link>
				<pubDate>Mon, 03 Feb 2014 19:02:12 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/02/04/free-python-books/</guid>
				<category>python</category>
				<description>Hi there guys. I am back again with yet another useful post. This one is going to be about free Python books. Most new Python programmers don’t realise that there are great Python books out there for free and due to their lack of knowledge they pay for expensive ones. Most of these books have the same high quality material which you would expect from a paid book. So without wasting any time let me list them here.</description>
			</item>
			<item>
				<title>Python 101: Writing a cleanup script</title>
				<link>https://yasoob.me/2014/01/23/python-101-writing-a-cleanup-script/</link>
				<pubDate>Thu, 23 Jan 2014 16:58:47 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/01/23/python-101-writing-a-cleanup-script/</guid>
				<category>python</category>
				<description>So hi there guys! I hope you are fine. So what is in this post? Today we will be writing a cleanup script. The idea for this post came from Mike Driscol who recently wrote a very useful post about writing a cleanup script in python. So how is my post different from his post? In my post I will be using path.py. When I used path.py for the first time I just fell in love with it.</description>
			</item>
			<item>
				<title>The open function explained</title>
				<link>https://yasoob.me/2014/01/15/the-open-function-explained/</link>
				<pubDate>Wed, 15 Jan 2014 13:19:30 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/01/15/the-open-function-explained/</guid>
				<category>python</category>
				<description>This is a guest post by Philipp. open opens a file. Pretty simple, eh? Most of the time, we see it being used like this: f = open(&amp;#39;photo.jpg&amp;#39;, &amp;#39;r+&amp;#39;) jpgdata = f.read() f.close() The reason I am writing this article is that most of the time, I see open used like this: There are three errors in the above code. Can you spot them all? If not, read on. By the end of this article, you’ll know what’s wrong in the above code, and, more importantly, be able to avoid these mistakes in your own code.</description>
			</item>
			<item>
				<title>Future Plans and logit-bin</title>
				<link>https://yasoob.me/2014/01/04/future-plans-and-logit-bin/</link>
				<pubDate>Fri, 03 Jan 2014 23:00:35 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2014/01/04/future-plans-and-logit-bin/</guid>
				<category>Uncategorized</category>
				<description>Oh hi there guys. Its been really a long time since I wrote my last post. Don’t think that I forgot about you guys. I was just super busy last couple of days. Firstly, it was my exams. But I am happy to tell you guys that they went well 😄 Secondly I had a competition coming up so I remained a lot busy. So what about the next post. The next post which is currently in draft form is “writing cleanup script in python”. The next post will include writing scripts that do house keeping tasks for you. I will be focusing on deleting files based on specific criteria e.g based on last modified time.</description>
			</item>
			<item>
				<title>Python decorators finally demystified</title>
				<link>https://yasoob.me/2013/12/05/python-decorators-finally-demystified/</link>
				<pubDate>Thu, 05 Dec 2013 16:09:59 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/12/05/python-decorators-finally-demystified/</guid>
				<category>python</category>
				<description>Hi there guys! I hope all of you are fine and doing well. Recently I was hanging out on a python related IRC where I got a request from someone to write an article on decorators in Python. It is perhaps one of the most difficult concept to grasp. So as usual without wasting anytime let get on with it. Everything in python is an object (Functions too!): First of all let’s understand functions in python:</description>
			</item>
			<item>
				<title>Kivy 101: How to Use BoxLayouts</title>
				<link>https://yasoob.me/2013/12/02/kivy-101-how-to-use-boxlayouts/</link>
				<pubDate>Mon, 02 Dec 2013 18:34:11 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/12/02/kivy-101-how-to-use-boxlayouts/</guid>
				<category>python</category>
				<description>This was a guest post by Mike Driscoll. Recently I’ve started learning about Kivy, a Python Natural User Interface (NUI) toolkit. As I understand it, Kivy is kind of a spiritual successor to pyMT, which you can read more about here. In this article, we will be learning how Kivy handles layout management. While you can position widgets using x/y coordinates, in every GUI toolkit I’ve used, it’s almost always better to use some kind of layout management that the toolkit provides. This allows the widgets to resize and move appropriately as the user changes the window’s size. In Kivy, these things Layouts. If you’ve used wxPython, they are analogous to wxPython’s sizers.</description>
			</item>
			<item>
				<title>Reverse engineering myspace</title>
				<link>https://yasoob.me/2013/11/23/reverse-engineering-myspace/</link>
				<pubDate>Fri, 22 Nov 2013 20:44:01 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/11/23/reverse-engineering-myspace/</guid>
				<category>python</category>
				<description>Hi guys! In todays post we will be looking into myspace.com and check whether it is possible to download songs with python or not. If it is possible then we will make a python script which will assist us in downloading the songs. Tools python - I am using py2k browser - I am using chrome rtmpdump &amp;amp; rtmpsrv internet connection So lets start. Lets go to myspace:</description>
			</item>
			<item>
				<title>Introduction to unittest</title>
				<link>https://yasoob.me/2013/11/15/introduction-to-unittest/</link>
				<pubDate>Fri, 15 Nov 2013 18:04:58 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/11/15/introduction-to-unittest/</guid>
				<category>Uncategorized</category>
				<description>Hi there folks. I recently thought that I have not written even a single post about testing in python. Testing is one of the most important part of any language. In this post I am going to share some information about unittest with you. So what exactly is unittest? You might have heard about it on StackOverflow or some other forum. It is a testing framework for python just like Junit for Java. It comes pre-installed with python from 2.1. It is easy to use.</description>
			</item>
			<item>
				<title>Recent posts by Guido Van Rossum</title>
				<link>https://yasoob.me/2013/11/15/recent-posts-by-guido-van-rossum/</link>
				<pubDate>Thu, 14 Nov 2013 19:13:06 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/11/15/recent-posts-by-guido-van-rossum/</guid>
				<category>Uncategorized</category>
				<description>Hi there friends. If you are a python programmer then there is not a single chance that you don’t know Guido. Everyone knows him in the python community. However for those who don’t know about him let me introduce him to you. He is the creator of python and is known as BDFL. Now a days he works at dropbox and previously he used to work at google. In this post I am going to share some of his recent posts with you. They are very informative and I suggest that you take a look at them.</description>
			</item>
			<item>
				<title>New Python books</title>
				<link>https://yasoob.me/2013/11/13/new-python-books/</link>
				<pubDate>Wed, 13 Nov 2013 18:35:41 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/11/13/new-python-books/</guid>
				<category>Uncategorized</category>
				<description>Hi everyone! Welcome back to yet another article. This one is going to be short. In this post I will be sharing two new books which have recently come out. So without wasting any time lets look at them. Tkinter GUI Application Development Hotshot Its been a long time since we saw a new Tkinter book out there. This book has received some good critics by the professional python programmers. According to the overview given on the website you will :</description>
			</item>
			<item>
				<title>Some Python projects worth looking at</title>
				<link>https://yasoob.me/2013/11/13/some-python-projects-worth-looking-at/</link>
				<pubDate>Wed, 13 Nov 2013 18:30:57 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/11/13/some-python-projects-worth-looking-at/</guid>
				<category>python</category>
				<description>Hi there guys. So a lot has happened while I was away. It has been only a few weeks and a whole ton of great python project have emerged. In this post I will share a list of some of the excellent projects I saw in the past few days. So lets take a look at them without wasting any more time.</description>
			</item>
			<item>
				<title>PyDev 3.0 Released</title>
				<link>https://yasoob.me/2013/11/13/pydev-3-0-released/</link>
				<pubDate>Wed, 13 Nov 2013 17:18:49 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/11/13/pydev-3-0-released/</guid>
				<category>python</category>
				<description>Hi there folks. Its been a long time since I posted here. That was because my studies were giving me some problems. So no worrys because the problems are all resolved and I am back with yet another news. So what is PyDev ? If you have been coding python scripts with eclipse (it’s an IDE) then the chances are that you know what PyDev is</description>
			</item>
			<item>
				<title>Python 3.4 to be equipped with pip by default</title>
				<link>https://yasoob.me/2013/10/22/python-3-4-to-be-equipped-with-pip-by-default/</link>
				<pubDate>Tue, 22 Oct 2013 16:59:27 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/10/22/python-3-4-to-be-equipped-with-pip-by-default/</guid>
				<category>python</category>
				<description>Hi there Pythonistas. A news has arrived that pip will be available by default with python 3.4. PEP 453 which was “Explicit bootstrapping of pip in Python installations” has been accepted. Python 3.4 which has entered into the beta phase after the release of final alpha will have pip by default. If you are new to python then you might be wondering what pip is ? Pip is a tool for installing and managing Python packages. Previously easy_install has been the most used package manager. </description>
			</item>
			<item>
				<title>PyCharm 3.0 Community Edition</title>
				<link>https://yasoob.me/2013/10/22/pycharm-3-0-community-edition/</link>
				<pubDate>Tue, 22 Oct 2013 16:43:23 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/10/22/pycharm-3-0-community-edition/</guid>
				<category>python</category>
				<description>The makers of the hugely popular Python IDE PyCharm recently announced a community edition of their Python IDE. JetBrains announced that they will be offering a community Edition of PyCharm however it will have some stripped down features for example it will not have builtin support for pyramid etc. However the news for a Community version of PyCharm became hot in the python community recently because PyCharm is currently the best IDE available for Python. This community edition has been out for quite some time now and has already been downloaded by a lot of developers. Today the Source code of this IDE was also open sourced by JetBrains. The source code is available on GitHub . This IDE has a lot of cool features. Here are a few of the features of the community version:</description>
			</item>
			<item>
				<title>Python News 13 Oct 2013</title>
				<link>https://yasoob.me/2013/10/14/python-news-13-oct-2013/</link>
				<pubDate>Sun, 13 Oct 2013 20:59:27 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/10/14/python-news-13-oct-2013/</guid>
				<category>python</category>
				<description>Hi folks in this post i am going to share with you news from the python world. This is like a roundup of monthly news. Latest News NHS drops Oracle for Python, Riak, Redis, RabbitMQ, Tornado, Flask and more The UK government’s quest to get public services to use more open source technologies seems to be taking hold, judging by the revamp of the NHS’s very large Spine service. Microsoft donates $100,000 to the IPython team Microsoft donates $100,000 to the IPython team for the continued development of IPython.</description>
			</item>
			<item>
				<title>All About Decorators in Python</title>
				<link>https://yasoob.me/2013/10/10/all-about-decorators-in-python/</link>
				<pubDate>Thu, 10 Oct 2013 16:18:07 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/10/10/all-about-decorators-in-python/</guid>
				<category>python</category>
				<description>Hi there fellas. This is an answer posted on stackoverflow by e-satis. The original link to the answer is given at the end. No credit goes to me. All of the credit goes to the original author. This answer is posted just because most of us are unaware of how decorators work in python and this answer solves that problem beautifully. Python’s functions are objects To understand decorators, you must first understand that functions are objects in Python. This has important consequences. Let’s see why with a simple example :</description>
			</item>
			<item>
				<title>The Python yield keyword explained</title>
				<link>https://yasoob.me/2013/09/29/the-python-yield-keyword-explained/</link>
				<pubDate>Sun, 29 Sep 2013 16:34:22 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/09/29/the-python-yield-keyword-explained/</guid>
				<category>python</category>
				<description>Hi there folks. Again welcome to yet another useful tutorial. This is again a stackoverflow answer. This one is related to the Python yield keyword. It explains you what yield, generators and iterables are. So without wasting any time lets continue with the answer. To understand what yield does, you must understand what generators are. And before generators come iterables. Iterables When you create a list, you can read its items one by one, and it’s called iteration:</description>
			</item>
			<item>
				<title>Python Quick Reference v2.7</title>
				<link>https://yasoob.me/2013/09/26/python-quick-ref-v2-7/</link>
				<pubDate>Thu, 26 Sep 2013 14:24:21 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/09/26/python-quick-ref-v2-7/</guid>
				<category>python</category>
				<description>Hi there everyone. We all have experienced that time when we say “what was that function called?”, “was it called get_attr() or post_attr()?” Recently I came across a wonderful Python Quick Reference for version 2.7. It contains some useful information. I hope you will find it very useful just like me. So here is the link. Go forward and get it. You will not regret it. Do tell me in the comments that whether you like it or not or do you want something to be added to it. I would really love to hear your response. Let me make it clear as well that I am not the author of this great reference guide.</description>
			</item>
			<item>
				<title>All about the metaclasses in Python!</title>
				<link>https://yasoob.me/2013/09/20/all-about-the-metaclasses-in-python/</link>
				<pubDate>Fri, 20 Sep 2013 14:41:26 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/09/20/all-about-the-metaclasses-in-python/</guid>
				<category>python</category>
				<description>Hi there pythonistas. Recently I was searching about metaclasses in Python and came across a very good explanation about metaclasses on stackoverflow. I found the answer really helpful so I think you should read it as well. Who knows when you might find something useful in there. Disclaimer: very long post. Classes as objects Before understanding metaclasses, you need to master classes in Python. And Python has a very peculiar idea of what classes are, borrowed from the Smalltalk language.</description>
			</item>
			<item>
				<title>Making a Reddit &#43; twitter Bot</title>
				<link>https://yasoob.me/2013/09/14/making-a-reddit-twitter-bot/</link>
				<pubDate>Sat, 14 Sep 2013 14:45:49 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/09/14/making-a-reddit-twitter-bot/</guid>
				<category>python</category>
				<description>Hi there pythonistas. I hope you are all fine. In this post I am going to teach you how we can make a Reddit + Twitter bot. What this bot will do is that it will copy post titles and url from any subreddit that you want and then it will post them to twitter keeping the 140 characters length in mind. Firstly let me tell you what Reddit is. Reddit is a social link sharing site where good links are upvoted and bad links are down voted. So lets start.</description>
			</item>
			<item>
				<title>A surprize for you</title>
				<link>https://yasoob.me/2013/09/09/a-surprize-for-you/</link>
				<pubDate>Mon, 09 Sep 2013 14:10:01 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/09/09/a-surprize-for-you/</guid>
				<category>Uncategorized</category>
				<description>Hi there pythonistas. You might have noticed that I haven’t been active much on this blog. There’s a reason for that. I was preparing a PyCon talk. Yes I was really preparing a PyCon talk. The title of the talk is “Web Scraping in Python”. I have submitted the proposal and now I am waiting for it’s acceptance (or rejection). Do pray for it’s acceptance and after that you will be able to see me in Montreal next year 😉. I will keep you guys updated.</description>
			</item>
			<item>
				<title>Making a twitter bot in python</title>
				<link>https://yasoob.me/2013/09/04/increase-your-twitter-followers/</link>
				<pubDate>Wed, 04 Sep 2013 16:53:13 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/09/04/increase-your-twitter-followers/</guid>
				<category>python</category>
				<description>Hi there guys. I hope you are fine. In this post I am going to tell you how you can make a twitter auto favouriter or a.k.a Twitter Bot. I am not going to make a twitter follower as it will get you banned quickly if you use it a lot. This post is going to help you to increase your twitter followers organically. By organically I mean that your followers will be those who really want to listen to your content. You can either use services on the web to increase your followers inorganically or else you can use this script 😉</description>
			</item>
			<item>
				<title>Python Resources</title>
				<link>https://yasoob.me/python-resources/</link>
				<pubDate>Sun, 01 Sep 2013 10:40:59 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/python-resources/</guid>
				<description>Contents Beginner’s Delight Resources for Women Why Python? Style Guide and Idioms Dictionary Decorators Generators Coroutines Iterators Yield Context Managers Unicode Networking Metaclasses Documentation Sphinx Debugging Logging Testing Environments and Environment Management Profiling Packaging Deployment Fabric Warts and Gotchas Web Frameworks Flask Web2Py Django Bottle Tornado Web Servers API and Web Services Scraping Mobile Development Kivy Google Glass Resources Libraries GUI Programming Android SL4A WSGI Databases SQLAlchemy Data Mining Data Analysis Pandas IPython Notebooks Design Patterns Concurrency Patterns Concurrency and Distributed Systems Functional Programming Python 2 vs Python 3 Porting to Python 3 Books Free Paid Online Courses and Challenges Discussions Conferences and Events Videos Editors and IDE’s for Python programming Big Data Curated Python resources from other websites Newsletters Miscellaneous Beginner’s Delight Beginner’s guide to Python The Hitchhiker’s guide to Python Learn Python the hard way Learn Python Google’s Python class Python tracks at Codecademy Python Monk Python for Beginners Best way to learn python Python Tips, tools and resources Python Koans: Learn Python through TDD LearnStreet Python course Beginner projects for a python newbie Learn X in Y minutes – Python Python Practice book Python tools and software Facts and myths about Python names and values _args and *_kwargs in python explained In Python, it’s all about the attributes Common newbie mistakes in Python- Part 1 Common newbie mistakes in Python- Part 2 PySchools Some cool Python Tricks if x and if x is not None Better Python APIs Declaring dependencies in Python Storing and Loading Data with JSON – Serialization/deserialization A Guide to Python’s Magic Methods Efficient String Concatenation in Python Be Pythonic: init.py Building an open-source Python application the right way Python progression path – From apprentice to guru Tutorialspoint python tutorial Python Importing Python’s super() considered super! No Naked Excepts Supercharge Your Python Developers Anti-Patterns in Python Programming Resources for Women Pyladies Diversity in Python Community Mailing List Django Girls Pystar Geek Feminism Python Posts Tarah Wheeler Van Vlack Videos Why Python? Python Success Stories Why Python – Slideshare 5 Reasons Why You Should Learn Python Programming 10 Reasons Python Rocks for Research (And a Few Reasons it Doesn’t) Why such popularity with Python? Why was Python’s popularity so sudden? Why Python? How Python became the language of choice for data science Style Guide and Idioms PEP 8 – Style Guide for Python Code Code Like a Pythonista: Idiomatic Python Google Python Style Guide Python Idioms and Efficiency How not to write Python code Docstring Conventions Dictionary Python hash, id and dictionary order Notes on dictionary implementation Python: The Dictionary Playbook Decorators Understanding Python Decorators in 12 easy steps Common uses of Python decorators – Quora Common uses of Python decorators – Stack Overflow Python Decorators Decorators I: Introduction to Python Decorators Decorators and annotations The dark side of decorators Thinking out aloud: Python decorators Using Python decorators for registering callbacks Meta-matters: Using decorators for better Python programming How can I make a chain of function decorators in Python? The Python Decorator Library Improve Your Python: Decorators Explained Painless Decorators Generators Improve Your Python: ‘yield’ and Generators Explained Generator Tricks for Systems Programmers Delegating to a Subgenerator in Python 3 Coroutines A Curious Course on Coroutines and Concurrency Iterators Understanding Iterators and Iterables Yield Python yield keyword explained Context Managers Understanding Python’s with statement The Python “with” Statement by Example Unicode Explain Unicode like I’m five years old Unicode Pain Python encodings and Unicode The Updated Guide to Unicode on Python More About Unicode in Python 2 and 3 Unicode in Python: Common Pitfalls Networking An intro to Python socket network programming Metaclasses A primer on python metaclasses What is a metaclass in Python ? Yet Another Python Metaclass tutorial Improve Your Python: Metaclasses and Dynamic Classes With Type Metaprogramming in Python Documentation Documentation is King Make your open source project documentation suck less Python Documentation Network Writing great documentation Sphinx Quick Sphinx documentation for Python Environments and Environment Management Virtualenv – The official documentation Virtual Environments — The Hitchhiker’s Guide to Python Virtualenv Tutorial A Primer on virtualenv How to use Python virtualenv Making Virtualenv play nice with Git Extension to Virtualenv VirtualEnv Burrito = virtualenv + virtualenvwrapper Virtualenv Tips Debugging Debugging Tools in Python Debugging Python Like a Boss Logging Sentry – realtime event logging and aggregation platform Testing Nose Introduction Unittest Introduction How To Use Coverage.py With Unittest An Extended Introduction to the nose Unit Testing Framework Test strategies for your Python projects Improve Your Python: Understanding Unit Testing An Introduction to Mocking in Python Python Mock Library Comparison Profiling A guide to analyzing Python performance Profiling Python Like a Boss Packaging The Hitchhiker’s Guide to Packaging Sharing Your Labor of Love: PyPI Quick And Dirty Open Sourcing a Python Project the Right Way 5 tips for packaging your Python projects AOSA: Python Packaging The Package Dependency Blues 5 Simple Rules For Building Great Python Packages Unofficial Windows Binaries for Python Extension Packages Py2app: Standalone Mac OS X applications PyInstaller: Stand-alone executables, under Windows, Linux, Mac OS X, Solaris and AIX setup.py tricks Deployment Solid Python Deployments for Everybody Fabric Using Fabric in a development environment Capture output from parallel execution with Fabric Warts and Gotchas Python 2.x gotcha’s and landmines Python Warts Python Gotchas Common Pitfalls in Python Web Python and Realtime Web A Python guide to handling HTTP request failures Frameworks Django vs Flask vs Pyramid: Choosing a Python Web Framework Flask Flask Mega Tutorial Series Designing a RESTful API with Python and Flask Building websites in Python with Flask How I structure my Flask apps Designing a RESTful API using Flask-RESTful Rapid Web Prototyping with Lightweight Tools Build a Simple, Static, Markdown-Powered Blog with Flask How to Build an API with Python and Flask Create a Simple Music Streaming App with Flask Adding full-text search to the flask note-taking app Kickstarting Flask on Ubuntu – Setup and Deployment OAuth Authentication with Flask Building a blog using Flask and AngularJS A repository of Flask resources Web2Py Building a Twitter clone in Web2Py Django The official Django documentation Getting started with Django Starting a Django 1.6 Project the Right Way Building a hacker news clone in Django Djen of Django Deploying Django Django by Example Django From the Ground Up (video tutorials) Tango with Django Django Screencasts Let’s TDD a Simple App in Django Django runserver and stunnel for testing HTTPS Scaling database with Django and HAProxy Classy Class-Based Views Django models, encapsulation and data integrity 11 Things I Wish I Knew About Django Development Before I Started My Company Build a Shopify App in 15 minutes with Django A repository of must-watch videos about Django Bottle Developing with Bottle- Part 1 Tornado Tornado official documentation Fastest database for Tornado Web Servers A Comparison of Web Servers for Python Based Web Applications Setting Up a Rock Solid Python Development Web Server API and Web Services How to access various web services in python Glassdoor API Scraping Web Scraping with BeautifulSoup Web Scraping 101 with Python Web Scraping with Scrapy Framework How to automatically search and download torrents with Python and Scrapy Mobile Development Kivy Creating an app in Kivy Google Glass Resources The official Python Quick Start for Google Glass Libraries glass.py Create python web applications for Google Glass Image Processing Python Image Library – Examples GUI Programming Python.org GUI Overview Page PyQt Tutorial Standalone executable for PyQt4 on Windows Kivy GUI for cross-platform applications EffBot.org Introduction to Tkinter Pytkgen: JSON to Tkinter GUI Generator Intro to programming with Python and Tkinter Android SL4A Making the Physics Gizmo app for Android using SL4A WSGI Getting started with WSGI WSGI Basics Databases SQLAlchemy SQLAlchemy SQLAlchemy and you Essential SQLAlchemy Tips and Techniques 10 common stumbling blocks for SQLAlchemy newbies Data Mining Linux system mining using Python Data Analysis Practical Data Science in Python Pandas A 10 min intro to Pandas Pandas and Python: Top 10 Learn Pandas Faster Data Processing in Python IPython Notebooks A Gallery of Interesting IPython Notebooks A collection of not-so-obvious Python stuff you should know! Statistical Natural Language Processing in Python | How To Do Things With Words. And Counters. Analysis of World Bank Fertility Rate Data With Statsmodels PCA Modeling the Last Flight of MH370 with a Markov Chain Monte Carlo Method Differential Equations in Data Science Stegotons: solitary waves arising in non-dispersive periodic media The Traveling Salesperson Problem Scientific Computing with Python Gaussian Blur Understanding the FFT Algorithm lifelines: Survival Analysis in Python Economics Simulation An Introduction to Bayesian Methods for Multilevel Modeling The Floods of the Nile Animal Foraging and the Evolution of Goal-Directed Cognition Wikipedia data scraping functions Python for Geosciences Media Signal Processing Digital Filters Image Filtering Audio Features Feature Detection and Matching for Images Gestures Design Patterns Python Best Practice Patterns by Vladimir Keleshev 28 Design Patterns in Python and Several Other Languages Factory Pattern In Python Concurrency Patterns Wasp’s Nest: The Read-Copy-Update Pattern In Python Concurrency and Distributed Systems Gevent and ZeroMQ Celery: Distributed Task Queue Gevent for the working Python developer Functional Programming Recursion Explained with the Flood Fill Algorithm Functional Programming in Python Python 2 vs 3 Python 2 or 3 ? Python 3 Q &amp;amp; A About Python 3 Let’s talk about Python 3.0 Pros and Cons about Python 3 Porting to Python 3 How to support both Python 2 and 3 How CherryPy supports Python 2 and 3 Porting to Python 3 – The Book Site Books Free Free Programming Books – Python Python Programming – Free Computer Books Some free books on Python Invent with Python Think Python Byte of Python Snake Wrangling for Kids Data Structures and Algorithms with Object-Oriented Design Patterns in Python Python programming on wikibooks Dive Into Python 3 Programming Computer Vision with Python Python for you and me Program Arcade Games With Python And Pygame Paid Some list of paid books on python Porting to Python 3 – The Book Site Online Courses and Challenges A Gentle Introduction to Programming Using Python Python Challenges Project Euler Discussions What’s your favorite programming language? What is your primary programming language? StackOverflow – Python beyond the basics StackOverflow – Python progression path from apprentice to guru StackOverflow – Zen of Python StackOverflow – Hidden Features of Python Conferences and events Official PyCon website Lanyrd – Python Conference and Events Meetup.com – Python Meetup Groups Videos Guido Van Rossum on the history of Python PyVideo Khan Academy – Introduction to programming and computer science using Python What are some “must-watch” Python videos ? Lanyrd – Python Videos Python Videos, Tutorials and Screencasts at ShowMeDo Talks by Brandon Rhodes A Billion Rows per Second: Metaprogramming Python for Big Data The newboston site tutorial Python Programming Tutorials Editors and IDE’s for Python programming Setting up Sublime Text for Python Development Sublime Text 2 Love by Kenneth Reitz Sublime Text 2 tips for Python and web developers PyCharm Geany Geany with pylint PyDev Ninja-IDE Emacs setup for python development environment Emacs for python BigData Mind map of Python for Big Data Curated Python resources from other websites Python Resources (All) – Codesters.org Newsletters Pycoder’s Python Weekly Miscellaneous Good to great Python reads How to Create Barcodes in Your PDFs with Python What are some good Python interview questions ? Python innards introduction Projects – A list of practical projects More Python Tutorials Developer Tools in Python The Best of Python in 2013 Top Projects of 2013 Advanced Regular Expression Tips and Techniques Advanced Data Structures in Python Simple Sudoku solver in python Looking Inside Dropbox – Security whitepaper Why sorting an array makes a Python loop faster Python Integer object implementation The history of Python – Blog The ever useful and neat subprocess module Hidden Features in Python Python module of the week Become a programmer Python tutor Best developer blogs about python – Quora Python blogs -Stackoverflow Abstracting Control Flow Python Algorithm Visualizations done in Python running in the browser Solving Every Sudoku Puzzle IHeartPy! source: pycrumbs github</description>
			</item>
			<item>
				<title>Best Python Resources for Beginners and Professionals</title>
				<link>https://yasoob.me/2013/09/01/best-python-resources/</link>
				<pubDate>Sun, 01 Sep 2013 10:37:31 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/09/01/best-python-resources/</guid>
				<category>python</category>
				<description>Beginner’s Delight Beginner’s guide to Python The Hitchhiker’s guide to Python Learn Python the hard way Google’s Python class Python for Beginners Python tracks at Codecademy Python Monk Best way to learn python Python Tips, tools and resources Python Koans: Learn Python through TDD LearnStreet Python course Beginner projects for a python newbie Learn X in Y minutes – Python Python Practice book Facts and myths about Python names and values _args and *_kwargs in python explained Common newbie mistakes in Python- Part 1 Common newbie mistakes in Python- Part 2 PySchools Some cool Python Tricks http://blog.amir.rachum.com/post/30176371115/you-cant-handle-the-truth Better Python APIs Python Gotchas Declaring dependencies in Python Style Guide and Idioms PEP 8 – Style Guide for Python Code Code Like a Pythonista: Idiomatic Python Dictionary Python hash, id and dictionary order Notes on dictionary implementation Decorators Understanding Python Decorators in 12 easy steps Common uses of Python decorators – Quora Common uses of Python decorators – Stack Overflow Python Decorators Decorators I: Introduction to Python Decorators Decorators and annotations The dark side of decorators Thinking out aloud: Python decorators Using Python decorators for registering callbacks Meta-matters: Using decorators for better Python programming Generators Generator Tricks for Systems Programmers Yield Python yield keyword explained Context Managers Understanding Python’s with statement Unicode Explain Unicode like I’m five years old Unicode Pain Python encodings and Unicode The Updated Guide to Unicode on Python Metaclasses A primer on python metaclasses What is a metaclass in Python ? Yet Another Python Metaclass tutorial Documentation Documentation is King Make your open source project documentation suck less Sphinx Quick Sphinx documentation for Python Debugging Debugging Tools in Python Testing Nose Introduction Unittest Introduction How To Use Coverage.py With Unittest Profiling A guide to analyzing Python performance Packaging Sharing Your Labor of Love: PyPI Quick And Dirty Open Sourcing a Python Project the Right Way Deployment Fabric Using Fabric in a development environment Web Python and Realtime Web Frameworks Flask Flask Mega Tutorial Series Designing a RESTful API with Python and Flask Building websites in Python with Flask How I structure my Flask apps Designing a RESTful API using Flask-RESTful Rapid Web Prototyping with Lightweight Tools Web2Py Building a Twitter clone in Web2Py Django The official Django documentation Getting started with Django Building a hacker news clone in Django Django Architecture: The good, bad and ugly http://www.lightbird.net/dbe/ http://showmedo.com/videotutorials/series?name=PPN7NA155 Bottle Developing with Bottle- Part 1 API and Web Services How to access various web services in python Scraping Web Scraping with BeautifulSoup Web Scraping 101 with Python How to automatically search and download torrents with Python and Scrapy Mobile Development Kivy Creating an app in Kivy Image Processing http://www.riisen.dk/dop/pil.html WSGI Getting started with WSGI WSGI Basics Databases SQLAlchemy http://www.aosabook.org/en/sqlalchemy.html http://lucumr.pocoo.org/2011/7/19/sqlachemy-and-you/ Data Mining Linux system mining using Python Data Analysis Pandas A 10 min intro to Pandas http://manishamde.github.io/blog/2013/03/07/pandas-and-python-top-10/ Design Patterns Python Best Practice Patterns by Vladimir Keleshev Concurrency Patterns Wasps Nest Pattern Wasp’s Nest: The Read-Copy-Update Pattern In Python Distributed Systems http://architects.dzone.com/articles/gevent-zeromq Python 2 vs 3 Python 2 or 3 ? Porting to Python 3 http://python3porting.com/ Books Free Some free books on Python Invent with Python Think Python Byte of Python Snake Wrangling for Kids Data Structures and Algorithms with Object-Oriented Design Patterns in Python Python programming on wikibooks http://readwrite.com/2011/03/25/python-is-an-increasingly-popu#awesm=~oalneJOKY2tp7U Dive Into Python 3 Paid Some list of paid books on python Discussions https://news.ycombinator.com/item?id=3746692 https://news.ycombinator.com/item?id=5944863 http://stackoverflow.com/questions/92230/python-beyond-the-basics http://stackoverflow.com/questions/2573135/python-progression-path-from-apprentice-to-guru http://stackoverflow.com/questions/228181/zen-of-python http://stackoverflow.com/questions/101268/hidden-features-of-python Conferences and events Official PyCon website http://lanyrd.com/topics/python/ http://lanyrd.com/topics/django/ http://python.meetup.com/ http://django.meetup.com/ Videos Guido Van Rossum on the history of Python PyVideo http://lanyrd.com/topics/python/video/ http://showmedo.com/videotutorials/python Talks by Brandon Rhodes Editors and IDE’s for Python programming Setting up Sublime Text for Python Development Sublime Text 2 Love by Kenneth Reitz Sublime Text 2 tips for Python and web developers Python Newsletters Python Weekly Pycoder’s Miscellaneous Good to great Python reads How to Create Barcodes in Your PDFs with Python What are some good Python interview questions ? Python innards introduction source: pycrumbs github</description>
			</item>
			<item>
				<title>Simple Sudoku solver in python</title>
				<link>https://yasoob.me/2013/09/01/sudoku-solver-in-python/</link>
				<pubDate>Sat, 31 Aug 2013 20:43:16 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/09/01/sudoku-solver-in-python/</guid>
				<category>python</category>
				<description>Hi there pythonistas! We all know that Sudoku is a great game. Some of us even bet on this game but did you know that you can use python to make a Sudoku solver? In this post I am going to share with you a Sudoku solver written in python. From now on you will win all Sudoku challenges. However let me tell you that I am not the original writer of this script. I stumbled over this script on stack-overflow. So without wasting any time let me share the script with you:</description>
			</item>
			<item>
				<title>Fixing error – maximum recursion depth reached</title>
				<link>https://yasoob.me/2013/08/31/fixing-error-maximum-recursion-depth-reached/</link>
				<pubDate>Fri, 30 Aug 2013 19:35:34 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/31/fixing-error-maximum-recursion-depth-reached/</guid>
				<category>python</category>
				<description>Hi there folks. In this post I am going to teach you how to increase the recursion depth in python. Most of us at some time get this error: RuntimeError: maximum recursion depth exceeded If you want to fix this error just increase the default recursion depth limit but how to do it? Just import the sys module in your script and in the beginning of the script type this: sys.setrecursionlimit(1500) This will increase the default limit to 1500. For the record, the default limit is 1000. I hope that you found this post useful. Do share this on facebook and twitter and stay tuned for my next post. ❤️ 👋</description>
			</item>
			<item>
				<title>Looking Inside Dropbox – whitepaper</title>
				<link>https://yasoob.me/2013/08/30/looking-inside-dropbox-whitepaper/</link>
				<pubDate>Fri, 30 Aug 2013 09:53:43 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/30/looking-inside-dropbox-whitepaper/</guid>
				<category>python</category>
				<description>Hi there folks. We all know that dropbox is made in python. It’s website is made with pyramid and it’s desktop applications are made with python. The existing Python bytecode reversing techniques are not enough for reversing hardened applications like Dropbox. Recently I came accross a whitepaper written by Dhiru Kholia and Przemysław Wegrzyn. This paper presents new and generic techniques, to reverse engineer frozen Python applications, which are not limited to just the Dropbox world. It describes a method to bypass Dropbox’s two factor authentication and hijack Dropbox accounts.</description>
			</item>
			<item>
				<title>Finding the module version</title>
				<link>https://yasoob.me/2013/08/28/finding-the-module-version/</link>
				<pubDate>Wed, 28 Aug 2013 03:57:05 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/28/finding-the-module-version/</guid>
				<category>python</category>
				<description>Hi there folks. I know I have not been active recently and it was because I was not in town. I was in Canada. So this post will be short. In this post i will show you how you can find the version number of any python module. Sometimes you need to find the version number in order to know whether you have the desired version of the module or not. So here is the trick.</description>
			</item>
			<item>
				<title>Making a song downloader with python</title>
				<link>https://yasoob.me/2013/08/13/making-a-song-downloader-with-python/</link>
				<pubDate>Tue, 13 Aug 2013 17:50:38 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/13/making-a-song-downloader-with-python/</guid>
				<category>python</category>
				<description>Edit: This post is about ex.fm which is not functioning anymore. ex.fm has closed their operations :crying_face: Hi there folks. Some time ago i was very much interested in how music downloaders for various websites worked. In order to learn this i went forward to make my own downloader for ex.fm. Currently ex.fm does not allow users to download songs so this was a very good chance for me to learn song downloading with python.</description>
			</item>
			<item>
				<title>Storing and Loading Data with JSON</title>
				<link>https://yasoob.me/2013/08/08/storing-and-loading-data-with-json/</link>
				<pubDate>Wed, 07 Aug 2013 23:55:19 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/08/storing-and-loading-data-with-json/</guid>
				<category>python</category>
				<description>We’ve already learned about pickle, so why do we need another way to (de)serialize Python objects to(from) disk or a network connection? There are three major reasons to prefer JSON over pickle: When you’re unpickling data, you’re essentially allowing your data source to execute arbitrary Python commands. If the data is trustworthy (say stored in a sufficiently protected directory), that may not be a problem, but it’s often really easy to accidentally leave a file unprotected (or read something from network). In these cases, you want to load data, and not execute potentially malicious Python code! Pickled data is not easy to read, and virtually impossible to write for humans. For example, the pickled version of {&amp;#34;answer&amp;#34;: [42]} looks like this: (dp0 S&amp;#39;answer&amp;#39; p1 (lp2 I42 as. In contrast, the JSON representation of {&amp;#34;answer&amp;#34;: [42]} is {&amp;#34;answer&amp;#34;: [42]}. If you can read Python, you can read JSON; since all JSON is valid Python code! Pickle is Python-specific. In fact, by default, the bytes generated by Python 3’s pickle cannot be read by a Python 2.x application! JSON can be read by virtually any programming language - just scroll down on the official homepage to see implementations in all major and some minor languages.</description>
			</item>
			<item>
				<title>The self variable in python explained</title>
				<link>https://yasoob.me/2013/08/07/the-self-variable-in-python-explained/</link>
				<pubDate>Tue, 06 Aug 2013 21:21:30 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/07/the-self-variable-in-python-explained/</guid>
				<category>python</category>
				<description>Hi everyone! In this post I am going to teach you about the self variable in python. I have seen many beginners struggling to grasp the concept of self variable. If you are one of them then this post is for you. So lets start by making a class involving the self variable. A simple class So here is our class: class Restaurant(object): bankrupt = False def open_branch(self): if not self.bankrupt: print(&amp;#34;branch opened&amp;#34;) First let me explain the above code without the technicalities. First of all we make a class Restaurant. Then we assign it a property ‘bankrupt’ which is currently false. After that we assign it a function open_branch which can only occur if ‘bankrupt’ is False which means that the Restaurant has some money.</description>
			</item>
			<item>
				<title>Python Socket Programming: Simple Server and Client Example</title>
				<link>https://yasoob.me/2013/08/06/python-socket-network-programming/</link>
				<pubDate>Mon, 05 Aug 2013 21:06:28 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/06/python-socket-network-programming/</guid>
				<category>python</category>
				<description>Learn Python socket programming with the built-in socket module: connect to a server, build a simple TCP server, and write a client that talks to it.</description>
			</item>
			<item>
				<title>*args and **kwargs in python explained</title>
				<link>https://yasoob.me/2013/08/04/args-and-kwargs-in-python-explained/</link>
				<pubDate>Sun, 04 Aug 2013 13:14:17 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/04/args-and-kwargs-in-python-explained/</guid>
				<category>python</category>
				<description>Hi there folks. I have come to see that most new python programmers have a hard time figuring out the *args and **kwargs magic variables. So what are they? First of all let me tell you that it is not necessary to write *args or **kwargs. Only the * (aesteric) is necessary. You could have also written *var and **vars. Writing *args and **kwargs is just a convention. So now lets take a look at *args first.</description>
			</item>
			<item>
				<title>Making a url shortener in python</title>
				<link>https://yasoob.me/2013/08/03/a-url-shortener-in-python/</link>
				<pubDate>Sat, 03 Aug 2013 04:54:10 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/03/a-url-shortener-in-python/</guid>
				<category>python</category>
				<description>Hi there fellas. Today in this post i am going to show you how we can use python to make bulk urls tiny. Let me clear that we are not making a url shortening SERVICE instead what we are going to do is that we are going to unofficially use the tinyurl api (Tinyurl is a url shortening service). There’s not any official python api released by tinyurl. So lets begin with this:</description>
			</item>
			<item>
				<title>5 quality screencasts worth watching</title>
				<link>https://yasoob.me/2013/08/02/5-quality-screencasts-worth-watching/</link>
				<pubDate>Fri, 02 Aug 2013 13:27:46 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/02/5-quality-screencasts-worth-watching/</guid>
				<category>python</category>
				<description>Hello there fellas. I am back with another list of useful resources. This time i am going to share with you 5 quality python screen casts worth watching. Unlike ruby there are not really much quality screen casts related to python out there. So without wasting a dime lets continue with the list of those screen casts. So here it is: The first one if Encoding Specifiers and Magical Mode Lines in python. There’s a lot in it for learning. Go check it out and you won’t regret it. The second one is by Neck Beard Republic. This one is about lambda functions in python. Neck Beard Republic have great python screen casts but most of them are paid however they have some free screen casts as well. The third one is a series of screen casts by Kenneth Love. They are related to django. The title is Getting Started With Django. They are great. I have personally watched them. There’s something for everyone in it. The fourth one is again by Neckbeard Republic. This one is a must watch for every python programmer out there. The title of this screen cast is __dunder__ functions in python. There can be alot of mystery involved in Python when it comes to the dunder (double underscore) methods. This screen cast will reveal the secret behind these function. However i have not personally watched it but it’s on my todo list. Ah so now comes the last one. This one is again a Neckbeard Republic production. This one is about the super() literal in python. I can see how much effort Mahdi Yusuf has put into making these screen casts.</description>
			</item>
			<item>
				<title>What is Pickle in python?</title>
				<link>https://yasoob.me/2013/08/02/what-is-pickle-in-python/</link>
				<pubDate>Fri, 02 Aug 2013 03:59:33 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/02/what-is-pickle-in-python/</guid>
				<category>python</category>
				<description>Hi there fellas. In this post i am going to tell you about pickle. It is used for serializing and de-serializing a Python object structure. Any object in python can be pickled so that it can be saved on disk. What pickle does is that it “serialises” the object first before writing it to file. Pickling is a way to convert a python object (list, dict, etc.) into a character stream. The idea is that this character stream contains all the information necessary to reconstruct the object in another python script. So lets continue:</description>
			</item>
			<item>
				<title>10 inspirations for your next python project</title>
				<link>https://yasoob.me/2013/08/01/10-inspirations-for-your-next-python-project/</link>
				<pubDate>Thu, 01 Aug 2013 18:27:34 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/01/10-inspirations-for-your-next-python-project/</guid>
				<category>python</category>
				<description>Hi there fellow coders. I know those times when we don’t know what to code. I am sure you must have experienced that time as well. Today i am going to share with you 10 python projects that will serve as an inspiration for your next python project. So without wasting a time here’s the list. Pillow. Pillow is the “friendly” PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lundh and Contributors. Alex teaches us that if you don’t like something then make a fork. Inbox.py. This is the simplest SMTP server you’ll ever see. It’s asynchronous. One instance should handle over one thousand emails per second. Pretty impressive. PyMinecraft. Have you ever thought of implementing the famous minecraft game into python? Hawstein has. fuqit. The latest and greatest from Zed Shaw (the writer of learn python the hard way) , fuqit is a web framework that attempts to make you forget everything you have learned from MVC frameworks and focuses on simplicity. Zed Shaw teaches us one thing through this project “Don’t panic while doing something against the trend”. PyPI Notifier. Watches your requirements.txt files and notifies you via email when a project is updated. Although i have not used it myself but i think this project is great. Vol. A simple project but great inspiration. vol lets you control your mac’s audio volume from the commandline. It also has support for profiles. Youtube-dl. A great python project. It allows you to download videos from various websites. It’s a great project make sure that you check it out. Jukebox. Ever wanted to listen to music with a larger group of people e.g. in your office? Who decides what to play? Make your music player democratic and give everyone the chance to promote their favourite song. This script will relieve you from numerous fights. Mitmproxy. mitmproxy is a an SSL capable man-in-the-middle-proxy. It allows HTTP(and other) traffic to be inspected and edited on the fly. Don’t be caught unaware by apps like Path any more, now you can know what data you are sending and receiving from remote servers. Thumbor. It is a smart imaging service. It enables on-demand crop, resizing and flipping of images. I haven’t checked it out though but it seems promising. Do check it out if you want a server side image cropper.</description>
			</item>
			<item>
				<title>Packaging and distributing your python libraries</title>
				<link>https://yasoob.me/2013/08/01/packaging-and-distributing-your-python-libraries/</link>
				<pubDate>Thu, 01 Aug 2013 09:51:08 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/01/packaging-and-distributing-your-python-libraries/</guid>
				<category>python</category>
				<description>Hi there fellow coders. This post will go over the basics of packaging and deploying your python libraries. So without wasting a minute lets get started.. Folder structure So first thing first. What should be your folder structure? At minimum you can have only two files. The first one should be the setup.py file and the second one should be your module file. But today I am not going to talk about the very basics. Today we are going to follow this folder structure:</description>
			</item>
			<item>
				<title>Connecting to Sqlite databases</title>
				<link>https://yasoob.me/2013/08/01/connecting-to-sqlite-databases/</link>
				<pubDate>Wed, 31 Jul 2013 19:48:33 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/08/01/connecting-to-sqlite-databases/</guid>
				<category>python</category>
				<description>Hi there fellas. Today i am going to teach you how to use sqlite databases with python. This post will cover the basics of making and using a sqlite database with python using the sqlite3 library. Okay lets get started. Firstly if you are using python 2.5 or greater then you will have sqlite3 installed otherwise you will have to install it. Creating and connecting to a database So how do you make a database in python using the sqlite3 library? It’s pretty simple. Just follow the code below and you will be able to make it out on your own.</description>
			</item>
			<item>
				<title>Give me an idea for an Ebook</title>
				<link>https://yasoob.me/2013/07/31/give-me-an-idea-for-an-ebook/</link>
				<pubDate>Wed, 31 Jul 2013 15:41:49 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/31/give-me-an-idea-for-an-ebook/</guid>
				<category>python</category>
				<description>Hi there fellas. Today i am going to ask you for a favour. I am going to write an ebook about python. I want you to give me some ideas about what i should write. This Ebook is going to be short. It will be between 10 to 20 pages because it’s my first ebook. Currently i have two topics in mind. The first one is to write an introductory ebook about how to get started with python. This will be for beginners and will include the installation and setting up of python as well as some introductory tutorials.</description>
			</item>
			<item>
				<title>10 python blogs worth following</title>
				<link>https://yasoob.me/2013/07/31/10-python-blogs-worth-following/</link>
				<pubDate>Wed, 31 Jul 2013 09:19:42 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/31/10-python-blogs-worth-following/</guid>
				<category>python</category>
				<description>Hi there fellow programmers. I remember those days when i started learning python. I was always eager to find new blogs about python but found just a handful of them. This is one of the reason i started this blog. To spread my knowledge about python to other fellow coders. Today i am going to try to provide you 10 links to different python blogs that are worth following. By that i mean they are regularly updated and have useful info. So here’s the list:</description>
			</item>
			<item>
				<title>20 Python libraries you can’t live without</title>
				<link>https://yasoob.me/2013/07/30/20-python-libraries-you-cant-live-without/</link>
				<pubDate>Tue, 30 Jul 2013 18:44:50 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/30/20-python-libraries-you-cant-live-without/</guid>
				<category>python</category>
				<description>Hi there fellas. Today i am going to list 20 python libraries which have been a part of my toolbelt and should be a part of yours as well. So here they are: Requests. The most famous http library written by Kenneth Reitz. It’s a must have for every python developer. Scrapy. If you are involved in webscraping then this is a must have library for you. After using this library you won’t use any other. wxPython. A gui toolkit for python. I have primarily used it in place of tkinter. You will really love it. Pillow. A friendly fork of PIL (Python Imaging Library). It is more user friendly than PIL and is a must have for anyone who works with images. SQLAlchemy. A database library. Many love it and many hate it. The choice is yours. BeautifulSoup. I know it’s slow but this xml and html parsing library is very useful for beginners. Twisted. The most important tool for any network application developer. It has a very beautiful api and is used by a lot of famous python developers. NumPy. How can we leave this very important library ? It provides some advance math functionalities to python. SciPy. When we talk about NumPy then we have to talk about scipy. It is a library of algorithms and mathematical tools for python and has caused many scientists to switch from ruby to python. matplotlib. A numerical plotting library. It is very useful for any data scientist or any data analyzer. Pygame. Which developer does not like to play games and develop them ? This library will help you achieve your goal of 2d game development. Pyglet. A 3d animation and game creation engine. This is the engine in which the famous python port of minecraft was made pyQT. A GUI toolkit for python. It is my second choice after wxpython for developing GUI’s for my python scripts. pyGtk. Another python GUI library. It is the same library in which the famous Bittorrent client is created. Scapy. A packet sniffer and analyzer for python made in python. pywin32. A python library which provides some useful methods and classes for interacting with windows. nltk. Natural Language Toolkit – I realize most people won’t be using this one, but it’s generic enough. It is a very useful library if you want to manipulate strings. But it’s capacity is beyond that. Do check it out. nose. A testing framework for python. It is used by millions of python developers. It is a must have if you do test driven development. SymPy. SymPy can do algebraic evaluation, differentiation, expansion, complex numbers, etc. It is contained in a pure Python distribution. IPython. I just can’t stress enough how useful this tool is. It is a python prompt on steroids. It has completion, history, shell capabilities, and a lot more. Make sure that you take a look at it.</description>
			</item>
			<item>
				<title>Targeting python 2 and 3 at the same time.</title>
				<link>https://yasoob.me/2013/07/30/make-your-programs-compatible-with-python-2-and-3-at-the-same-time/</link>
				<pubDate>Tue, 30 Jul 2013 14:58:06 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/30/make-your-programs-compatible-with-python-2-and-3-at-the-same-time/</guid>
				<category>python</category>
				<description>Hi there pythonistas. Today i am not going to write a lengthy tutorial about how to make your programs compatible with python 2 and 3 at the same time, but i am going to share a simple tip with you guys which will help you achieve this target. Just imagine that you have a very popular python module which is use by hundreds of people but not all of them have python 2 or 3. In that case you have two choices. The first one is to distribute 2 modules. One for python 2 and the other for python 3 and the other choice is to modify your current code so that it can be used with both python 2 and 3.</description>
			</item>
			<item>
				<title>What is virtualenv and why you should use it.</title>
				<link>https://yasoob.me/2013/07/30/what-is-virtualenv/</link>
				<pubDate>Tue, 30 Jul 2013 09:02:12 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/30/what-is-virtualenv/</guid>
				<category>python</category>
				<description>Have you ever heard of virtualenv? The chances are that if you are a beginner then you might not have heard about it but if you are a seasoned programmer than it’s a vital part of your toolset. So what is virtualenv really? Virtualenv is a tool which allows us to make isolated python environments. How does making isolated python environments help us? Imagine you have an application that needs version 2 of a LibraryBar, but another application requires version 2. How can you use and develop both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.</description>
			</item>
			<item>
				<title>Exception handling</title>
				<link>https://yasoob.me/2013/07/30/exception-handling/</link>
				<pubDate>Mon, 29 Jul 2013 21:03:40 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/30/exception-handling/</guid>
				<category>python</category>
				<description>Okay so the chances are you already know about exception handling in python but some new programmers don’t. How do you handle exceptions in python? First let me tell you what exceptions are. Exceptions are when something unexpected happens with your code. Just think that you writing a huge program which browses the internet and accesses web pages, the program works fine on your side and you consider packaging and distributing it. But something unexpected occurs on the pc of the user who downloaded your package from the internet and tried to run it. His internet connection dropped. What will happen?</description>
			</item>
			<item>
				<title>Python install location and version</title>
				<link>https://yasoob.me/2013/07/30/python-install-location-and-version/</link>
				<pubDate>Mon, 29 Jul 2013 19:17:34 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/30/python-install-location-and-version/</guid>
				<category>python</category>
				<description>Have you ever wondered how to check the install path of python and it’s version? If you have then this post is for you. It is very easy to check the version and install location of python on linux as well as on windows. First I will show the method of checking this on linux and then on windows. On linux just type these two commands in the terminal: # for python install path root@bt:/$ which python /usr/bin/python # for python version; root@bt:/usr/bin$ python -V Python 2.7.5 On windows type this commands in the command prompt for python version: python -V And type these commands in the python shell for python install path</description>
			</item>
			<item>
				<title>Coding styles for python</title>
				<link>https://yasoob.me/2013/07/29/coding-styles-for-python/</link>
				<pubDate>Mon, 29 Jul 2013 15:08:16 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/29/coding-styles-for-python/</guid>
				<category>python</category>
				<description>Yet another useful post and this one is about coding styles in python. Everyone has his own coding style in python. Here i am going to post some links that will help you to choose your own coding style in python. The first link is undoubtedly from the official python documentation as python documentation has everything to get you started. This link will teach you how to use python and how not to use python. The second link is from the famous PEP-8 which is python’s official style guide. It determines the python’s official coding standards. You should definitely take a look at them and try to incorporate them in your code. The third link is from google because as you know google is a huge user of python and most of their infrastructure is based on python as is their online support forum. So it’s not surprising that google has it’s own style guide for python. So the last link is from khanacademy. As you know it’s the biggest online academy and whole of their online infrastructure is based on python. I really love their python style guide.</description>
			</item>
			<item>
				<title>Setting up python on windows</title>
				<link>https://yasoob.me/2013/07/29/setting-up-python-on-windows/</link>
				<pubDate>Mon, 29 Jul 2013 11:44:11 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/29/setting-up-python-on-windows/</guid>
				<category>python</category>
				<description>Hi there pythonistas. Most of the new python programmers don’t know how to correctly install python on windows. Today I am going to share clean and clear instructions on how to install python on a Windows 7 machine. There are only 4 steps involved so without wasting a minute lets get started. Visit the official Python download page and grab the Windows installer. Choose the 32-bit version. (A 64-bit version is available, but there are compatibility issues with some modules you may want to install later.) Note: Python currently exists in two versions. One is 2.xx version and the other is 3.xx version. In this post i am going to focus only on 2.xx version as it is more widely used right now and some modules don’t support 3.xx version as yet. Run the installer and accept all the default settings. Don’t change the default directory it creates. Now comes the trickiest part. We have to add python to our environment variable. You do not have to understand what environment variable is. Just follow along with me. We set the system’s PATH variable to include directories that include Python components and packages so that they are available in the command prompt. Without doing this we won’t be able to use python from command line. To do this: Right-click Computer and select Properties. In the dialog box, select Advanced System Settings. In the next dialog, select Environment Variables. In the User Variables section, edit the PATH statement to include this: C:\Python27;C:\Python27\Lib\site-packages\;C:\Python27\Scripts\; Now, you can open a command prompt (Start Menu|Accessories or Start Menu|Run|cmd) and type: python That will load the Python interpreter:</description>
			</item>
			<item>
				<title>Packaging your python scripts.</title>
				<link>https://yasoob.me/2013/07/29/packaging-your-python-scripts/</link>
				<pubDate>Mon, 29 Jul 2013 09:42:38 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/29/packaging-your-python-scripts/</guid>
				<category>python</category>
				<description>Oh hi there! Welcome to another useful post. This post is going to be about how to package your python scripts and packages for distribution on PyPI or some other place. Here I won’t go too deep into explaining everything as most of us just need to know the basics of packaging. However i will provide you with different links for further study. Okay lets talk about setuptools first. What is it? It’s a Python module which allows us to easily package our python scripts and modules for distribution. However there are other packaging libraries as well but here i will talk about setuptools only.</description>
			</item>
			<item>
				<title>Dictionaries have a get() method</title>
				<link>https://yasoob.me/2013/07/29/dictionaries-have-a-get-method/</link>
				<pubDate>Sun, 28 Jul 2013 19:59:13 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/29/dictionaries-have-a-get-method/</guid>
				<category>python</category>
				<description>Okay here we are with yet another post. However this post is going to be short as in this post i am going to teach you a small, simple and very useful trick. Have you ever tried to access a value from a dictionary and got an exception that there is no value mapped to that key? Like this: &amp;gt;&amp;gt;&amp;gt; dict = {&amp;#39;key1&amp;#39;:2,&amp;#39;key2&amp;#39;:3} &amp;gt;&amp;gt;&amp;gt; dict[&amp;#39;key1&amp;#39;] 2 &amp;gt;&amp;gt;&amp;gt; dict[&amp;#39;key3&amp;#39;] Traceback (most recent call last): File &amp;#34;&amp;#34;, line 1, in dict[&amp;#39;key3&amp;#39;] KeyError: &amp;#39;key3&amp;#39; Sometimes you do not want anything like this because this error can break your whole program and make it useless until you fix this issue. Is there any way through which we can see if a key is present in a dictionary or not and if it is not present then get a default value in it’s place? the chances are that you don’t know of any such method. Okay so here’s the trick. Just examine the code below and i will explain it later.</description>
			</item>
			<item>
				<title>The use of return and global keywords</title>
				<link>https://yasoob.me/2013/07/28/the-use-of-return-and-global-keywords/</link>
				<pubDate>Sun, 28 Jul 2013 18:52:08 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/28/the-use-of-return-and-global-keywords/</guid>
				<category>python</category>
				<description>Okay so here we have another post. This post is about the return keyword. you might have encountered some functions written in python which have a return keyword in the end of the function. Do you know what it does? Lets examine this little function: &amp;gt;&amp;gt;&amp;gt; def add(value1,value2): ... return value1 + value2 &amp;gt;&amp;gt;&amp;gt; result = add(3,5) &amp;gt;&amp;gt;&amp;gt; print result 8 The function above takes two values as input and then output their addition. We could have also done:</description>
			</item>
			<item>
				<title>Generating a random string</title>
				<link>https://yasoob.me/2013/07/28/generating-a-random-string/</link>
				<pubDate>Sun, 28 Jul 2013 12:40:54 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/28/generating-a-random-string/</guid>
				<category>python</category>
				<description>Okay, so, most of us do not know how to generate random strings which include letters and digits. This can be really useful for generating a password (or, you know, stuff to aid you in your plan for world domination). So how do we generate a random string? Have you ever heard of the string module available in python? Chances are, you haven’t. So what does this module provide us? Okay here you go lets understand this module by example:</description>
			</item>
			<item>
				<title>What is __init__.py ?</title>
				<link>https://yasoob.me/2013/07/28/what-is-__init__-py/</link>
				<pubDate>Sun, 28 Jul 2013 11:00:30 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/28/what-is-__init__-py/</guid>
				<category>python</category>
				<description>Okay yet another useful post. This post is really important and useful for anyone just starting out with python. So what is the __init__.py file ? Files name __init__.py are used to mark directories on disk as Python package directories. If you have the following files: mydir/spam/__init__.py mydir/spam/module.py and mydir is on your path, you can import the code in module.py as import spam.module or from spam import module If you remove the __init__.py file, Python will no longer look for submodules inside that directory, so attempts to import the module will fail.</description>
			</item>
			<item>
				<title>The with statement</title>
				<link>https://yasoob.me/2013/07/28/the-with-statement/</link>
				<pubDate>Sun, 28 Jul 2013 10:23:14 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/28/the-with-statement/</guid>
				<category>python</category>
				<description>So the chances are that you already know about the with statement but some of us do not know about it. Lets face the reality the with statement saves us a lot of time and reduces our code base. Just imagine you are opening a file width python and then saving something to it. You would normally do: file = open(&amp;#39;file.txt&amp;#39;,&amp;#39;w&amp;#39;) file.write(&amp;#34;freepythontips.wordpress.com&amp;#34;) file.close() But what if an exception occurs while writing to file ? then the file won’t be closed properly. I know how much trouble it can cause. It once happened with me that i was running a web scrapper and it was running for past three hours and then unexpectedly an exception occured and my whole csv file got corrupted and i had to run the scrapper again.</description>
			</item>
			<item>
				<title>A simple python server</title>
				<link>https://yasoob.me/2013/07/28/a-simple-python-server/</link>
				<pubDate>Sat, 27 Jul 2013 21:25:44 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/28/a-simple-python-server/</guid>
				<category>python</category>
				<description>I guess it’s not a simple python server. It is really simple and easy to deploy python server. Just imagine you want to share a folder on your pc with someone on your network. What you will do? Obviously you will start the sharing service but what if you have python installed and want an easier solution? Here you go. You can just type in: $ python -m SimpleHTTPServer This should be typed in the terminal or command prompt if you are a windows guy. Just open command prompt. Navigate to the directory which you want to share and then run this command. Unlike the normal sharing services this server will also show you the IP addresses of the PCs which are accessing that folder. Pretty slick right?</description>
			</item>
			<item>
				<title>In-place value swapping</title>
				<link>https://yasoob.me/2013/07/28/in-place-value-swapping/</link>
				<pubDate>Sat, 27 Jul 2013 21:08:51 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/28/in-place-value-swapping/</guid>
				<category>python</category>
				<description>Okay so this is kinda new for some of us. If you are a seasoned programmer then this might not be surprising for you but if you are a new programmer then this is something you really need to know. Okay so here we go. In normal situations if you would want to swap the values of two variables then this would be something you would go after: a = 1 b = 2 c = a a = b b = c But there’s a more simple method which will merely take three lines. Here it is:</description>
			</item>
			<item>
				<title>The beginning of a new blog.</title>
				<link>https://yasoob.me/2013/07/28/welcome/</link>
				<pubDate>Sat, 27 Jul 2013 20:29:22 +0000</pubDate>
				<dc:creator>Yasoob Khalid</dc:creator>
				<guid>https://yasoob.me/2013/07/28/welcome/</guid>
				<category>Uncategorized</category>
				<description>Hi there! Today, I am beginning my very own personal blog related to Python. Let me first tell you who I am. I am a computer programmer from Pakistan. I have made a lot open source contributions. I have contributed mainly to youtube-dl. It’s a python script which allows you to download videos from various websites like youtube, facebook, dailymotion, metacafe, etc. I also run a website with the name of http://www.soundcloud-dl.appspot.com/ It allows you to search and download music from soundcloud.com. Sounds cool, doesn’t it? 😀 I have done all of its backend programming in python. I also have some useful scripts on my GitHub page, and if you would like to check them out or utilize them, you are most welcome to do so. This blog will serve you new Python tips every other day. This blog is not for seasoned programmers but those who are starting out with Python, or want to enhance their knowledge about this language.</description>
			</item>
	</channel>
</rss>
