-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvk-backup.py
executable file
·93 lines (69 loc) · 2.81 KB
/
vk-backup.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
'''VK-Backup 0.9.0
Author: Rabit <[email protected]>
License: GPL v3
Description: Script can backup your VK profile to your storage
Required: python3.5
Usage:
$ ./vk-backup.py --help
'''
from lib import Common as c
import getpass, os
import traceback
from sys import exit
c.init_begin(__doc__)
c.option('-u', '--user', type='string', dest='user', metavar='EMAIL', default=None, help='vk.com account user email (<user>@<host>) (required)')
c.option('-p', '--password', type='string', dest='password', metavar='PASSWORD', default=None, help='vk.com account password (will be requested if not set)')
c.option('-d', '--backup-dir', type='string', dest='backup-dir', metavar='PATH', default='backup', help='directory to store data [%default]')
c.option('--download-threads', type='int', dest='download-threads', metavar='NUM', default=16, help='number of simultaneous media downloads, 0 - disables download at all [%default]')
c.init_end()
if c.cfg('user') == None:
c.log('error', 'Unable to get email from the user option')
exit(1)
if c.cfg('password') == None:
c.cfg('password', getpass.getpass())
if c.cfg('download-threads') < 1:
c.log('error', 'Number of download threads can\'t be lower then one')
exit(1)
class Backup:
def __init__(self):
c.log('debug', 'Init Backup')
self.path = c.cfg('backup-dir')
def store(self):
c.log('debug', 'Store data')
Users.store()
Dialogs.store()
Chats.store()
Media.store()
with open(os.path.join(self.path, 'backup.id'), 'w') as outfile:
outfile.write(str(Api.getUserId()))
def process(self):
c.log('debug', 'Start processing')
try:
Users.requestUsers([Api.getUserId()])
# Get friends of user & load them
Users.requestUsers(Users.requestFriends(Api.getUserId()))
# Get user photos
Users.requestUserPhotos(Api.getUserId())
# Get user blog
#Users.requestBlog(Api.getUserId())
# Get dialogs info
# Unfortunately this functionality was blocked by vk.com for the non-trusted apps...
# So instead please use messages_backup.py to use UI API to get your data from Messages
Dialogs.requestDialogs()
# Store data
backup.store()
except (Exception, KeyboardInterrupt) as e:
c.log('error', 'Exception: %s: %s' % (str(e), traceback.format_exc()))
Media.stopDownloads()
from lib import Api
from lib.Users import S as Users
#from lib.Dialogs import S as Dialogs
#from lib.Chats import S as Chats
from lib.DialogsUI import S as Dialogs
from lib.ChatsUI import S as Chats
from lib.Media import S as Media
backup = Backup()
backup.process()
c.log('info', 'DONE')