This repository has been archived on 2026-10-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
neuf-userinfo/scripts/push_active_to_wordpress.py
T
nikolark 79a14fca02 Major update on the way to less users in LDAP
- Adds new app inside with models and moves related logic.
- Working InsideAuthBackend with group sync
- use passlib (<3) for MySQL hashes
- Renames main app to neuf_userinfo
- introduced local_settings.py
2015-02-14 22:54:36 +01:00

34 lines
1.1 KiB
Python

import json
import codecs
import subprocess
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "userinfosite.settings")
from neuf_userinfo.models import LdapGroup, LdapUser
PHP_SCRIPT_PATH = '/var/www/neuf.no/userinfo/scripts'
OUT_FILENAME = os.path.join(PHP_SCRIPT_PATH, "users_in_group_active.json")
usernames = LdapGroup.objects.get(posix_name="dns-aktiv").usernames
users = LdapUser.objects.filter(username__in=usernames)
users_out = [[u.username, u.first_name, u.last_name, u.email] for u in users]
out_file = codecs.open(OUT_FILENAME, "w", encoding="utf-8")
json.dump(users_out, out_file, ensure_ascii=False)
out_file.close()
wp_load_paths = [
"/var/www/studentersamfundet.no/www/wp/wp-load.php",
"/var/www/neuf.no/aktivweb/wp-load.php"
]
for load_path in wp_load_paths:
cmd = "php {0} {1} {2}".format(
os.path.join(PHP_SCRIPT_PATH, "import_users.php"),
OUT_FILENAME,
load_path
)
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()
print script_response,