Skip to content
Newer
Older
100644 64 lines (51 sloc) 1.4 KB
8775fee @peterbe using mongodb now
authored
1 import datetime
876d6a6 @peterbe adding so it randomly picks a funny background image
authored
2 from pymongo.objectid import ObjectId
8775fee @peterbe using mongodb now
authored
3 from mongolite import Connection, Document
4 connection = Connection()
5
1047afb @peterbe saving tweeters to mongo
authored
6 class BaseDocument(Document):
7 skeleton = {
8 'modify_date': datetime.datetime
9 }
10
11 default_values = {'modify_date': datetime.datetime.utcnow}
12
13 def save(self, *args, **kwargs):
14 if '_id' in self and kwargs.get('update_modify_date', True):
15 m = datetime.datetime.utcnow()
16 self['modify_date'] = m
17 super(BaseDocument, self).save(*args, **kwargs)
18
19
8775fee @peterbe using mongodb now
authored
20 @connection.register
1047afb @peterbe saving tweeters to mongo
authored
21 class User(BaseDocument):
8775fee @peterbe using mongodb now
authored
22 __collection__ = 'users'
c3e5ea7 @peterbe implementing new everyone I follow feature
authored
23 skeleton = {
8775fee @peterbe using mongodb now
authored
24 'username': unicode,
25 'access_token': dict,
26 'modify_date': datetime.datetime
27 }
c3e5ea7 @peterbe implementing new everyone I follow feature
authored
28 optional = {
29 'user_id': int,
30 }
8775fee @peterbe using mongodb now
authored
31
32
1047afb @peterbe saving tweeters to mongo
authored
33 @connection.register
34 class Tweeter(BaseDocument):
35 __collection__ = 'tweeters'
36 skeleton = {
37 'user_id': int,
38 'username': unicode,
39 'name': unicode,
40 'followers': int,
41 'following': int,
42 'ratio': float,
43 'last_tweet_date': datetime.datetime,
44 }
45 optional = {
46 'ratio_rank': int,
47 }
48
49 def set_ratio(self):
50 self['ratio'] = 1.0 * self['followers'] / max(self['following'], 1)
876d6a6 @peterbe adding so it randomly picks a funny background image
authored
51
52 # def calculate_ratio_rank(self, db):
53
54
55
56 @connection.register
57 class Following(BaseDocument):
58 __collection__ = 'following'
59 skeleton = {
60 'user': unicode,
61 'follows': unicode,
62 'following': bool,
63 }
Something went wrong with that request. Please try again.