<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Python</title>
	<atom:link href="https://www.project34.net/category/software/python/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.project34.net</link>
	<description></description>
	<lastBuildDate>Thu, 25 Sep 2025 08:24:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Python print stops printing</title>
		<link>https://www.project34.net/2025/09/25/python-print-stops-printing/</link>
		
		<dc:creator><![CDATA[Maikel]]></dc:creator>
		<pubDate>Thu, 25 Sep 2025 08:24:38 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[print]]></category>
		<guid isPermaLink="false">https://www.project34.net/?p=562</guid>

					<description><![CDATA[I&#8217;ve created a script that only prints a dot (.) when a process with a tag has been processed. For every process there can be a couple of hunderds of dots printed. I noticed that after a while the dot&#8217;s didn&#8217;t appear anymore. A bit of googling gave me the answer: End the print statement&#8230;]]></description>
										<content:encoded><![CDATA[
<p>I&#8217;ve created a script that only prints a dot (.) when a process with a tag has been processed. For every process there can be a couple of hunderds of dots printed. I noticed that after a while the dot&#8217;s didn&#8217;t appear anymore. </p>



<p>A bit of googling gave me the answer: <br>End the print statement with &#8220;, flush=True&#8221; and then the print command will output immediately. </p>



<p>So the command<br><code>print('.', end='')</code><br>needs to be changed to<br><code>print('.', end='', flush=True)</code></p>



<p>URL: <a href="https://stackoverflow.com/questions/25897335/why-doesnt-print-output-show-up-immediately-in-the-terminal-when-there-is-no-ne">https://stackoverflow.com/questions/25897335/why-doesnt-print-output-show-up-immediately-in-the-terminal-when-there-is-no-ne</a><br></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Storing face_encodings in a database</title>
		<link>https://www.project34.net/2022/01/06/storing-face_encodings-in-a-database/</link>
		
		<dc:creator><![CDATA[Maikel]]></dc:creator>
		<pubDate>Thu, 06 Jan 2022 21:59:31 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">http://www.project34.net/?p=252</guid>

					<description><![CDATA[I&#8217;ve been interested in Python for a while now. One thing i like is the possibility to do face recognition. Made a python script based upon a youtube clip from sentdex. The script worked fine and after some tests i was confident that i could extend the original script to what i want it to&#8230;]]></description>
										<content:encoded><![CDATA[
<p>I&#8217;ve been interested in Python for a while now. One thing i like is the possibility to do face recognition. Made a python script based upon a <a href="https://www.youtube.com/watch?v=535acCxjHCI">youtube clip from sentdex</a>. The script worked fine and after some tests i was confident that i could extend the original script to what i want it to do.</p>



<p>The main thing that annoyed me was that every time you run the script, the scripts went through the same intensive process of checking if there is a face, encoding this face to a 128 value variable type that make up this face. The 128 value variable (&#8220;encoded face&#8221;) didn&#8217;t change between run 1, run 2 and run 100. Only if you would change something to the image, maybe the library (for better processing), that could be a reason to recheck the image.</p>



<p>One other thing that annoyed me was the size of the files. When the files have been processed and you have the &#8220;face variable&#8221;, there is no need to store those files anymore. because the information that we need (and have), is much smaller then the file.</p>



<p>A couple of hours later i just couldn&#8217;t find any reliable and usable info about how that data is represented. There is a lot of information what the data means, but (at least) i couldn&#8217;t find the correct way to store the data in a MariaDB database. Well, then start from the beginning: What is the data type that comes out of <em>face_recognition.face_encodings</em>?</p>



<p>First start at the beginning:<br>Let&#8217;s find what the type is:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
encoding = face_recognition.face_encodings(image)&#x5B;0]
print(type(encoding))
</pre></div>


<p>This results in the output:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
&amp;lt;class &#039;numpy.ndarray&#039;&gt;
</pre></div>


<p>After a lot of searching (again), there was not an easy solution:</p>



<ul class="wp-block-list">
<li>sqlite3 has an array data type, which MariaDB doesn&#8217;t have.</li>



<li>You can use pickle to convert the data something to store in the database, but i just couldn&#8217;t get it working with a normal insert command</li>



<li>Converting it to base64 gave me the same issue as pickle.</li>
</ul>



<p>Eventually i found the solution to my misery: it was as, but it took me a while: <em>str(encoding.tolist())</em></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
encoding = face_recognition.face_encodings(image)&#x5B;0]
encodinglist = str(encoding.tolist())
print(type(encodinglist))
</pre></div>


<p>This gave me the following output: <em>&lt;class &#8216;str&#8217;></em></p>



<p>Well, strings is something MariaDB can work with. Created a column as varchar(4096) and voila the data can be stored. <br>Well, the 3 part process is now for 2/3 done (getting info and storing info) now we need to get the data back. The retrieval is very straight forward, select the correct columns from the table and storing it into a array again.</p>



<p>Because the data is now stored as a string and not an array, the face_recognition.compare_faces process can&#8217;t do anything with it. To convert the string back to an array is very easy:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
KNOWN_FACES.append(eval(row&#x5B;1]))
</pre></div>


<p>The eval part converts the string back to an array and puts that array in the KNOWN_FACES array.</p>



<p>So now after processing the images the main info is stored in the database and you can throw away the images if you want, or not, do what you like.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Retrieve FQDN from IP numbers in Nginx access log</title>
		<link>https://www.project34.net/2018/09/03/retrieve-fqdn-from-ip-numbers-in-nginx-access-log/</link>
		
		<dc:creator><![CDATA[Maikel]]></dc:creator>
		<pubDate>Mon, 03 Sep 2018 19:53:27 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">http://www.project34.net/?p=176</guid>

					<description><![CDATA[I wanted to write a script for&#160;expanding my Python knowledge.&#160;I ussually create small scripts to accommodate my &#8220;problems&#8221; or wishes. If you want use it:]]></description>
										<content:encoded><![CDATA[
<p>I wanted to write a script for&nbsp;expanding my Python knowledge.&nbsp;I ussually create small scripts to accommodate my &#8220;problems&#8221; or wishes.</p>



<p>If you want use it:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; quick-code: false; notranslate">
import socket

FQDN = &#x5B;]
ACC = &#x5B;]

ACC_FILE = open(&#039;/var/log/nginx/access.log&#039;)
for LINE in ACC_FILE:
        ACC.append(LINE.split(&#039; &#039;)&#x5B;0])

ACC.sort()
ACC = set(ACC)
for LINE in ACC:
        ADDR = socket.getfqdn(LINE)
        FQDN.append(ADDR)

FQDN.sort()
for SERVER in FQDN:
        print(SERVER)

</pre></div>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Thanks to my birthday gift i created my first python script</title>
		<link>https://www.project34.net/2018/05/02/thanks-to-my-birthday-gift-i-created-my-first-python-script/</link>
		
		<dc:creator><![CDATA[Maikel]]></dc:creator>
		<pubDate>Wed, 02 May 2018 22:41:29 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">http://www.project34.net/?p=173</guid>

					<description><![CDATA[A couple of weeks back was my birthday and although i don&#8217;t really celebrate, my daughter wanted to get me a gift. Because we&#8217;ve gotten a new second hand car with an old tape deck that doesn&#8217;t support aux or something, i saw a so-called FM Transmitter. This is a device you place in you&#8230;]]></description>
										<content:encoded><![CDATA[
<p>A couple of weeks back was my birthday and although i don&#8217;t really celebrate, my daughter wanted to get me a gift. Because we&#8217;ve gotten a new second hand car with an old tape deck that doesn&#8217;t support aux or something, i saw a so-called FM Transmitter. This is a device you place in you cigarette lighter in the car and you can connect a phone (over Bluetooth or AUX cable) or a simple USB stick. The AUX connection is crap! A lot of noise, but the BT and USB connection are oké. Main thing that i found as a disadvantage is that when you play music over the USB stick the music isn&#8217;t random. If you don&#8217;t like an album, you have to skip through al the songs of the album and hope you get a nice record&nbsp;after going through.</p>



<p></p>



<p>To solve this (and to learn the Python scripting language) i&#8217;ve created the next script:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
import os
from shutil import copyfile
from random import randint
import pathlib

MP3_FOLDER=r&#039;Source  folder&#039;
DEST_FOLDER = &#039;Destination Folder&#039;
FileCount = 1
for root,dirs,files in os.walk(MP3_FOLDER):
    for file in files:
        if file.endswith(&#039;.mp3&#039;):
            print(FileCount)
            FileCount = FileCount + 1
            rndFolder = DEST_FOLDER+str(randint(100, 999))
            rndFile = randint(10000, 99999)
            pathlib.Path(rndFolder).mkdir(parents=True, exist_ok=True)
            srcfile = os.path.join(root,file)
            dstfile = rndFolder+&#039;\\&#039;+str(rndFile)+&#039;.mp3&#039;
            copyfile(srcfile,dstfile)&lt;/pre&gt;
</pre></div>


<p>It scans the source folder and for every file that ends with &#8216;.mp3&#8217; it generates&nbsp;a random number between 100 and 999, and creates a folder of it. Then it generates a random number between 10000 and 99999 and makes a file out of it with the extension &#8216;.mp3&#8217;. In my situation there are 5000+ mp3 files, so there will be a descent amount of directories, with different filenames in them. When the files are done, i can copy them from the destination folder to my USB stick. Of course the destination folder can already be the USB stick.</p>



<p>If you are interested in the FM Transmitter, search for &#8216;BC06&#8217;. This is a very generic FM transmitter. I think you can buy them in China and sell them under your own brand. I&#8217;ve seen them from MFEEL, Kebidumei, Kebidu etc etc etc.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
