Skip to content

Commit ac27fd3

Browse files
committed
Update changes
1 parent 0e01955 commit ac27fd3

File tree

5 files changed

+234
-146
lines changed

5 files changed

+234
-146
lines changed

.gitignore

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,73 @@
1-
# Byte-compiled / optimized / DLL files
2-
__pycache__/
3-
*.py[cod]
4-
*$py.class
5-
6-
# C extensions
7-
*.so
8-
9-
# Distribution / packaging
10-
.Python
11-
env/
12-
build/
13-
develop-eggs/
14-
dist/
15-
downloads/
16-
eggs/
17-
.eggs/
18-
lib/
19-
lib64/
20-
parts/
21-
sdist/
22-
var/
23-
*.egg-info/
24-
.installed.cfg
25-
*.egg
26-
27-
# PyInstaller
28-
# Usually these files are written by a python script from a template
29-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30-
*.manifest
31-
*.spec
32-
33-
# Installer logs
34-
pip-log.txt
35-
pip-delete-this-directory.txt
36-
37-
# Unit test / coverage reports
38-
htmlcov/
39-
.tox/
40-
.coverage
41-
.coverage.*
42-
.cache
43-
nosetests.xml
44-
coverage.xml
45-
*,cover
46-
47-
# Translations
48-
*.mo
49-
*.pot
50-
51-
# Django stuff:
52-
*.log
53-
54-
# Sphinx documentation
55-
docs/_build/
56-
57-
# PyBuilder
58-
target/
59-
60-
# Virtualenv
61-
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
62-
.Python
63-
[Bb]in
64-
[Ii]nclude
65-
[Ll]ib
66-
[Ss]cripts
67-
pyvenv.cfg
68-
pip-selfcheck.json
69-
Credentials.txt
70-
client_id
71-
client_secret
1+
*.zip
2+
3+
# Byte-compiled / optimized / DLL files
4+
__pycache__/
5+
*.py[cod]
6+
*$py.class
7+
8+
# C extensions
9+
*.so
10+
11+
# Distribution / packaging
12+
.Python
13+
env/
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*,cover
48+
49+
# Translations
50+
*.mo
51+
*.pot
52+
53+
# Django stuff:
54+
*.log
55+
56+
# Sphinx documentation
57+
docs/_build/
58+
59+
# PyBuilder
60+
target/
61+
62+
# Virtualenv
63+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
64+
.Python
65+
[Bb]in
66+
[Ii]nclude
67+
[Ll]ib
68+
[Ss]cripts
69+
pyvenv.cfg
70+
pip-selfcheck.json
71+
Credentials.txt
72+
client_id
73+
client_secret

app.py

Lines changed: 133 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,133 @@
1-
from pydrive.auth import GoogleAuth
2-
from pydrive.drive import GoogleDrive
3-
import httplib2
4-
import pickle
5-
6-
gauth = GoogleAuth()
7-
gauth.settings = {
8-
'client_config_backend': 'settings',
9-
'client_config_file' :'file',
10-
'save_credentials' : 'true',
11-
'save_credentials_backend' : 'file',
12-
'save_credentials_file' : 'Credentials.txt',
13-
'get_refresh_token' : True,
14-
'oauth_scope' : ['https://www.googleapis.com/auth/drive'],
15-
'client_config' : {
16-
'client_id':pickle.load(open('client_id', 'rb')),
17-
'auth_uri':'https://accounts.google.com/o/oauth2/auth',
18-
'token_uri':'https://accounts.google.com/o/oauth2/token',
19-
'client_secret':pickle.load(open('client_secret', 'rb')),
20-
'redirect_uri': 'http://localhost',
21-
'revoke_uri' : 'https://accounts.google.com/o/oauth2/revoke'
22-
}
23-
}
24-
25-
gauth.LoadClientConfigSettings()
26-
gauth.LoadCredentials()
27-
gauth.LocalWebserverAuth()
1+
from __future__ import print_function
2+
3+
from pydrive.auth import GoogleAuth
4+
from pydrive.drive import GoogleDrive
5+
import httplib2
6+
import zipfile
7+
import sys
8+
import os
9+
import time
10+
import hashlib
11+
12+
gauth = GoogleAuth()
13+
drive = GoogleDrive(gauth)
14+
GDZipFile = drive.CreateFile()
15+
oldHash = None
16+
17+
def authenticate():
18+
gauth.settings = {
19+
'client_config_backend': 'settings',
20+
'client_config_file' :'file',
21+
'save_credentials' : 'true',
22+
'save_credentials_backend' : 'file',
23+
'save_credentials_file' : 'Credentials.txt',
24+
'get_refresh_token' : True,
25+
'oauth_scope' : ['https://www.googleapis.com/auth/drive'],
26+
'client_config' : {
27+
# 'client_id':pickle.load(open('client_id', 'rb'))
28+
'client_id':'1069969218802-lms0do78nc6hsqkp88ltaesf9ve0dn1p.apps.googleusercontent.com',
29+
'auth_uri':'https://accounts.google.com/o/oauth2/auth',
30+
'token_uri':'https://accounts.google.com/o/oauth2/token',
31+
# 'client_secret':pickle.load(open('client_secret', 'rb')),
32+
'client_secret':'Nws7EkTv6SI5j2D8fJMNzRpp',
33+
'redirect_uri': 'http://localhost',
34+
'revoke_uri' : 'https://accounts.google.com/o/oauth2/revoke'
35+
}
36+
}
37+
38+
gauth.LoadClientConfigSettings()
39+
# gauth.LoadCredentials()
40+
gauth.http = httplib2.Http(ca_certs='cacert.pem')
41+
gauth.LocalWebserverAuth()
42+
43+
def zip_folder(folder_path, output_path):
44+
parent_folder = os.path.dirname(folder_path)
45+
# Retrieve the paths of the folder contents.
46+
contents = os.walk(folder_path)
47+
try:
48+
zip_file = zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED)
49+
for root, folders, files in contents:
50+
# Include all subfolders, including empty ones.
51+
for folder_name in folders:
52+
absolute_path = os.path.join(root, folder_name)
53+
relative_path = absolute_path.replace(parent_folder + '\\','')
54+
# print "Adding '%s' to archive." % absolute_path
55+
zip_file.write(absolute_path, relative_path)
56+
for file_name in files:
57+
absolute_path = os.path.join(root, file_name)
58+
relative_path = absolute_path.replace(parent_folder + '\\','')
59+
# print "Adding '%s' to archive." % absolute_path
60+
zip_file.write(absolute_path, relative_path)
61+
print ("Archive '{0}' created successfully.".format(output_path))
62+
except IOError, message:
63+
print (message)
64+
sys.exit(1)
65+
except OSError, message:
66+
print (message)
67+
sys.exit(1)
68+
except zipfile.BadZipfile, message:
69+
print (message)
70+
sys.exit(1)
71+
finally:
72+
zip_file.close()
73+
74+
75+
def upload(info):
76+
fileName = info['projectName'] + ".zip"
77+
zip_folder(info['dirName'] , info['projectName'] + ".zip")
78+
global GDZipFile
79+
GDZipFile['mimeType'] = 'application/zip'
80+
GDZipFile['title'] = info['projectName'] + time.strftime("_%x_%X") + ".zip"
81+
GDZipFile['description'] = info['description']
82+
GDZipFile.SetContentFile(info['projectName'] +".zip")
83+
84+
if changed(fileName):
85+
print("Uploading...")
86+
GDZipFile.Upload()
87+
print("File Uploaded\n")
88+
else:
89+
return
90+
91+
def changed(fileName):
92+
zipFile = open(fileName , 'rb')
93+
buff = zipFile.read(128)
94+
sha = hashlib.sha256()
95+
while len(buff) > 0:
96+
sha.update(buff)
97+
buff = zipFile.read(128)
98+
newHash = sha.hexdigest()
99+
# print newHash
100+
# print oldHash
101+
global oldHash
102+
if newHash == str(oldHash):
103+
print( "No changes made, not uploading\n")
104+
# print newHash
105+
oldHash = newHash
106+
return False
107+
else:
108+
oldHash = newHash
109+
return True
110+
111+
112+
# raw_input("File Uploaded, press any key to exit")
113+
114+
if __name__ == '__main__' :
115+
print( "Welcome to Auto Upload to Drive program!")
116+
print ("First we'd like to collect some information about the project")
117+
118+
zip_info = {
119+
'projectName' : raw_input("\tWhat is the name of the project?: "),
120+
'dirName' : raw_input("\tWhere is the location?: ").strip("\"") ,
121+
'description' : raw_input("\tPlease enter something about your project, for searching in GDrive\n\t(What it does...)[Optional]: "),
122+
'interval' : int(raw_input("\tPlease enter Upload interval, in seconds (choose reasonably)\n\tEg:300: "))
123+
}
124+
authenticate()
125+
try:
126+
for i in range(1,100 * 60 * 35):
127+
print( "File #{}".format(i))
128+
upload(zip_info)
129+
print( "Waiting for next turn.")
130+
time.sleep(zip_info['interval'])
131+
except KeyboardInterrupt, messgae:
132+
print ("Exit requested, Exiting now")
133+
sys.exit(0)

auth.py.patch

Lines changed: 0 additions & 20 deletions
This file was deleted.

requirements.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
google-api-python-client==1.4.1
2-
httplib2==0.9.1
3-
oauth2client==1.4.12
4-
py2exe==0.6.9
5-
pyasn1==0.1.8
6-
pyasn1-modules==0.0.7
7-
PyDrive==1.0.1
8-
PyYAML==3.11
9-
rsa==3.2
10-
simplejson==3.8.0
11-
six==1.9.0
12-
uritemplate==0.6
13-
wheel==0.24.0
1+
google-api-python-client==1.4.1
2+
httplib2==0.9.1
3+
oauth2client==1.4.12
4+
py2exe==0.6.9
5+
pyasn1==0.1.8
6+
pyasn1-modules==0.0.7
7+
PyDrive==1.0.1
8+
PyYAML==3.11
9+
rsa==3.2
10+
simplejson==3.8.0
11+
six==1.9.0
12+
uritemplate==0.6
13+
wheel==0.24.0

setup.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
from distutils.core import setup
2-
import py2exe
3-
4-
5-
setup( console=[
6-
{"script": "app.py"}],
7-
options={
8-
"py2exe":
9-
{
10-
"includes":["BaseHTTPServer"],
11-
'bundle_files': 1,
12-
'compressed': True
13-
}},
14-
data_files=[ ("",["cacert.pem",])],
15-
zipfile = None
1+
from distutils.core import setup
2+
import py2exe
3+
4+
5+
setup( console=[
6+
{"script": "app.py"}],
7+
options={
8+
"py2exe":
9+
{
10+
"includes":["BaseHTTPServer"],
11+
'bundle_files': 1,
12+
'compressed': True
13+
}},
14+
data_files=[ ("",["cacert.pem",])],
15+
zipfile = None
1616
)

0 commit comments

Comments
 (0)