-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
35 lines (28 loc) · 856 Bytes
/
models.py
File metadata and controls
35 lines (28 loc) · 856 Bytes
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
from datetime import datetime
from config import Config
from pony.orm import Database, PrimaryKey, Required
db = Database()
class Articles(db.Entity):
id = PrimaryKey(int, auto=True)
article_id = Required(str, unique=True)
pub_date = Required(datetime)
link = Required(str)
title = Required(str)
summary = Required(str)
def db_setup():
"""Connect to the db and create it if it doesn't already exists"""
data = Config.DB_URL.split("/")
database = data[-1]
credentials = data[2].split("@")
host, port = credentials[-1].split(":")
user, password = credentials[0].split(":")
db.bind(
provider="postgres",
user=user,
password=password,
host=host,
database=database,
port=port,
sslmode="require",
)
db.generate_mapping(create_tables=True)