-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.py
55 lines (42 loc) · 1.35 KB
/
lib.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
import os
import smtplib, ssl
import json
data = json.load(open("data.json", encoding="utf-8"))
def send_email(name, subject, email, msg):
port = 587 # For starttls
smtp_server = os.getenv("SMTP")
sender_email = os.getenv("SENDER")
password = os.getenv("PSSWD")
message = f"""
Subject: {subject}
From: {name}
Email: {email}
{msg}
"""
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.ehlo() # Can be omitted
server.starttls(context=context)
server.ehlo() # Can be omitted
server.login(sender_email, password)
for addr in admins:
server.sendmail(sender_email, addr, message)
def get_conts():
conts = []
for i in data['continents']:
conts.append(i)
return conts
def get_animals_of_cont(cont):
animals = []
for animal in data['continents'][cont]:
animals.append(animal['name'])
return animals
def get_cont_info(cont):
return data['info'][cont]
def get_animal_info(cont, animal):
for anim in data['continents'][cont]:
if animal == anim['name']:
aid = anim['id']
a3d = anim['3d']
return {"fact": data['facts'][aid], "3d":a3d}