disable_user_daily_push.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # vim:fenc=utf-8
  4. """
  5. Agent在和用户对话过程中可能识别到用户不想再收消息,Agent会做识别,但需将信息同步至Growth Manager
  6. """
  7. import sys
  8. import os
  9. import json
  10. import pymysql.cursors
  11. sys.path.append(os.curdir)
  12. import configs
  13. from user_manager import MySQLUserManager, MySQLUserRelationManager
  14. if __name__ == '__main__':
  15. config = configs.get()
  16. user_db_config = config['storage']['user']
  17. staff_db_config = config['storage']['staff']
  18. user_manager = MySQLUserManager(user_db_config['mysql'], user_db_config['table'], staff_db_config['table'])
  19. wecom_db_config = config['storage']['user_relation']
  20. user_relation_manager = MySQLUserRelationManager(
  21. user_db_config['mysql'], wecom_db_config['mysql'],
  22. config['storage']['staff']['table'],
  23. user_db_config['table'],
  24. wecom_db_config['table']['staff'],
  25. wecom_db_config['table']['relation'],
  26. wecom_db_config['table']['user']
  27. )
  28. sql = f"SELECT wxid, name, profile_data_v1 FROM {user_manager.table_name} WHERE profile_data_v1 IS NOT NULL"
  29. users = user_manager.db.select(sql, pymysql.cursors.DictCursor)
  30. for user in users:
  31. profile = json.loads(user['profile_data_v1'])
  32. if profile.get('interaction_frequency', None) == 'stopped':
  33. user_id = user['wxid']
  34. user_name = user['name']
  35. print(f'update user[{user_id}] {user_name}: stop group message')
  36. sql = f"UPDATE we_com_user SET group_msg_disabled = 1 WHERE union_id = %s"
  37. rows = user_relation_manager.wecom_db.execute(sql, (user_id, ))
  38. print(f'affected rows: {rows}')