Python Create UUID from random string of words

Context: I'm loading data from one database (A) to another database (Weaviate). Weaviate only supports UUID, however database A is using strings as the primary identifier for some tables.

Problem: In order to not duplicate data I need to ensure that the string identifier gets converted to an UUID in …

Continue reading »

Python Create UUID from integer

Code:

import uuid
my_uuid = uuid.UUID(int=1)
print(my_uuid)

That should show the following string:

00000000-0000-0000-0000-000000000001

You can also convert back to integer by doing:

my_uuid.int()

For my use case this was needed because my source database has integer based IDs, however the destination …

Continue reading »

Install PyQt in a virtualenv with Pip

Noticed that pip install pyqt isn't working? At least at the time of writing this blog it isn't..

This is the error that I got:
IOError: [Errno 2] No such file or directory: setup.py

It seems they didn't package it well and it's using configure.py to install. So …

Continue reading »

Only use worker when required on heroku with Django/Python

For a mobile project I required a background worker which sents an email with 300 generated QR codes zipped together as attachment. This costs quite some time so we need a background worker to execute this task.

I wanted to achieve the following result:

  • When the user wants to generate …

Continue reading »

Using Sendgrid with Django on Heroku (How to find your Sendgrid password on Heroku)

While setting up sentgrid I was searching for my password of sendgrid, but coudn't find it. You can get it in the following way:

heroku config --long

Which will show the parameters:
SENDGRID_PASSWORD, SENDGRID_USERNAME

After you get your username don't forget to add it to django settings:

EMAIL\_HOST = 'smtp …

Continue reading »

Django Custom View Decorator with Arguments

To make my life easier I made a simple decorator which checks if the parameters are present in the request.POST or request.GET and returns a response if they are not.

It accepts a list of parameters in string format and will loop through each parameter to check if …

Continue reading »

Simple function to return json in Django

Just a small code snippet I use when I need to return json, comments are welcomed.

from django.http import HttpResponse  
from django.utils import simplejson as json

def json_response(dict_to_convert_to_json):  
    return HttpResponse(json.dumps(dict_to_convert_to_json),
                        mimetype="application/json")

To use it in your view you just do it this …

Continue reading »

Trying to install scrapy with pip lxml error: command 'gcc' failed with exit status 1

Just tried to install scrapy with pip / easy_install, but when it comes to installing lxml it will give the following error:

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml …

Continue reading »

How to install Setuptools to a specific python version

To install easy_install for a specific python version. I just installed from source and used the python version you want to install setuptools too. I used the following steps in Ubuntu 11.04 with Python 2.5 and Python 2.7 installed. The following commands will install setuptools to python …

Continue reading »