This repository was archived by the owner on Dec 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
108 lines (90 loc) · 3.35 KB
/
models.py
File metadata and controls
108 lines (90 loc) · 3.35 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import datetime
from sqlalchemy import BigInteger, SmallInteger, Column, ForeignKey, UnicodeText
from sqlalchemy.orm import backref, relationship
from manager import db
class Category(db.Model):
id = Column(BigInteger, primary_key=True)
name = Column(UnicodeText(), nullable=True)
class Guide(db.Model):
id = Column(BigInteger, primary_key=True)
date = Column(BigInteger, nullable=False)
url = Column(UnicodeText(), nullable=True)
title = Column(UnicodeText(), nullable=True)
image_guid = Column(UnicodeText(), nullable=True)
category_id = Column(BigInteger, ForeignKey(Category.id), nullable=False)
category = relationship(
Category,
backref=backref('guides', lazy=True, cascade="all,delete"),
primaryjoin=Category.id == category_id,
)
@property
def image(self):
img = self.image_guid
if not img:
return ''
url = f'https://guide-images.cdn.ifixit.com/igi/{img}.full'
return url
def get_json(self):
return {
'url': self.url,
'image': self.image,
'title': self.title,
'category': self.category.name
}
class Icecat(db.Model):
id = Column(BigInteger, primary_key=True)
date = Column(BigInteger, nullable=False)
url = Column(UnicodeText(), nullable=True)
title = Column(UnicodeText(), nullable=True)
image = Column(UnicodeText(), nullable=True)
brand = Column(UnicodeText(), nullable=True)
brand_logo = Column(UnicodeText(), nullable=True)
product_name = Column(UnicodeText(), nullable=True)
product_serie = Column(UnicodeText(), nullable=True)
long_product_name = Column(UnicodeText(), nullable=True)
brand_part_code = Column(UnicodeText(), nullable=True)
chassis = Column(UnicodeText(), nullable=True)
family = Column(UnicodeText(), nullable=True)
@property
def pdf(self):
id = self.id
if not id:
return ''
url = f'https://icecat.biz/rest/product-pdf?productId={id}&lang=en'
return url
@property
def datetime(self):
return datetime.datetime.fromtimestamp(self.date)
@property
def date_str(self):
return datetime.datetime.fromtimestamp(self.date).strftime("%d/%m/%Y")
def get_json(self):
return {
'url': self.url,
'logo': self.brand_logo,
'title': self.title,
'pdf': self.pdf,
"image": self.image,
}
class Laer(db.Model):
id = Column(BigInteger, primary_key=True)
code = Column(UnicodeText(), nullable=True)
metal = Column(SmallInteger(), nullable=True)
plastic_post_consumer = Column(SmallInteger(), nullable=True)
plastic_post_industry = Column(SmallInteger(), nullable=True)
class computer_laer(db.Model):
id = Column(BigInteger, primary_key=True)
title = Column(UnicodeText(), nullable=False)
laer_id = Column(BigInteger, ForeignKey(Laer.id), nullable=False)
laer = relationship(
Laer,
backref=backref('computers', lazy=True, cascade="all,delete"),
primaryjoin=Laer.id == laer_id,
)
def get_json(self):
return {
'code': self.laer.code,
'metal': self.laer.metal,
'plastic_post_consumer': self.laer.plastic_post_consumer,
'plastic_post_industry': self.laer.plastic_post_industry
}