Exemplo n.º 1
0
 def gravatar(self, size=100):
     email = email_for_user(self.user_name, check_exists=False)
     return 'https://www.gravatar.com/avatar/{hash}?{params}'.format(
         hash=md5(email.lower().encode('utf-8')).hexdigest(),
         params=urlencode({
             'd': 'mm',
             's': size
         }),
     )
def main():
    for lab, pairs in pending_labs().items():
        facilitators = db.facilitator_labs(lab)
        emails = [email_for_user(f) for f in facilitators]

        submissions_txt = '\n'.join('{} {}'.format(*p) for p in pairs)
        body = template.format(
            names=', '.join(facilitators),
            lab=lab,
            submissions=submissions_txt,
        )

        send_mail(
            to=', '.join(emails),
            subject='Decal Checkoff Reminder for lab {}'.format(lab),
            body=body,
            sender='*****@*****.**',
        )
Exemplo n.º 3
0
 def gravatar(self, size=100):
     email = email_for_user(self.user_name)
     return 'https://www.gravatar.com/avatar/{hash}?{params}'.format(
         hash=md5(email.lower().encode('utf-8')).hexdigest(),
         params=urlencode({'d': 'mm', 's': size}),
     )
Exemplo n.º 4
0
        if co.rowid in stored_rowids:
            continue

        if co.correct:
            sentence = 'Congratulations, you were checked off for lab {}.'
        else:
            sentence = 'Unfortunately you were not checked off for lab {}.'

        sentence = sentence.format(co.labid)

        full_text = template.format(name=co.username,
                                    correct_sentence=sentence,
                                    facilitator=co.facilitator,
                                    feedback=co.feedback)

        to_email = email_for_user(co.username)

        try:
            cursor = db.get_cursor()
            checkoff.insert_into_db(cursor, co)
        except:
            db.db.rollback()
            db.db.close()
            raise
        else:
            db.db.commit()

            # send the email
            send_mail(
                to=to_email,
                subject='[Decal] Feedback on lab {}'.format(co.labid),
Exemplo n.º 5
0
 def test_nonexistant(self):
     with pytest.raises(ValueError):
         assert email_for_user('nonexist')
Exemplo n.º 6
0
 def test_existant(self, username, email):
     assert email_for_user(username) == email
Exemplo n.º 7
0
    help='Config file to sql creds read from.',
)
parser.add_argument(
    '-t',
    '--track',
    default='%',
    help='Which track to dump emails from (basic, advanced).',
)

args = parser.parse_args()

config = ConfigParser()
config.read(args.config)

user = config.get('mysql', 'user')
pw = config.get('mysql', 'password')
dbname = config.get('mysql', 'db')

conn = functools.partial(
    db.get_connection,
    user=user,
    password=pw,
    db=dbname,
)

with conn() as c:
    c.execute('SELECT `username` FROM `students` WHERE `track` LIKE %s',
              (args.track, ))
    for student in c.fetchall():
        print(email_for_user(student['username']))
Exemplo n.º 8
0
def current_user_email():
    """Returns @ocf email address of the current user."""
    return email_for_user(current_user())