Posted by & filed under python.

import smtplib
from email.mime.text import MIMEText
                
msg = MIMEText('Hello, this is message body')
              
msg['Subject'] = 'Hello'
msg['From'] = 'belstudent@yandex.ru'
msg['To'] = 'petrov@petrov.ru'
s = smtplib.SMTP()
s.connect('http://smtp.myhost.com') # соединяемся с SMTP сервером
s.login('login','password') # авторизуемся
s.sendmail('belstudent@yandex.ru', ['petrov@petrov.ru'], msg.as_string())
s.quit()

Posted by & filed under python.

import time
def _findCountDays(dateString1, dateString2):
        dateString1=dateString1[0:10] # вырезаем такое "2010-03-01"
        dateString2=dateString2[0:10]
        t1=time.mktime(time.strptime(dateString1, '%Y-%m-%d'))
        t2=time.mktime(time.strptime(dateString2, '%Y-%m-%d'))
        t=round((t2-t1)/(60*60*24))+1
        return int(t)

dateString1 и dateString2 — это timestamp из PostgreSQL

Posted by & filed under PostgreSQL.

Пример1:

PREPARE fooplan (int, text, bool, numeric) AS
    INSERT INTO foo VALUES($1, $2, $3, $4);
EXECUTE fooplan(1, 'Hunter Valley', 't', 200.00);

Пример2:

PREPARE usrrptplan (int, date) AS
    SELECT * FROM users u, logs l WHERE u.usrid=$1 AND u.usrid=l.usrid
    AND l.date = $2;
EXECUTE usrrptplan(1, current_date);

Posted by & filed under PostgreSQL.

Писал хранимую функцию, пока не указал SETOF никак не мог вывести результат назад