-
Notifications
You must be signed in to change notification settings - Fork 0
/
dropboxm.py
executable file
·60 lines (53 loc) · 2.29 KB
/
dropboxm.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
# Include the Dropbox SDK
import dropbox
import os
class DropboxConnection(object):
"""DropboxConnection class"""
def __init__(self, *arg, **kwargs):
self._arg = arg
self._client = self._connect(kwargs)
def _connect(self,kwargs):
# Get your app key and secret from the Dropbox developer website
app_key = 'lf7drg20ucmhiga'
app_secret = '1uf7e8o5eu2pqe9'
flow = dropbox.client.DropboxOAuth2FlowNoRedirect(app_key, app_secret)
authorize_url = flow.start()
# Have the user sign in and authorize this token
authorize_url = flow.start()
print ('1. Go to: \n%s' % authorize_url)
print ('2. Click "Allow" (you might have to log in first)')
print ('3. Copy the authorization code.')
if kwargs['copy2clipboard']:
import pyperclip
pyperclip.copy(authorize_url)
# spam = pyperclip.paste()
try:
if kwargs['copy2clipboard']:
print("Authorization url is copied to clipboard")
code = raw_input("Enter the authorization code here: ").strip()
except Exception as e:
print('Error using raw_input() - trying input()')
code = input("Enter the authorization code here: ").strip()
# This will fail if the user enters an invalid authorization code
access_token, user_id = flow.finish(code)
client = dropbox.client.DropboxClient(access_token)
print('linked account user: %s' % client.account_info()['display_name'])
# print 'linked account: ', client.account_info()
return client
def open_dropbox_file(self,full_file_path_name):
f, metadata = self._client.get_file_and_metadata(full_file_path_name)
return f
if __name__ == "__main__":
dr_fname = '/othodi/settings.txt'
print('reading file \'%s\' from dropbox' % dr_fname)
dc = DropboxConnection()
out_fname = 'cities_from_dropbox.txt'
if not os.path.isfile(out_fname):
with open(out_fname,'w'):
pass
lines_list = []
with dc.open_dropbox_file(dr_fname) as dr_f:
with open(out_fname,'r'):
for line in dr_f:
print(line)
lines_list.append(line)