import os
import psycopg2
from psycopg2.extras import DictCursor
import datetime
from timber.utils import Channel, Message


def get_db_cursor(connect_stmt):
    c = psycopg2.connect(connect_stmt)
    return c.cursor(cursor_factory=DictCursor)


def get_channels(connect_stmt, current, date):
    c = get_db_cursor(connect_stmt)
    start_of_day = datetime.datetime(date.year, date.month, date.day, 0, 0, 0).isoformat()
    end_of_day = datetime.datetime(date.year, date.month, date.day, 23, 59, 59).isoformat()
    c.execute('SELECT lower(channel) FROM chanlogs WHERE timestamp>%s::timestamp AND timestamp<%s::timestamp GROUP BY lower(channel) ORDER BY lower(channel) ASC;', (start_of_day, end_of_day))
    res = c.fetchall()
    c.close()
    channels = []
    for chan in res:
        name = chan[0]
        channels = channels + [Channel(name, name==current),]
    return channels


def get_messages(connect_stmt, channel, date):
    c = get_db_cursor(connect_stmt)
    start_of_day = datetime.datetime(date.year, date.month, date.day, 0, 0, 0).isoformat()
    end_of_day = datetime.datetime(date.year, date.month, date.day, 23, 59, 59).isoformat()
    c.execute('SELECT * FROM chanlogs WHERE lower(channel)=lower(%s) AND timestamp>%s::timestamp AND timestamp<%s::timestamp;', (channel, start_of_day, end_of_day))
    res = c.fetchall()
    c.close()
    print(repr(c.query))
    messages = []
    for msg in res:
        messages = messages + [Message(msg),]
    return messages

4d29a1b61afd5c1631b2429ec7d3cc0c92f872d1
<mask token>

<mask token>


def get_db_cursor(connect_stmt):
    c = psycopg2.connect(connect_stmt)
    return c.cursor(cursor_factory=DictCursor)


def get_channels(connect_stmt, current, date):
    c = get_db_cursor(connect_stmt)
    start_of_day = datetime.datetime(date.year, date.month, date.day, 0, 0, 0
        ).isoformat()
    end_of_day = datetime.datetime(date.year, date.month, date.day, 23, 59, 59
        ).isoformat()
    c.execute(
        'SELECT lower(channel) FROM chanlogs WHERE timestamp>%s::timestamp AND timestamp<%s::timestamp GROUP BY lower(channel) ORDER BY lower(channel) ASC;'
        , (start_of_day, end_of_day))
    res = c.fetchall()
    c.close()
    channels = []
    for chan in res:
        name = chan[0]
        channels = channels + [Channel(name, name == current)]
    return channels


<mask token>

<mask token>


def get_db_cursor(connect_stmt):
    c = psycopg2.connect(connect_stmt)
    return c.cursor(cursor_factory=DictCursor)


def get_channels(connect_stmt, current, date):
    c = get_db_cursor(connect_stmt)
    start_of_day = datetime.datetime(date.year, date.month, date.day, 0, 0, 0
        ).isoformat()
    end_of_day = datetime.datetime(date.year, date.month, date.day, 23, 59, 59
        ).isoformat()
    c.execute(
        'SELECT lower(channel) FROM chanlogs WHERE timestamp>%s::timestamp AND timestamp<%s::timestamp GROUP BY lower(channel) ORDER BY lower(channel) ASC;'
        , (start_of_day, end_of_day))
    res = c.fetchall()
    c.close()
    channels = []
    for chan in res:
        name = chan[0]
        channels = channels + [Channel(name, name == current)]
    return channels


def get_messages(connect_stmt, channel, date):
    c = get_db_cursor(connect_stmt)
    start_of_day = datetime.datetime(date.year, date.month, date.day, 0, 0, 0
        ).isoformat()
    end_of_day = datetime.datetime(date.year, date.month, date.day, 23, 59, 59
        ).isoformat()
    c.execute(
        'SELECT * FROM chanlogs WHERE lower(channel)=lower(%s) AND timestamp>%s::timestamp AND timestamp<%s::timestamp;'
        , (channel, start_of_day, end_of_day))
    res = c.fetchall()
    c.close()
    print(repr(c.query))
    messages = []
    for msg in res:
        messages = messages + [Message(msg)]
    return messages

import os
import psycopg2
from psycopg2.extras import DictCursor
import datetime
from timber.utils import Channel, Message


def get_db_cursor(connect_stmt):
    c = psycopg2.connect(connect_stmt)
    return c.cursor(cursor_factory=DictCursor)


def get_channels(connect_stmt, current, date):
    c = get_db_cursor(connect_stmt)
    start_of_day = datetime.datetime(date.year, date.month, date.day, 0, 0, 0
        ).isoformat()
    end_of_day = datetime.datetime(date.year, date.month, date.day, 23, 59, 59
        ).isoformat()
    c.execute(
        'SELECT lower(channel) FROM chanlogs WHERE timestamp>%s::timestamp AND timestamp<%s::timestamp GROUP BY lower(channel) ORDER BY lower(channel) ASC;'
        , (start_of_day, end_of_day))
    res = c.fetchall()
    c.close()
    channels = []
    for chan in res:
        name = chan[0]
        channels = channels + [Channel(name, name == current)]
    return channels


def get_messages(connect_stmt, channel, date):
    c = get_db_cursor(connect_stmt)
    start_of_day = datetime.datetime(date.year, date.month, date.day, 0, 0, 0
        ).isoformat()
    end_of_day = datetime.datetime(date.year, date.month, date.day, 23, 59, 59
        ).isoformat()
    c.execute(
        'SELECT * FROM chanlogs WHERE lower(channel)=lower(%s) AND timestamp>%s::timestamp AND timestamp<%s::timestamp;'
        , (channel, start_of_day, end_of_day))
    res = c.fetchall()
    c.close()
    print(repr(c.query))
    messages = []
    for msg in res:
        messages = messages + [Message(msg)]
    return messages

import os
import psycopg2
from psycopg2.extras import DictCursor
import datetime
from timber.utils import Channel, Message


def get_db_cursor(connect_stmt):
    c = psycopg2.connect(connect_stmt)
    return c.cursor(cursor_factory=DictCursor)


def get_channels(connect_stmt, current, date):
    c = get_db_cursor(connect_stmt)
    start_of_day = datetime.datetime(date.year, date.month, date.day, 0, 0, 0).isoformat()
    end_of_day = datetime.datetime(date.year, date.month, date.day, 23, 59, 59).isoformat()
    c.execute('SELECT lower(channel) FROM chanlogs WHERE timestamp>%s::timestamp AND timestamp<%s::timestamp GROUP BY lower(channel) ORDER BY lower(channel) ASC;', (start_of_day, end_of_day))
    res = c.fetchall()
    c.close()
    channels = []
    for chan in res:
        name = chan[0]
        channels = channels + [Channel(name, name==current),]
    return channels


def get_messages(connect_stmt, channel, date):
    c = get_db_cursor(connect_stmt)
    start_of_day = datetime.datetime(date.year, date.month, date.day, 0, 0, 0).isoformat()
    end_of_day = datetime.datetime(date.year, date.month, date.day, 23, 59, 59).isoformat()
    c.execute('SELECT * FROM chanlogs WHERE lower(channel)=lower(%s) AND timestamp>%s::timestamp AND timestamp<%s::timestamp;', (channel, start_of_day, end_of_day))
    res = c.fetchall()
    c.close()
    print(repr(c.query))
    messages = []
    for msg in res:
        messages = messages + [Message(msg),]
    return messages
