<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>Python developer, Linux administrator and MacOS user from Russia.</description><title>PenPen</title><generator>Tumblr (3.0; @penpen938)</generator><link>http://penpen.in/</link><item><title>Multi site system on single django project with uwsgi </title><description>&lt;p&gt;Yesterday I&amp;#8217;ve set up an interesting uwsgi installation, which can serve multiple sites from single django project. Here is uWSGI Upstart script for ubuntu server:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
description "uWSGI starter"

start on (local-filesystems
and runlevel [2345])
stop on runlevel [016]

respawn

exec /usr/local/bin/uwsgi --uid penpen \
-s 127.0.0.1:9010 -M -p 2 --reload-os-env \
--logto /home/penpen/logs/biribiri/uwsgi_log \
-H /home/penpen/biribiri/virtualenv \
--pythonpath /home/penpen --vhost --vhost-host
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This script uses uWSGI virtual hosting mode, which allows multiple wsgi apps in single interpreter (unlike emperor mode, which uses interpreter per app (or site)).&lt;br/&gt;It is necessary to use &amp;#8220;&amp;#8212;reload-os-env&amp;#8221; option, which passes environment variable through UWSGI_SETENV parameter. In this installation nginx passes current site name in uwsgi, which loads settings from module named as biribiri.hosts.SITE_NAME. &lt;br/&gt; For production use, it would be a nice idea to check if file exists and use default settings for non-existant sites. &lt;br/&gt;I use DJANGO_HOST instead of DJANGO_SETTINGS_MODULE because in current installation it overrides somewhere. &lt;br/&gt; Nginx config:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
server {
	listen 80 default;
	server_name biribiri;
	root /home/penpen/biribiri;

	location / {
		uwsgi_pass 127.0.0.1:9010;
		uwsgi_param UWSGI_MODULE biribiri.production.wsgi;
		uwsgi_param UWSGI_SETENV DJANGO_HOST=biribiri.hosts.$http_host;
		include uwsgi_params;	
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;wsgi.py connector for django (in biribiri.production.wsgi):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
import os
import sys

path = '/home/penpen/biribiri'

if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = os.environ['DJANGO_HOST'].replace('.ru', '')

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the above code snippet we are going to remove TLD from site name, because python modules don&amp;#8217;t allow dot in their names.&lt;/p&gt;</description><link>http://penpen.in/post/8599244515</link><guid>http://penpen.in/post/8599244515</guid><pubDate>Sun, 07 Aug 2011 17:36:00 +0400</pubDate><category>django</category><category>uwsgi</category><category>multisite</category></item><item><title>IPv6 Sage Certified</title><description>&lt;p&gt;&lt;a target="_blank" href="http://ipv6.he.net/certification/scoresheet.php?pass_name=penpen938"&gt;&lt;img src="http://ipv6.he.net/certification/create_badge.php?pass_name=penpen938&amp;amp;badge=3" width="229" height="137" border="0" alt="IPv6 Certification Badge for penpen938"/&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://penpen.in/post/6824768832</link><guid>http://penpen.in/post/6824768832</guid><pubDate>Thu, 23 Jun 2011 16:46:37 +0400</pubDate></item><item><title>Publishedin</title><description>&lt;p&gt;One of my friends told me about good service for bloggers. Here is - &lt;span&gt;&lt;a href="http://publishedin.com/" target="_blank"&gt;&lt;a href="http://publishedin.com/" target="_blank"&gt;http://publishedin.com/&lt;/a&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;</description><link>http://penpen.in/post/6549574450</link><guid>http://penpen.in/post/6549574450</guid><pubDate>Wed, 15 Jun 2011 12:47:00 +0400</pubDate></item><item><title>Leaf</title><description>&lt;p&gt;I&amp;#8217;ve just released leaf 0.4. This is simple python library for html parsing.&lt;/p&gt;
&lt;p&gt;&lt;a title="GitHub Repo" href="https://github.com/penpen/Leaf" target="_blank"&gt;GitHub&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a title="Python packages" href="http://pypi.python.org/pypi/leaf/0.4" target="_blank"&gt;Python packages&lt;/a&gt;&lt;/p&gt;</description><link>http://penpen.in/post/3727047015</link><guid>http://penpen.in/post/3727047015</guid><pubDate>Tue, 08 Mar 2011 23:09:00 +0300</pubDate></item><item><title>Ugly unicode text</title><description>&lt;p&gt;A couple of days ago, I worked with an ugly unicode text, kind of like this:&lt;/p&gt;
&lt;pre&gt;ⒶⓀⓋⓉⒺ
b̼̘̬ͭ͂̈́̀l͇͉̱͚̲̗̗͞a̱̭̬͎͉̤ͨ͂̌̑̓͂͐h̬̯̻̩͗ͩͯḅ̢̬͕͈̥̅̌͆̔̉ͅḽ̘̖̼͚́͒̈́̏͌̃͟ ͎̮̫̍ͫ̽͐͋ͤ͂a̜͔̩͇̩̪͐̍̐̃ͤ͑ ̦̌ḧ̙̝͓̜͕̝̈́ͅb̛̞͔̽̃̍ͪla̘̠͖͍̣͙̝͌ͪ͒̃ͯ ͗͛̆͊.̛̭̜̞̲͓̯ͧ̅ĥ͂͑/̢̊/̠̘͖͖̖̺̯
&lt;/pre&gt;
&lt;p&gt;And I need to get a normal text from this shit, because MySQL has weird unicode support. So I made these simple functions for cleaning up unicode text:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;def strip_accents(s):
    """ Strip accents from a string """
    result = []
    for char in s:
		# Pass these symbols without processing
        if char in [u'й', u'Й', u'\n']: 
            result.append(char)
            continue
        for c in unicodedata.normalize('NFD', char):
            if unicodedata.category(c) == 'Mn':
                continue
            result.append(c)
    return ''.join(result)
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;def strip_symbols(s):
    """ Strip ugly unicode symbols from a string """
    result = []
    for char in s:
		# Pass these symbols without processing
        if char in [u'й', u'Й', u'\n']:
            result.append(char)
            continue
        for c in unicodedata.normalize('NFKC', char):
            if unicodedata.category(c) == 'Zs':
                result.append(u' ')
                continue
            if unicodedata.category(c) not in ['So', 'Mn', 
                             'Lo', 'Cn', 'Co', 'Cf', 'Cc']:
                result.append(c)
    return u"".join(result)
&lt;/code&gt;
&lt;/pre&gt;</description><link>http://penpen.in/post/3271567608</link><guid>http://penpen.in/post/3271567608</guid><pubDate>Sun, 13 Feb 2011 16:44:00 +0300</pubDate><category>python</category><category>unicode</category><category>mysql</category></item><item><title>Timestamps in Python</title><description>&lt;p&gt;Sometimes you need to use unix timestamp in Python for data exchange with external application (e.g. PunBB stores date as timestamp). Unfortunately Python doesn&amp;#8217;t have a built-in function for that. &lt;br/&gt;Here are some functions for that from my utils.py.&lt;/p&gt;
&lt;p&gt;Convert datetime.datetime object to unix timestamp:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;def timestamp(datetime_obj):
    """ Convert datetime object to timestamp """
    if type(datetime_obj) is datetime.datetime:
        return int(time.mktime(datetime_obj.timetuple()))
    else:
        return int(datetime_obj)
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Convert unix timestamp to datetime.datetime object:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;def from_timestamp(timestamp):
    """ Convert timestamp to datetime object"""
    return datetime.datetime.fromtimestamp(timestamp)
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Return current unix timestamp:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;def timestamp_now():
    """ Return current unix timestamp """
    return timestamp(datetime.datetime.now())&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;</description><link>http://penpen.in/post/2743372637</link><guid>http://penpen.in/post/2743372637</guid><pubDate>Fri, 14 Jan 2011 14:50:00 +0300</pubDate><category>python</category><category>timestamp</category></item><item><title>First post</title><description>&lt;p&gt;Hello there :3&lt;/p&gt;</description><link>http://penpen.in/post/2732102409</link><guid>http://penpen.in/post/2732102409</guid><pubDate>Thu, 13 Jan 2011 22:43:52 +0300</pubDate></item></channel></rss>

