simple mysql dao class for python

This is DAO class for working with mysql which may help you if you need do something quickly and don't want to use ORM:

# encoding: utf8

import MySQLdb

class Singleton(object):
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
return cls._instance


class DAO(Singleton):
def __init__(self):
"""
Inits MySQL connection
"""
self._connect()
return


def _connect(self):
"""
Creates connection
"""
self.connection = MySQLdb.connect(host="localhost", \
user="mysql_user", \
passwd="mysql_password", \
db="mysql_db", \
port=3306)
return


def _get_cursor(self):
"""
Pings connection and returns cursor
"""
try:
self.connection.ping()
except:
self._connect()
return self.connection.cursor()


def get_row(self, query):
"""
Fetchs one row
"""
cursor = self._get_cursor()
cursor.execute(query)
row = cursor.fetchone()
cursor.close()
return row


def get_rows(self, query):
"""
Fetchs all rows
"""
cursor = self._get_cursor()
cursor.execute(query)
rows = cursor.fetchall()
cursor.close()
return rows


def execute(self, query):
"""
Executes query for update, delete
"""
cursor = self._get_cursor()
cursor.execute(query)
cursor.close()
return

How to fetch feed url from web page in python

Easyly.


import urllib2
from lxml import etree

webPageUrl = "http://www.osmonov.com"
try:
opener = urllib2.build_opener()
response = opener.open(webPageUrl)
if response.headers.__getitem__('Content-Type').startswith('text/html'):
html_element = etree.HTML( response.read() )
link_elements =html_element.findall('.//link[@rel="alternate"]')
if link_elements.__len__() > 0:
# so we can have several link tags, i use just the first
feedUrl = link_elements.__getitem__(0).get('href')

except urllib2.URLError:
# commander! do something violent

hi.kg API

Dear Sudar'! ^_^
Please! Try out hi.kg API.
It's implemented on json-rpc.
url: http://hi.kg/api.php
method: shorten
argument: url
return: shorten_url

Some examples:


<?php

require_once("jsonRPCClient.php");
$client = new jsonRPCClient("http://hi.kg/api.php");

echo $client->shorten( "http://www.osmonov.com");

?>



Also JSON-RPC PHP lib here

Have a nice shortening!

Адмирал

Представляете, квартиры в доме на месте ресторана "Адмирал" уже раскупили. Вот как расположение имеет значение. Кста, комплекс из двух жилых и офисных зданий сохранит старое название.

Trip to Sary-Chelek.

Sary-Chelek is a lake in the south of Kyrgyzstan. Recently we had trip there. "Bishkek-Osh" highway connects the north and the south of my country. The highest point in road, ~3300 meters altitude, is Tyo-Ashuu pass. It was cold there but it's beautiful all seasons.

We had breakfast in Ala-Bel pass near Chychkan river and found nice car.

Water of Toktogul reservoir twists generators of Toktogul hydro electric station which powers all country with electricity.

After Toktogul reservoir Naryn river becomes blue-green color cause of depth.

Sary-Chelek is in ~1800 altitude. At the entrance to lake's plain there are place called Panorama.

At place.



Find the difference in pictures. :)





View all photos in album

Soon I'll post photos from the second trip to Sary-Chelek.

ме сага

(12:06:41 AM) Никита Федяшев: Калыс, напиши что-нибудь в блог )
(12:06:46 AM) Никита Федяшев: почитать хочется )

читай

блог не открывается ><

фигня какая-то.
http://www.blogger.com и *.blogspot.com открываются, а custom домены (http:/www.osmonov.com, http://www.abraliev.com) с акнета нет. с хомы открывается. причем, пинги нормальные, коннект происходит, firefox грит waiting for ... и усё.

Звуки-муки

Открыл для себя, что гул от кулеров компьютера сильно мешает работать тем, что я засыпаю под его монотонные звуки. Когда компьютер включенный, этот звук незаметен, но когда выключаешь комп и наступает тишина, уши и мозг испытывают такое облегчение.

Если у тебя есть такая проблема, то быстро решай его. Выноси системник на балкон, приобретай ноут, ставь жидкостное охлаждение, что угодно, но работать ты должен в тишине.

Вот так вот.

УНЬЮЮЮЮЮЮЮЮЮАААААГГГЪХ!!!!!

НЯЯЯЯЯЯЯЯЯЯЯРГЪЪЪЪХ!!!!
КУКЛЫ ДЕЛАЮТ МЕНЯ ДОБРЕЙ!!!
ДОБРАЯ ДЕСА ЛЮБИТ ДЕТЕЙ!!!
ШИНКА И ХИНА ПОССОРИЛИСЬ С НЕЙ!!1
НО ВСЕ ПОМИРИЛИСЬ И СТАЛО ВЕСЕЛЕЙ!!!!!
УНЬЮЮЮЮЮЮЮЮЮ!!!!!
Я ЧУВСТВУЮ ЗАПАХ РОЗ!!!!!
УНЬЮЮЮЮЮЮЮЮЮАААААГГГЪХ!!!!!
Я ЧУВСВТУЮ ЗАПАХ РОЗ!!!!!
НАДО ОБНЯТЬ И ЛЮБИТЬ ДО СЛЁЗ!!!!!
НОЧЬЮ ВНЕЗАПНО! В ЗЕРКАЛЕ ТУМАН!
СУЙГИНТА ЗАДУМАЛА ХИТРЫ ОБМАН!!!!
РУТНАЯ ЛАМПА РОЗЫ СИЛЬНЕЙ!!!
НО ВСЕ ПОМИРИЛИСЬ И СТАЛО ВЕСЕЛЕЙ!!!!
УНЬЮЮЮЮЮЮЮЮЮЮЮЮ!!!!!111!!
Я ЧУВСТВУЮ ЗАПАХ РОЗ!!!!!1!
УНЬЮЮЮЮЮЮЮЮЮАААААГГГЪХ!!!!!!!
Я ЧУВСТВУЮ ЗАПАХ РОЗ!!!!!!
НАДО ОБНЯТЬ И ЛЮБИТЬ ДО СЛЁЗ!!!!!!!!!!

отсюда http://nya.sh/post/4109

WebMoney in AUB terminals

Good news, friends!!!

Now it's possible to buy webmoney (WMZ, WMR) in terminals of AsiaUniversalBank.