This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
70 lines (56 loc) · 1.72 KB
/
model.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
59
60
61
62
63
64
65
66
67
68
69
70
from peewee import *
import datetime
import random
db = SqliteDatabase('adminfest.db')
def gen_hex_colour_code():
return ''.join([random.choice('0123456789ABCDEF') for x in range(6)])
class BaseModel(Model):
class Meta:
database = db
class User(BaseModel):
"""
ORM model of the User table
"""
#username = CharField(unique=True)
user_id = BigIntegerField(primary_key=True)
beers = IntegerField(default=0)
class BeerCode(BaseModel):
"""
ORM model of the BeerCode table
"""
beer_code = TextField(unique=True)
user = ForeignKeyField(User, null=True, related_name='beer_codes')
timestamp = DateTimeField(default="")
used = BooleanField(default=False)
class Tweet(BaseModel):
"""
ORM model of the Tweet table
"""
user = ForeignKeyField(User, related_name='tweets')
status_id = BigIntegerField(unique=True)
text = TextField(default="")
json = TextField(default="")
created_date = DateTimeField(default=datetime.datetime.now)
is_published = BooleanField(default=True)
processed = BooleanField(default=False)
process_try = IntegerField(default=0)
beer_code = TextField(default="")
if __name__ == "__main__":
try:
User.create_table()
except OperationalError:
print("User table already exists!")
try:
BeerCode.create_table()
except OperationalError:
print("BeerCode table already exists!")
try:
Tweet.create_table()
except OperationalError:
print("Tweet table already exists!")
#generate codes
with db.atomic():
for n in range(200):
code = gen_hex_colour_code()
beer_code = BeerCode.create(beer_code=code)
beer_code.save()