portail/scripts/common/rocketchathelper.py

49 lines
1.5 KiB
Python
Raw Normal View History

2019-09-01 10:50:21 +00:00
from rocketchat_API.rocketchat import RocketChat
2019-09-01 17:21:42 +00:00
from datetime import datetime
2019-09-01 10:51:41 +00:00
import os
2019-09-01 10:50:21 +00:00
def Connection():
return RocketChat(None, None, auth_token= os.environ['ROCKETCHAT_AUTH'], user_id= os.environ['ROCKETCHAT_USERID'], server_url=os.environ['ROCKETCHAT_SERVER'])
2019-09-01 10:03:04 +00:00
def getNodesOrigin(channel):
nodes = []
if 'description' not in channel:
nodes.append("global")
return nodes
if channel['description'].find("#projet") != -1:
nodes.append("project")
if channel['description'].find("#democratie") != -1:
nodes.append("democratie")
if channel['description'].find("#ecologie") != -1:
nodes.append("ecologie")
if channel['description'].find("#technologie") != -1:
nodes.append("technologie")
if not nodes:
nodes.append("global")
return nodes
def getAllChannels(rocket):
index = 0
allChannels = []
while True:
channels = rocket.channels_list(offset= index).json()
allChannels.extend([ channel for channel in channels['channels'] if 'archived' not in channel])
if channels['count'] + channels['offset'] >= channels['total']:
break
index += channels['count']
return allChannels
2019-09-01 17:21:42 +00:00
def getAllMessages(rocket, roomid, begindate=None, enddate=datetime.now()):
2019-09-01 14:52:19 +00:00
result = rocket.channels_history(roomid, oldest= begindate, latest= enddate, count= 10000).json()
if result["success"]:
#filter system message
return list(filter(lambda message: "t" not in message, result["messages"]))
return None
2019-09-01 10:03:04 +00:00
if __name__ == "__main__":
print("Ce fichier est juste une librarie")