This repository has been archived by the owner on May 28, 2024. It is now read-only.
forked from pcjl/mattermost-coffeebot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpair.py
59 lines (46 loc) · 1.7 KB
/
pair.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
from mattermostdriver import Driver
from coffeebot.logger import logger
from coffeebot import config, database, utils
def create_driver():
logger.info("Creating Mattermost Driver...")
driver_options = {
'url': config.URL,
'login_id': config.USERNAME,
'password': config.PASSWORD,
'port': config.PORT
}
return Driver(driver_options)
def authenticate(driver):
logger.info("Authenticating...")
driver.login()
driver.users.get_user('me')
logger.info("Successfully authenticated.")
def get_members(driver):
logger.info("Retrieving Coffee Buddies participants...")
members = utils.get_channel_members(
driver, config.TEAM_NAME, config.CHANNEL_NAME)
logger.info("Successfully retrieved Coffee Buddies participants.")
return members
def prepare_db(session, members):
logger.info("Preparing participants database...")
utils.create_users(session, members)
utils.create_pairs(session, members)
logger.info("Succesfully prepared participants database.")
def pair(session, driver, members):
logger.info("Pairing Coffee Buddies participants...")
pairs = utils.get_pairs(session, members)
logger.debug(pairs)
logger.info("Successfully paired Coffee Buddies participants.")
logger.info("Messaging paired Coffee Buddies participants...")
utils.message_pairs(driver, pairs)
logger.info("Successfully messaged paired Coffee Buddies participants.")
def main():
session = database.init_session()
driver = create_driver()
authenticate(driver)
members = get_members(driver)
logger.debug(members)
prepare_db(session, members)
pair(session, driver, members)
if __name__ == '__main__':
main()