Commit 64da4f8a authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

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

parents 3dca041f ce6eeb0f
# Greet Newcomers
## Get ready
- Get Python 3 & pip
- `pip3 install ldap3` (you might need sudo, or --user, or a virtualenv)
- `mkdir -p ~/.cache`
## Go !
- `./`
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:
crontab -l > cronfile
echo "0 5 * * * $(which python) $(pwd)/" >> cronfile
crontab cronfile
rm cronfile
#!/usr/bin/env python3
import sys
import requests
from bs4 import BeautifulSoup
URL = ''
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:
from greet_newcomers import get_gepetto # noqa
for username in get_gepetto():
print(, 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 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 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 as shelf:
shelf['me'] = me
return me
def greet(to, sender):
Send a greeting email to `to`
if '@' not in sender:
sender = '' % sender
if '@' not in to:
to = '' % to
with open(join(dirname(abspath(__file__)), 'template.txt')) as f:
msg = MIMEText(
msg['Subject'] = 'Welcome in Gepetto !'
msg['From'] = sender
msg['To'] = to
msg['Bcc'] = sender
s = SMTP('localhost')
def get_gepetto_ldap():
Get a new list of Gepetto members in the LDAP of the LAAS
conn = Connection('', auto_bind=True)'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 as shelf:
shelf['gepetto'] = gepetto_ldap
Welcome in Gepetto !
Here's a link to the The Gepetto wiki:
You will find information about:
- the mailing-list,
- Framateam - our instant messaging tool
- the team software and hardware guidelines
- ...
See you soon !
This is an automatic email from
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment