Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Saturday, July 30, 2016

PostgreSQL + SQLAlchemy: accent and case insensitive search

Ignore accents & case

Maybe you know what it's like: you store UTF-8 encoded text/strings in your database but you want to be able to execute an ASCII based query ignoring all those pesky diacritics. It's not always straightforward.

The following tutorial is a compilation of 3 StackOverflow posts and it describes how to perform an accent and case insensitive search with PostgreSQL and SQLAlchemy.

Thursday, February 11, 2016

Tor IP changing and web scraping

Anonymous web scraping

Many of us who scrape web pages, be it for fun, data, love or something else, are concerned about anonymity. Well, not anonymity per se, we just don't want our IP blacklisted.

Many of us choose Tor and its network to achieve our goal. In this post I am going to share my experience and observations using Tor + Privoxy for Python driven web scraping.

Tuesday, October 20, 2015

SyntaxHighlighter on Blogger and an unexpected output in a Python snippet

Syntax highlighting on Blogger

I was looking for an easy way to add syntax highlighting to my code snippets here on Blogger. Yes, you can embed Gist code snippets, but this approach is not ideal always. There must be a better way for doing this. And of course there is!

I found SyntaxHighlighter after a few minutes of googling. It does exactly what I want, it's easy to use, supports many syntaxes and is nicely documented. But, for some Python code, it is doing a bit more than it should.

Thursday, May 14, 2015

Python 3.x and packaging issues

Greetings to ...

We will create a very simple Python 3.4 command line greeting app. It will take two arguments. An user name and an effect (if any) that should be applied to the user name. Then it will print out a greeting message. That's all.

While implementing and testing, we will run into and solve imports and packaging issues that may occur when someone used to Python 2.x is creating, testing and distributing a Python 3.x application containing a sub-package.

Sunday, February 1, 2015

SQLite to Spatialite

Preface

Imagine that you have a SQLite database which besides other data has latitude and longitude stored as separate [floating point] columns representing the position in WGS-84 (or any other SRID). And at some point you would want to geographically analyse your data in your favorite desktop GIS ( QGIS for example). It would not be possible until the database is spatially enabled, or in other words, converted to a spatial database.

Sunday, January 18, 2015

Python 2.x and Unicode

Preface

I was working [and still have some work to do] on a web-scraping project for last couple of months. I stared this project because I wanted to get more comfortable with Python and some nonstandard libraries like Requests and SQLAlchemy.
Python 2.7.6 was chosen to scrape websites which were using UTF-8 character set. That's how it all began.