-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailClient.py
More file actions
57 lines (45 loc) · 1.74 KB
/
EmailClient.py
File metadata and controls
57 lines (45 loc) · 1.74 KB
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
import requests
"""Sends an email to the user to give them more info
about a landmark/treasure they just found
@Params:
email(string): Email address of user
landmark(string): name of landmark/treasure
landmarkImage(string): url to image of landmark/item
landmakerURL(string): link to page about landmark
"""
def sendEmail(email, landmark,landmarkImage,landmarkURL,summary):
payload = {'to': email, 'link': landmarkURL,'image':landmarkImage, 'landmark':landmark,'summary':summary}
r = requests.post("http://jrbradley.co.uk:8002/", data=payload)
#an example email
# sendEmail("poo@poo.com","Cabbages",
# "http://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Cabbage_and_cross_section_on_white.jpg/300px-Cabbage_and_cross_section_on_white.jpg",
# "http://en.wikipedia.org/wiki/Cabbage")
"""Gets a random wikipedia page and emails the user details about it
@Params:
email(string): email address of the user
@Return:
landmark(string): name of the landmark
"""
def sendRandomEmail(email):
r = requests.get("http://en.wikipedia.org/wiki/Special:Random")
link = r.text.split('<link rel="canonical" href="')
link = link[1].split('"')
print link[0]
image = r.text.split('<img')
image = image[1].split('/>')
image = image[0].split('src="')
#print image[1],"\n"
image = image[1].split('"')
#print image[0],"\n"
image = image[0].split("//")
#print image[1],"\n"
image = image[1]
#print image
title = r.text.split('"wgTitle":"')
title = title[1].split('","')
#print title[0]
summary = r.text.split("<p>")
summary = summary[1].split("</p>")
print summary[0]
sendEmail(email,title[0],image,link[0],summary[0])
return title[0]