-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (56 loc) · 2.05 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os, glob, urllib
from fbchat import Client, log
from getpass import getpass
from Send_email import sendEmail, zipping
media = ['mp3', 'mp4']
Email_username = str(raw_input("Gmail_Username till @: "))
Email_pass = getpass()
TO = Email_username + "@gmail.com"
FROM = TO
username = str(raw_input("Facebook_Username: "))
password = getpass()
arr = []
class EchoBot(Client):
def onMessage(self, author_id, message, thread_id, thread_type, **kwargs):
#self.markAsDelivered(author_id, thread_id)
#self.markAsRead(author_id)
global arr
if not os.path.exists('msg/'):
os.mkdir('msg/')
if author_id != self.uid:
arr.append(author_id)
user = client.fetchUserInfo(author_id)[author_id]
Folder_name = 'msg/' + user.name + '/'
if not os.path.exists(Folder_name):
os.mkdir(Folder_name)
file = open(Folder_name + user.name + '.txt', 'a' )
Message = client.fetchThreadMessages(thread_id=thread_id, limit=1)[0]
if Message.text is not None:
file.write( user.name + ' -- ' + Message.text.encode('utf-8') + ' \n' )
if Message.attachments:
for attachment in Message.attachments:
# For Image
Filename = attachment['filename']
if Filename.split("-")[0] == 'image':
add = attachment['large_preview']['uri']
name = Folder_name + user.name + '_' + attachment['filename']+'.'+attachment['original_extension']
urllib.urlretrieve(add, name)
elif len(Filename.split(".")) > 1 and Filename.split(".")[1] in media:
add = attachment['playable_url']
Filename = Folder_name + user.name + '_' + Filename
urllib.urlretrieve(add, Filename)
else:
add = attachment['url']
test = urllib.urlopen(add)
temp = test.read().split('replace("')[1]
temp = temp.split('");</script>')[0]
temp = temp.replace("\\","")
Filename = Folder_name + user.name + '_' + Filename
urllib.urlretrieve(temp, Filename)
file.close()
if len(arr) > 20:
zipping()
sendEmail(FROM, TO, Email_username, Email_pass)
arr = []
client = EchoBot(username, password)
client.listen()