-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathyop.py
More file actions
executable file
·111 lines (85 loc) · 3.21 KB
/
yop.py
File metadata and controls
executable file
·111 lines (85 loc) · 3.21 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from os.path import join
from dateutil import parser, tz
from collections import OrderedDict
from bs4 import BeautifulSoup as bs4
class Yop(object):
def __init__(self, username, url='http://www.yopmail.com/', lang='en', id_fix=u'', version='2.6'):
self._url = url
self._lang = lang
self._username = username
self._id_fix = id_fix
self._version = version
self._session = requests.Session()
self._session.stream = False
def list_mails(self):
payload = {'login': self._username, 'v': self._version}
r = self._session.get(join(self._url, self._lang, 'inbox.php'), params=payload)
return self._compress(self._parse_list_mails(r.text))
def _parse_list_mails(self, source):
html = bs4(source, 'lxml')
messages = html.find_all('div', class_='m')
return [[m.find('span', class_='lmh').get_text(), m.find('span', class_='lmf').get_text(), m.find('span', class_='lms').get_text(), self._id_fix + m.find('a').get('href').split('id=')[-1]] for m in messages]
def get_mail(self, mail_id):
payload = {'b': self._username, 'id': mail_id}
r = self._session.get(join(self._url, self._lang, 'mail.php'), params=payload)
return self._parse_get_mail(r.text)
def _parse_get_mail(self, source):
html = bs4(source, 'lxml')
cryptogram = html.find('span', class_='petit nb')
if cryptogram:
raise Exception('Cryptogram presents')
message = html.find('div', id='mailmillieu')
for i in message.find_all('script'):
i.decompose()
return message
def read_mail(self, mail_id):
return self.get_mail(mail_id).get_text()
def click_mail(self, mail_id, limit=None):
message = self.get_mail(mail_id)
results = []
for link in message.find_all('a')[:limit]:
title, url = link.get_text(), link.get('href')
print title
print url
try:
r = self._session.get(url)
print r.status_code
results += [r]
except:
print 'Error'
return results
def click_last_mail(self, limit=1):
last_mail = self.list_mails().itervalues().next()[0]
last_mail_time = last_mail[0]
last_mail_sender = last_mail[1]
last_mail_title = last_mail[2]
last_mail_id = last_mail[3]
print last_mail_time
print last_mail_sender
print last_mail_title
return self.click_mail(last_mail_id, limit)
def _parse_timestamp(self, timestamp):
p = parser.parse(timestamp)
#local = p.astimezone(tz.tzlocal())
return (p.date(), p.time())
def _compress(self, ms):
mails = OrderedDict()
for m in ms:
d, t = self._parse_timestamp(m[0])
m[0] = t
if d in mails:
mails[d].append(m)
else:
mails.setdefault(d, [m])
return mails
if __name__ == '__main__':
import sys
try:
user = sys.argv[1]
except:
user = raw_input('User : ')
y = Yop(user)
y.click_last_mail()