-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_users.py
executable file
·35 lines (30 loc) · 1001 Bytes
/
generate_users.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
#! /bin/python3
import odoolib
import configparser
import random
import uuid
import hashlib
config = configparser.ConfigParser()
config.read("conf.ini")
connection = odoolib.get_connection(
hostname=config["odoo"]["url"],
database=config["odoo"]["db"],
login=config["odoo"]["user"],
password=config["odoo"]["pass"],
port=443,
protocol="jsonrpcs",
)
company_model = connection.get_model('res.company')
user_model = connection.get_model('res.users')
key_model = connection.get_model('res.users.apikeys')
# clean old api keys
key_ids = key_model.search([('user_id', '>', 10)])
if key_ids:
key_model.unlink(key_ids)
# Set random user passwords
with open('usr.txt', 'w') as lst:
for i in range(0, 1000):
name = f"user_{i}"
pwd = hashlib.md5(('%s/%s' % (uuid.uuid4(), random.randint(0, 2^32))).encode('UTF-8') ).hexdigest()
user_id = user_model.create( {' login' : name, 'name': name, 'password': pwd})
lst.write('%s:%s\n' % (name, pwd))