-
Notifications
You must be signed in to change notification settings - Fork 7
/
Test.py
58 lines (40 loc) · 1.47 KB
/
Test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from pymongo import MongoClient
import random
import string
import smtplib
from email.mime.text import MIMEText
client = MongoClient(host="127.0.0.1")
db = client.event_scrape
def api_key_gen():
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(32))
def add_user(firstName, lastName, email, country, organization, position, purpose, db):
userInfo = db.event_users.find_one({"email": email})
if userInfo is None:
userInfo = {}
userInfo["firstName"] = firstName
userInfo["lastName"] = lastName
userInfo["email"] = email
userInfo["country"] = country
userInfo["organization"] = organization
userInfo["position"] = position
userInfo["purpose"] = purpose
userInfo["apiKey"] = api_key_gen()
db.event_users.insert(userInfo)
return userInfo["apiKey"]
def send_api_key(apiKey, db):
userInfo = locate_user(apiKey, db)
fromaddr = '[email protected]'
toaddrs = userInfo["email"]
msg = MIMEText("Here is the api key: "+apiKey)
msg['Subject'] = "API Key for accessing event data repository"
username = '[email protected]'
password = 'workingwell'
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
# server.ehlo()
# server.starttls()
server.login(username, password)
server.sendmail(fromaddr, toaddrs, msg.as_string())
server.quit()
def locate_user(apiKey, db):
return db.event_users.find_one({"apiKey": apiKey})
""