Skip to content

Commit 166db86

Browse files
committed
Adding Documentation
1 parent df7d1f4 commit 166db86

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

automate.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@
44
from mail import sendmail
55
import json
66

7+
# Scraping the webpage and storing the data in a csv
78
data = scraper('http://automatescrape.surge.sh/')
89
write_csv(data)
910

11+
# Reading the scraped data from the csv and preprocessing the data
1012
participants = read_csv()
1113
participants = preprocess(participants)
1214

15+
# Getting the list of mails to whom mails have already been sent
1316
sent_mails = read_file()
14-
mails = []
1517

18+
# Looping over all participants
1619
for participant in participants:
20+
# Checking if the participant was sent a mail previously
1721
if participant['email'] not in sent_mails:
22+
# Generating a message from the template
1823
msg = _render_template(participant['name'], participant['payment'])
24+
# Sending the message to the participant via mail
1925
response = sendmail(to_email=participant['email'], msg=msg)
2026
if response['email_status'] == "Success":
21-
mails.append(participant['email'])
27+
# if mail was sent successfully append the email to sentmails.txt
2228
write_file(participant['email'])

file_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33

44
def read_csv():
5+
# opening the file in read mode
56
with open("studentdetails.csv", 'r') as csv_file:
7+
# reading the csv
68
csv_reader = csv.reader(csv_file, delimiter=',')
79
data = []
810
for row in csv_reader:
@@ -11,18 +13,22 @@ def read_csv():
1113

1214

1315
def write_csv(data):
16+
# opening the file in write mode
1417
with open("studentdetails.csv", 'w') as csv_file:
18+
# writing to the csv
1519
csv_writer = csv.writer(csv_file, delimiter=',')
1620
for row in data:
1721
csv_writer.writerow(row)
1822

1923

2024
def read_file():
25+
# opening the file in read mode and reading lines
2126
with open("sentmails.txt", 'r') as f:
2227
sent_mails = f.readlines()
2328
return sent_mails
2429

2530

2631
def write_file(mail):
32+
# opening the file in append mode and appending the mail at the end
2733
with open("sentmails.txt", 'a') as f:
2834
f.write(mail + "\n")

generate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33

44

55
def _render_template(name, payment_status):
6+
# loading the templates folder
67
file_loader = FileSystemLoader('templates')
78
env = Environment(
89
loader=file_loader,
910
trim_blocks=True,
1011
lstrip_blocks=True,
1112
keep_trailing_newline=True,
1213
)
14+
# fetching the template from the FileSystemLoader
1315
template = env.get_template('message.txt')
16+
# rendering the template
1417
return template.render(name=name, payment_status=payment_status)
1518

1619

1720
def preprocess(participants):
21+
# converting the list of lists to list of dict
1822
data = []
1923
for participant in participants:
2024
data.append({

scrape.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33

44

55
def scraper(url):
6+
# sending a get http request to the url
67
response = requests.get(url)
8+
# response: html page
79
html = response.text
810
data = []
911

12+
# converting the html string to soup object
1013
soup = bs4.BeautifulSoup(html)
1114
li_tags = soup.select('li')
1215

1316
for i in range(len(li_tags)):
17+
# selecting all the necessary classes from the li tags
18+
# Note: .select returns a list of elements
1419
name = li_tags[i].select('.name')[0].text
1520
dob = li_tags[i].select('.dob')[0].text
1621
email = li_tags[i].select('.email')[0].text

0 commit comments

Comments
 (0)