Last active
March 10, 2020 18:47
-
-
Save Porter97/39801fd94955ba0508edbf2f5c6ee8b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#... | |
Content(db.Model): | |
#... | |
image = db.Column(db.String, default=None) | |
#... | |
def add_to_stream(self): | |
#... | |
client.feed("Collections", str(self.collection_id)).add_activity({'actor': client.users.create_reference(str(self.collection.author_id)), | |
'verb': 'post', | |
'object': 'Content:' + str(self.id), | |
'post': self.title, | |
'url': self.url, | |
'image': self.image, | |
'description': self.description, | |
'time': self.timestamp, | |
'collection': { | |
'id': self.collection_id, | |
'name': self.collection.name | |
}, | |
'foreign_id': 'Content:' + str(self.id) | |
}) | |
#... | |
def add_fields_to_stream(self, **kwargs): | |
# Update Stream Feed with new fields | |
try: | |
client = stream.connect(current_app.config['STREAM_API_KEY'], current_app.config['STREAM_SECRET']) | |
client.activity_partial_update(foreign_id='Content:' + str(self.id), | |
time=self.timestamp, | |
set=kwargs | |
) | |
return True | |
except: | |
return False | |
def remove_fields_from_stream(self, **kwargs): | |
# Update Stream with removed fields | |
try: | |
client = stream.connect(current_app.config['STREAM_API_KEY'], current_app.config['STREAM_SECRET']) | |
client.activity_partial_update(foreign_id='Content:' + str(self.id), | |
time=self.timestamp, | |
unset=kwargs | |
) | |
return True | |
except: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment