Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit46f1448

Browse files
OidaTiftlajuzim
authored andcommitted
rename drive to googledrive to keep identity
1 parentcfc802a commit46f1448

File tree

7 files changed

+57
-57
lines changed

7 files changed

+57
-57
lines changed

‎README.md‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ This crawler automates the following step:
1616

1717
###Default command
1818
```bash
19-
# upload pdf todrive, store data and notify via email
20-
python script/spider.py -c config/prod.cfg -udrive -s firebase -n gmail
19+
# upload pdf togoogledrive, store data and notify via email
20+
python script/spider.py -c config/prod.cfg -ugoogledrive -s firebase -n gmail
2121
```
2222

2323
###Other options
@@ -33,9 +33,9 @@ python script/spider.py --config config/prod.cfg -t pdf --extras
3333
# equivalent (default is pdf)
3434
python script/spider.py -c config/prod.cfg -e
3535

36-
# download and then upload to Drive (given the download url anyone can download it)
37-
python script/spider.py -c config/prod.cfg -t epub --uploaddrive
38-
python script/spider.py --config config/prod.cfg --all --extras --uploaddrive
36+
# download and then upload toGoogleDrive (given the download url anyone can download it)
37+
python script/spider.py -c config/prod.cfg -t epub --uploadgoogledrive
38+
python script/spider.py --config config/prod.cfg --all --extras --uploadgoogledrive
3939

4040
# download and notify: gmail|ifttt|join
4141
python script/spider.py -c config/prod.cfg --notify gmail
@@ -64,38 +64,38 @@ Now you should be able to claim and download your first eBook
6464
python script/spider.py --config config/prod.cfg
6565
```
6666

67-
###Drive
67+
###GoogleDrive
6868

69-
From the documentation, Drive API requires OAuth2.0 for authentication, so to upload files you should:
69+
From the documentation,GoogleDrive API requires OAuth2.0 for authentication, so to upload files you should:
7070

71-
* Go to[Google APIs Console](https://code.google.com/apis/console) and create a new[Drive](https://console.developers.google.com/apis/api/drive/overview) project named**PacktpubDrive**
71+
* Go to[Google APIs Console](https://code.google.com/apis/console) and create a new[GoogleDrive](https://console.developers.google.com/apis/api/drive/overview) project named**PacktpubDrive**
7272
* On*API manager > Overview* menu
7373
* Enable Google Drive API
7474
* On*API manager > Credentials* menu
7575
* In*OAuth consent screen* tab set**PacktpubDrive** as the product name shown to users
7676
* In*Credentials* tab create credentials of type*OAuth client ID* and choose Application type*Other* named**PacktpubDriveCredentials**
7777
* Click*Download JSON* and save the file`config/client_secrets.json`
78-
* Change your Drive credentials in the config file
78+
* Change yourGoogleDrive credentials in the config file
7979

8080
```
81-
[drive]
81+
[googledrive]
8282
...
83-
drive.client_secrets=config/client_secrets.json
84-
drive.gmail=GOOGLE_DRIVE@gmail.com
83+
googledrive.client_secrets=config/client_secrets.json
84+
googledrive.gmail=GOOGLE_DRIVE@gmail.com
8585
```
8686

87-
Now you should be able to upload your eBook to Drive
87+
Now you should be able to upload your eBook toGoogleDrive
8888
```
89-
python script/spider.py --config config/prod.cfg --uploaddrive
89+
python script/spider.py --config config/prod.cfg --uploadgoogledrive
9090
```
9191

9292
Only the first time you will be prompted to login in a browser which has javascript enabled (no text-based browser) to generate`config/auth_token.json`.
9393
You should also copy and paste in the config the*FOLDER_ID*, otherwise every time a new folder with the same name will be created.
9494
```
95-
[drive]
95+
[googledrive]
9696
...
97-
drive.default_folder=packtpub
98-
drive.upload_folder=FOLDER_ID
97+
googledrive.default_folder=packtpub
98+
googledrive.upload_folder=FOLDER_ID
9999
```
100100

101101
Documentation:[OAuth](https://developers.google.com/api-client-library/python/guide/aaa_oauth),[Quickstart](https://developers.google.com/drive/v3/web/quickstart/python),[example](https://github.com/googledrive/python-quickstart) and[permissions](https://developers.google.com/drive/v2/reference/permissions)
@@ -136,7 +136,7 @@ firebase.url=https://PROJECT_NAME.firebaseio.com
136136

137137
Now you should be able to store your eBook details on Firebase
138138
```
139-
python script/spider.py --config config/prod.cfg --uploaddrive --store firebase
139+
python script/spider.py --config config/prod.cfg --uploadgoogledrive --store firebase
140140
```
141141

142142
###Gmail notification

‎config/dev.cfg‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ path.ebooks=ebooks
2020
path.extras=ebooks/extras
2121
#path.group=true
2222

23-
[drive]
24-
drive.oauth2_scope=https://www.googleapis.com/auth/drive
25-
drive.client_secrets=config/client_secrets.json
26-
drive.auth_token=config/auth_token.json
27-
drive.gmail=g00gler@gmail.com
23+
[googledrive]
24+
googledrive.oauth2_scope=https://www.googleapis.com/auth/drive
25+
googledrive.client_secrets=config/client_secrets.json
26+
googledrive.auth_token=config/auth_token.json
27+
googledrive.gmail=g00gler@gmail.com

‎config/prod_example.cfg‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ path.ebooks=ebooks
1818
path.extras=ebooks/extras
1919
#path.group=true
2020

21-
[drive]
22-
drive.oauth2_scope=https://www.googleapis.com/auth/drive
23-
drive.client_secrets=config/client_secrets.json
24-
drive.auth_token=config/auth_token.json
25-
drive.gmail=GOOGLE_DRIVE@gmail.com
26-
drive.default_folder=packtpub
27-
#drive.upload_folder=FOLDER_ID
21+
[googledrive]
22+
googledrive.oauth2_scope=https://www.googleapis.com/auth/drive
23+
googledrive.client_secrets=config/client_secrets.json
24+
googledrive.auth_token=config/auth_token.json
25+
googledrive.gmail=GOOGLE_DRIVE@gmail.com
26+
googledrive.default_folder=packtpub
27+
#googledrive.upload_folder=FOLDER_ID
2828

2929
[scp]
3030
scp.host=SCP_HOST

‎script/drive.py‎renamed to ‎script/googledrive.py‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
fromutilsimportthread_loader
1010
fromlogsimport*
1111

12-
classDrive(object):
12+
classGoogleDrive(object):
1313
"""
1414
"""
1515

1616
def__init__(self,config):
1717
self.__config=config
18-
self.__drive_service=None
18+
self.__googledrive_service=None
1919
self.info= {}
2020

2121
def__guess_info(self,file_path):
@@ -27,11 +27,11 @@ def __guess_info(self, file_path):
2727
'name':file_path.split('/')[-1],
2828
'mime_type':magic.from_file(file_path,mime=True),
2929
}
30-
log_info('[+] new file upload on Drive:')
30+
log_info('[+] new file upload onGoogleDrive:')
3131
# log_dict(self.file_info)
3232

3333
def__init_service(self):
34-
auth_token=self.__config.get('drive','drive.auth_token')
34+
auth_token=self.__config.get('googledrive','googledrive.auth_token')
3535

3636
ifnotexists(auth_token):
3737
self.__save_credentials(auth_token)
@@ -41,12 +41,12 @@ def __init_service(self):
4141

4242
http=httplib2.Http()
4343
http=credentials.authorize(http)
44-
self.__drive_service=build('drive','v2',http=http)
44+
self.__googledrive_service=build('drive','v2',http=http)
4545

4646
def__save_credentials(self,auth_token):
4747
flow=flow_from_clientsecrets(
48-
self.__config.get('drive','drive.client_secrets'),
49-
self.__config.get('drive','drive.oauth2_scope'),
48+
self.__config.get('googledrive','googledrive.client_secrets'),
49+
self.__config.get('googledrive','googledrive.oauth2_scope'),
5050
OOB_CALLBACK_URN)
5151

5252
authorize_url=flow.step1_get_authorize_url()
@@ -63,35 +63,35 @@ def __save_credentials(self, auth_token):
6363

6464
def__create_folder(self):#Create folder with provided name
6565
try:#Check default folder name
66-
default_folder_name=self.__config.get('drive','drive.default_folder')
66+
default_folder_name=self.__config.get('googledrive','googledrive.default_folder')
6767
except:
6868
default_folder_name='packtpub'
6969

7070
metadata= {
7171
'title':default_folder_name,
7272
'mimeType' :'application/vnd.google-apps.folder'
7373
}
74-
folder=self.__drive_service.files().insert(body=metadata).execute()
75-
self.__config.set('drive','drive.upload_folder',folder['id'])
74+
folder=self.__googledrive_service.files().insert(body=metadata).execute()
75+
self.__config.set('googledrive','googledrive.upload_folder',folder['id'])
7676
log_success('[+] creating new directory...')
7777
print'[+] updating folder permissions...'
7878
permissions= {
7979
'role':'reader',
8080
'type':'anyone',
81-
'value':self.__config.get('drive','drive.gmail')
81+
'value':self.__config.get('googledrive','googledrive.gmail')
8282
}
83-
self.__drive_service.permissions().insert(fileId=folder['id'],body=permissions).execute()
83+
self.__googledrive_service.permissions().insert(fileId=folder['id'],body=permissions).execute()
8484
log_dict({'folder_name':default_folder_name,
8585
'id':folder['id'],})
8686
#'share_link': folder['webContentLink']}) #TODO Fix
87-
log_success('[+] Please add this line after [drive] in your configuration file:')
88-
log_info('drive.upload_folder='+folder.get('id'))
87+
log_success('[+] Please add this line after [googledrive] in your configuration file:')
88+
log_info('googledrive.upload_folder='+folder.get('id'))
8989

9090
returnfolder.get('id')#Return folder object ID
9191

9292
def__get_folder(self):#Get folder name settings
9393
try:
94-
returnself.__config.get('drive','drive.upload_folder')
94+
returnself.__config.get('googledrive','googledrive.upload_folder')
9595
except:
9696
returnself.__create_folder()#new folder ID
9797

@@ -105,18 +105,18 @@ def __insert_file(self):
105105
'mimeType':self.info['mime_type'],
106106
'parents': [{'id':self.__get_folder()}]
107107
}
108-
file=self.__drive_service.files().insert(body=body,media_body=media_body).execute()
108+
file=self.__googledrive_service.files().insert(body=body,media_body=media_body).execute()
109109
# log_dict(file)
110110

111111
print'[+] updating file permissions...'
112112
permissions= {
113113
'role':'reader',
114114
'type':'anyone',
115-
'value':self.__config.get('drive','drive.gmail')
115+
'value':self.__config.get('googledrive','googledrive.gmail')
116116
}
117-
self.__drive_service.permissions().insert(fileId=file['id'],body=permissions).execute()
117+
self.__googledrive_service.permissions().insert(fileId=file['id'],body=permissions).execute()
118118

119-
# self.__drive_service.files().get(fileId=file['id']).execute()
119+
# self.__googledrive_service.files().get(fileId=file['id']).execute()
120120

121121
self.info['id']=file['id']
122122
self.info['download_url']=file['webContentLink']

‎script/scheduler.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
defscheduled_job():
99
print('New job: packtpub-crawler')
1010
shutil.rmtree('./ebooks',ignore_errors=True)
11-
os.system('python script/spider.py --config config/prod.cfg --uploaddrive --store firebase --notify gmail')
11+
os.system('python script/spider.py --config config/prod.cfg --uploadgoogledrive --store firebase --notify gmail')
1212

1313
sched.start()

‎script/spider.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
importos
77
fromutilsimportip_address,config_file
88
frompacktpubimportPacktpub
9-
fromuploadimportUpload,SERVICE_DRIVE,SERVICE_DROPBOX,SERVICE_SCP
9+
fromuploadimportUpload,SERVICE_GOOGLE_DRIVE,SERVICE_DROPBOX,SERVICE_SCP
1010
fromdatabaseimportDatabase,DB_FIREBASE
1111
fromlogsimport*
1212
fromnotifyimportNotify,SERVICE_GMAIL,SERVICE_IFTTT,SERVICE_JOIN
@@ -44,7 +44,7 @@ def handleClaim(packtpub, args, config, dir_path):
4444
upload.run(packtpub.info['paths'])
4545

4646
ifargs.storeisnotNone:
47-
ifargs.upload==SERVICE_DRIVE:
47+
ifargs.upload==SERVICE_GOOGLE_DRIVE:
4848
Database(config,args.store,packtpub.info,upload.info).store()
4949
else:
5050
log_warn('[-] skip store info: missing upload info')
@@ -65,7 +65,7 @@ def main():
6565
parser.add_argument('-c','--config',required=True,help='configuration file')
6666
parser.add_argument('-d','--dev',action='store_true',help='only for development')
6767
parser.add_argument('-e','--extras',action='store_true',help='download source code (if exists) and book cover')
68-
parser.add_argument('-u','--upload',choices=[SERVICE_DRIVE,SERVICE_DROPBOX,SERVICE_SCP],help='upload to cloud')
68+
parser.add_argument('-u','--upload',choices=[SERVICE_GOOGLE_DRIVE,SERVICE_DROPBOX,SERVICE_SCP],help='upload to cloud')
6969
parser.add_argument('-a','--archive',action='store_true',help='compress all file')
7070
parser.add_argument('-n','--notify',choices=[SERVICE_GMAIL,SERVICE_IFTTT,SERVICE_JOIN],help='notify after claim/download')
7171
parser.add_argument('-s','--store',choices=[DB_FIREBASE],help='store info')

‎script/upload.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
fromdriveimportDrive
1+
fromgoogledriveimportGoogleDrive
22
fromscpUploadimportScpUpload
33
fromlogsimport*
44

5-
SERVICE_DRIVE='drive'
5+
SERVICE_GOOGLE_DRIVE='googledrive'
66
SERVICE_DROPBOX='DROPBOX'
77
SERVICE_SCP='scp'
88

@@ -16,8 +16,8 @@ def __init__(self, config, service_type):
1616
self.info= {
1717
'details': []
1818
}
19-
ifservice_type==SERVICE_DRIVE:
20-
self.service=Drive(config)
19+
ifservice_type==SERVICE_GOOGLE_DRIVE:
20+
self.service=GoogleDrive(config)
2121
elifservice_type==SERVICE_DROPBOX:
2222
raiseNotImplementedError('not implemented yet!')
2323
elifservice_type==SERVICE_SCP:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp