This repository has been archived by the owner on Nov 11, 2021. It is now read-only.
forked from SeckMohameth/hopeful-cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasewish.py
executable file
·58 lines (51 loc) · 1.57 KB
/
basewish.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python3
"""
Wish sqlalchemy object
"""
from datetime import datetime
import uuid
from sqlalchemy import Column, String
from sqlalchemy.ext.declarative import declarative_base
from storage import storage_instance
time = "%Y-%m-%d|%H:%M:%S"
Base = declarative_base()
class Wish(Base):
"""
The Wish class which provides the skeleton of a wish
"""
"""
sqlalchemy variable mappings
"""
__tablename__ = 'allwishes_test'
wish_id = Column(String(128), nullable=False, primary_key=True)
name = Column(String(128), nullable=False)
state = Column(String(128), nullable=False)
country = Column(String(128), nullable=False)
star_name = Column(String(128), nullable=False)
wish = Column(String(128), nullable=False)
creation_time = Column(String(128), nullable=False)
def __init__(self, name, state, country, star_name, wish):
"""
Class constructor
"""
self.wish_id = str(uuid.uuid4())
self.name = name
self.state = state
self.country = country
self.star_name = star_name
self.wish = wish
self.creation_time = datetime.strftime(datetime.utcnow(), time)
def save(self):
"""
Use storage engine to save self instance
"""
storage_instance.new(self)
storage_instance.save()
def to_dict(self):
"""
Return dictionary representation
"""
dict_copy = self.__dict__.copy()
if '_sa_instance_state' in dict_copy:
del dict_copy['_sa_instance_state']
return dict_copy