Skip to content
Snippets Groups Projects
Commit 64da4f8a authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

Merge remote-tracking branch 'newcomers/master' in newcomers/

parents 3dca041f ce6eeb0f
No related branches found
No related tags found
No related merge requests found
# Greet Newcomers
## Get ready
- Get Python 3 & pip
- `pip3 install ldap3` (you might need sudo, or --user, or a virtualenv)
- `mkdir -p ~/.cache`
## Go !
- `./greet_newcomers.py`
On the first time, it will construct a database of the guys already here.
After that, on each launch, it will find the new guys, and send them a greeting mail.
The template of this mail is in `template.txt`.
## Cron job
To run this script everyday at 5 AM:
```bash
crontab -l > cronfile
echo "0 5 * * * $(which python) $(pwd)/greet_newcomers.py" >> cronfile
crontab cronfile
rm cronfile
```
#!/usr/bin/env python3
import sys
import requests
from bs4 import BeautifulSoup
URL = 'https://www.laas.fr/public/fr/'
def find_in_directory(name):
req = requests.get(URL + 'searchuser', {'letter': name})
soup = BeautifulSoup(req.content, 'html.parser')
for guy in soup.find('div', class_='personnel').find_all('tr')[1:]:
if 'GEPETTO' in guy.text:
return URL + guy.find('a').attrs['href']
if __name__ == '__main__':
if len(sys.argv) > 1:
print(find_in_directory(sys.argv[1]))
else:
from greet_newcomers import get_gepetto # noqa
for username in get_gepetto():
print(username.center(10), find_in_directory(username[1:]))
#!/usr/bin/env python3
import shelve
from email.mime.text import MIMEText
from getpass import getuser
from os.path import abspath, dirname, expanduser, join
from smtplib import SMTP
from ldap3 import Connection
SHELF = expanduser('~/.cache/gepetto_newcomers')
def get_gepetto():
"""
Get the old list of Gepetto members
"""
with shelve.open(SHELF) as shelf:
gepetto = shelf['gepetto'] if 'gepetto' in shelf else []
return gepetto
def whoami(gepetto):
"""
Returns the LAAS username of the current user.
The mail will be sent from this account
"""
with shelve.open(SHELF) as shelf:
me = shelf['me'] if 'me' in shelf else getuser()
while me not in gepetto:
print("You (%s) dont's seem to be in the Gepetto group… What's your LAAS username ?" % me)
me = input('--> ')
# remember this in the cache
with shelve.open(SHELF) as shelf:
shelf['me'] = me
return me
def greet(to, sender):
"""
Send a greeting email to `to`
"""
if '@' not in sender:
sender = '%s@laas.fr' % sender
if '@' not in to:
to = '%s@laas.fr' % to
with open(join(dirname(abspath(__file__)), 'template.txt')) as f:
msg = MIMEText(f.read())
msg['Subject'] = 'Welcome in Gepetto !'
msg['From'] = sender
msg['To'] = to
msg['Bcc'] = sender
s = SMTP('localhost')
s.send_message(msg)
s.quit()
def get_gepetto_ldap():
"""
Get a new list of Gepetto members in the LDAP of the LAAS
"""
conn = Connection('ldap.laas.fr', auto_bind=True)
conn.search('dc=laas,dc=fr', '(o=gepetto)', attributes=['uid'])
return [str(entry.uid) for entry in conn.entries]
if __name__ == '__main__':
# Get old and new list of members
gepetto = get_gepetto()
gepetto_ldap = get_gepetto_ldap()
# On the first run, old list is empty, so we just set it to the new one
if not gepetto:
gepetto = gepetto_ldap
# Retrieve the login of the current user, who must already be a member
me = whoami(gepetto)
for guy in gepetto_ldap:
if guy not in gepetto:
greet(guy, me)
# Save the new list
with shelve.open(SHELF) as shelf:
shelf['gepetto'] = gepetto_ldap
Welcome in Gepetto !
Here's a link to the The Gepetto wiki:
https://wiki.laas.fr/gepetto/Welcome
You will find information about:
- the mailing-list, gepetto-students@laas.fr
- Framateam - our instant messaging tool
- the team software and hardware guidelines
- ...
See you soon !
--
This is an automatic email from https://github.com/nim65s/GepettoStudents
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment