Skip to content

Instantly share code, notes, and snippets.

@konfiot
Created December 1, 2020 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konfiot/1a820495a62c61c9712b4e9b37c58bff to your computer and use it in GitHub Desktop.
Save konfiot/1a820495a62c61c9712b4e9b37c58bff to your computer and use it in GitHub Desktop.
import mimetypes
import mimetypes
import csv
import glob
import re
import smtplib
from email.message import EmailMessage
import random
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
drive = GoogleDrive(gauth)
def shuffle_list(some_list):
randomized_list = list(some_list)[:]
while True:
random.shuffle(randomized_list)
for a, b in zip(some_list, randomized_list):
if a == b:
break
else:
return randomized_list
name_mail = dict()
with open("mail.csv") as fmail:
reader = csv.DictReader(fmail)
for line in reader:
name_mail[" ".join(reversed(line["name"].split(","))).strip()] = line["email"]
files = dict()
r = re.compile(r"(.+)-150470 - (.+?) - (.+)")
for fn in glob.glob("*150470*"):
m = re.search(r, fn)
name = m.group(2)
if name_mail[name] in files.keys():
files[name_mail[name]].append(fn)
else:
files[name_mail[name]] = [fn]
emails = files.keys()
files = files.values()
shuffled_files = shuffle_list(files)
for email, files in zip(emails, shuffled_files):
print(f"send {files} to {email}")
msg = EmailMessage()
msg['Subject'] = "[ECSE416] Peer evaluation"
msg["From"] = "Arthur Toussaint <arthur.toussaint@free.fr>"
msg["To"] = "Arthur Toussaint <arthur.toussaint@mail.mcgill.ca>"
links = []
for f in files:
file1 = drive.CreateFile()
file1.SetContentFile(f) # Read local file
file1.Upload() # Upload it
permission = file1.InsertPermission({
'type': 'anyone',
'value': 'anyone',
'role': 'reader'})
links.append(file1['alternateLink'])
msg.set_content("Following are the links to the the submission that you have to peer-review, for more informations, check the announcements on mycourses\n" + "\n".join(links))
s = smtplib.SMTP('smtp.free.fr',25)
s.send_message(msg)
s.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment