<commit_before>"""
First do the following:

ssh to the Metalogix server

```
(if necessary): sudo mv /tmp/metalogix_users.csv /tmp/metalogix_users.(date).csv
sudo su edxapp -s /bin/bash
cd ~/edx-platform
source ~/edxapp_env
./manage.py lms 6002exportusers.csv --settings=aws_appsembler
```

This will output the file transfer_users.txt.
Then

```
python
```

and paste in this code.
Exit the Metalogix server terminal session, `scp` the file to your local drive
and email to Cathy or other contact at Metalogix.
"""




import json
import csv

fp = open('/tmp/metalogix_users.csv', 'w')
jsonfp = open('transfer_users.txt', 'r')
userjson = jsonfp.read()
users = json.loads(userjson)

writer = csv.writer(fp, dialect='excel', quotechar='"', quoting=csv.QUOTE_ALL)

for user in users:
    user_id = user['up']['user_id']
    username = user['u']['username']
    fullname = user['up']['name']
    emaildomain = user['u']['email'].split('@')[1]
    isactive = user['u']['is_active']
    lastlogin = user['u']['last_login']
    output_data = [user_id, username, fullname, emaildomain, isactive, lastlogin]
    encoded_row = [unicode(s).encode('utf-8') for s in output_data]
    writer.writerow(encoded_row)

fp.close()<commit_msg>Add date joined to Metalogix user report, plus a header row<commit_after>"""
First do the following:

ssh to the Metalogix server

```
(if necessary): sudo mv /tmp/metalogix_users.csv /tmp/metalogix_users.(date).csv
sudo su edxapp -s /bin/bash
cd ~/edx-platform
source ~/edxapp_env
./manage.py lms 6002exportusers.csv --settings=aws_appsembler
```

This will output the file transfer_users.txt.
Then

```
python
```

and paste in this code.
Exit the Metalogix server terminal session, `scp` the file to your local drive
and email to Cathy or other contact at Metalogix.
"""




import json
import csv

fp = open('/tmp/metalogix_users.csv', 'w')
jsonfp = open('transfer_users.txt', 'r')
userjson = jsonfp.read()
users = json.loads(userjson)

writer = csv.writer(fp, dialect='excel', quotechar='"', quoting=csv.QUOTE_ALL)
writer.writerow(['#user_id', 'Username','full_name','Email domain','Is_active','Last_login','date_joined'])

for user in users:
    user_id = user['up']['user_id']
    username = user['u']['username']
    fullname = user['up']['name']
    emaildomain = user['u']['email'].split('@')[1]
    isactive = user['u']['is_active']
    lastlogin = user['u']['last_login']
    datejoined = user['u']['date_joined']
    output_data = [user_id, username, fullname, emaildomain, isactive, lastlogin, datejoined]
    encoded_row = [unicode(s).encode('utf-8') for s in output_data]
    writer.writerow(encoded_row)

fp.close()
{'fraction_non_alphanumeric': 0.15549698795180722, 'fraction_numerical': 0.004518072289156626, 'mean_word_length': 4.839560439560439, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5037393', 'n_tokens_mistral': 945, 'n_tokens_neox': 900, 'n_words': 243}