This repository has been archived by the owner on Feb 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodels.py
76 lines (55 loc) · 2.19 KB
/
models.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
71
72
73
74
from peewee import *
db = SqliteDatabase('slack.db')
class BaseModel(Model):
"""
Just lets us not repeat ourselves too much.
"""
class Meta:
database = db
class Slack(BaseModel):
"""
This fulfills the legacy needs from slackToDB.py from the deprecated
`slack-urls` repo and is only populated if a `--legacy` argument is passed to the importer.
For details see the legacy commands documentation:
../README.md#legacy-commands
"""
channel = TextField()
channel_date = TextField()
data = TextField()
class SlackChannel(BaseModel):
"""
Stores key information about Slack channels.
There is more info available in channels.json but for our purposes
most likely only the ID and name are needed.
Having channel_id null isn't a great idea, but so long as we're finding channels
that aren't in channels.json I'm not sure what we can do about it.
To compensate somewhat, we'll index name and use it as a sort-of key.
"""
channel_id = CharField(null=True)
name = CharField(unique=True, index=True)
private_group = BooleanField(default=False)
private_messages = BooleanField(default=False)
class SlackUser(BaseModel):
"""
Stores key information about Slack users.
More information is available in users.json
but for our purposes we should only need the ID, name and real_name.
"""
user_id = CharField(primary_key=True)
name = CharField()
real_name = CharField()
class SlackMessage(BaseModel):
"""
Stores key info from Slack messages.
Note we are not storing all info that may be attached to a message.
We also do not currently resolve internal link references to users, channels, etc.
To do so, we'll need to hunt and translate the <#C02A80ZHG> type references.
Also note the `resolution=1e6` on TimestampField.
That's because Peewee's TimestampField implementation strips milliseconds by default,
but there's a workaround: https://github.com/coleifer/peewee/issues/1747
"""
channel_name = CharField()
user = ForeignKeyField(SlackUser, backref='messages')
message = TextField()
date = DateField()
ts = TimestampField(resolution=1e6)