repl.it
@tml/

CharmingDisloyalInstance

Python

No description

fork
loading
Files
  • main.py
  • example.db
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pendulum
from pprint import pprint
import sqlite3

conn = sqlite3.connect(':memory:')
conn.set_trace_callback(print)



c = conn.cursor()
c.execute("""
create table sample(start text, end text, title varchar, location varchar)
""")

def create_new_row(c, start, end, title='Event #1', location='North America'):
    c.execute("""
    insert into sample(start, end, title, location) values(
        start=:start, end=:end, title=:title, location=:location
    )
    """.format(start.isoformat(), end.isoformat(), title, location))

create_new_row(c, pendulum.now().subtract(days=1), pendulum.now().add(days=6))
conn.commit()
create_new_row(c, pendulum.now().subtract(days=3, hours=5, minutes=17), pendulum.now().add(days=2, hours=2), 'Event #2')
conn.commit()
create_new_row(c, pendulum.now().add(days=3), pendulum.now().add(days=5), 'Event #3')
conn.commit()

c.execute("select * from sample where start < date('now')")
rows = []
for row in c.fetchall():
    rows.append((row[0], pendulum.parse(row[0]), row[1], pendulum.parse(row[1]), row[2], row[3]))
pprint(rows)

cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age})