Skip to content

Commit

Permalink
Update changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cshubhamrao committed Jun 20, 2018
1 parent 0e01955 commit ac27fd3
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 146 deletions.
144 changes: 73 additions & 71 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,71 +1,73 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ss]cripts
pyvenv.cfg
pip-selfcheck.json
Credentials.txt
client_id
client_secret
*.zip

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ss]cripts
pyvenv.cfg
pip-selfcheck.json
Credentials.txt
client_id
client_secret
160 changes: 133 additions & 27 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,133 @@
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
import httplib2
import pickle

gauth = GoogleAuth()
gauth.settings = {
'client_config_backend': 'settings',
'client_config_file' :'file',
'save_credentials' : 'true',
'save_credentials_backend' : 'file',
'save_credentials_file' : 'Credentials.txt',
'get_refresh_token' : True,
'oauth_scope' : ['https://www.googleapis.com/auth/drive'],
'client_config' : {
'client_id':pickle.load(open('client_id', 'rb')),
'auth_uri':'https://accounts.google.com/o/oauth2/auth',
'token_uri':'https://accounts.google.com/o/oauth2/token',
'client_secret':pickle.load(open('client_secret', 'rb')),
'redirect_uri': 'http://localhost',
'revoke_uri' : 'https://accounts.google.com/o/oauth2/revoke'
}
}

gauth.LoadClientConfigSettings()
gauth.LoadCredentials()
gauth.LocalWebserverAuth()
from __future__ import print_function

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
import httplib2
import zipfile
import sys
import os
import time
import hashlib

gauth = GoogleAuth()
drive = GoogleDrive(gauth)
GDZipFile = drive.CreateFile()
oldHash = None

def authenticate():
gauth.settings = {
'client_config_backend': 'settings',
'client_config_file' :'file',
'save_credentials' : 'true',
'save_credentials_backend' : 'file',
'save_credentials_file' : 'Credentials.txt',
'get_refresh_token' : True,
'oauth_scope' : ['https://www.googleapis.com/auth/drive'],
'client_config' : {
# 'client_id':pickle.load(open('client_id', 'rb'))
'client_id':'1069969218802-lms0do78nc6hsqkp88ltaesf9ve0dn1p.apps.googleusercontent.com',
'auth_uri':'https://accounts.google.com/o/oauth2/auth',
'token_uri':'https://accounts.google.com/o/oauth2/token',
# 'client_secret':pickle.load(open('client_secret', 'rb')),
'client_secret':'Nws7EkTv6SI5j2D8fJMNzRpp',
'redirect_uri': 'http://localhost',
'revoke_uri' : 'https://accounts.google.com/o/oauth2/revoke'
}
}

gauth.LoadClientConfigSettings()
# gauth.LoadCredentials()
gauth.http = httplib2.Http(ca_certs='cacert.pem')
gauth.LocalWebserverAuth()

def zip_folder(folder_path, output_path):
parent_folder = os.path.dirname(folder_path)
# Retrieve the paths of the folder contents.
contents = os.walk(folder_path)
try:
zip_file = zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED)
for root, folders, files in contents:
# Include all subfolders, including empty ones.
for folder_name in folders:
absolute_path = os.path.join(root, folder_name)
relative_path = absolute_path.replace(parent_folder + '\\','')
# print "Adding '%s' to archive." % absolute_path
zip_file.write(absolute_path, relative_path)
for file_name in files:
absolute_path = os.path.join(root, file_name)
relative_path = absolute_path.replace(parent_folder + '\\','')
# print "Adding '%s' to archive." % absolute_path
zip_file.write(absolute_path, relative_path)
print ("Archive '{0}' created successfully.".format(output_path))
except IOError, message:
print (message)
sys.exit(1)
except OSError, message:
print (message)
sys.exit(1)
except zipfile.BadZipfile, message:
print (message)
sys.exit(1)
finally:
zip_file.close()


def upload(info):
fileName = info['projectName'] + ".zip"
zip_folder(info['dirName'] , info['projectName'] + ".zip")
global GDZipFile
GDZipFile['mimeType'] = 'application/zip'
GDZipFile['title'] = info['projectName'] + time.strftime("_%x_%X") + ".zip"
GDZipFile['description'] = info['description']
GDZipFile.SetContentFile(info['projectName'] +".zip")

if changed(fileName):
print("Uploading...")
GDZipFile.Upload()
print("File Uploaded\n")
else:
return

def changed(fileName):
zipFile = open(fileName , 'rb')
buff = zipFile.read(128)
sha = hashlib.sha256()
while len(buff) > 0:
sha.update(buff)
buff = zipFile.read(128)
newHash = sha.hexdigest()
# print newHash
# print oldHash
global oldHash
if newHash == str(oldHash):
print( "No changes made, not uploading\n")
# print newHash
oldHash = newHash
return False
else:
oldHash = newHash
return True


# raw_input("File Uploaded, press any key to exit")

if __name__ == '__main__' :
print( "Welcome to Auto Upload to Drive program!")
print ("First we'd like to collect some information about the project")

zip_info = {
'projectName' : raw_input("\tWhat is the name of the project?: "),
'dirName' : raw_input("\tWhere is the location?: ").strip("\"") ,
'description' : raw_input("\tPlease enter something about your project, for searching in GDrive\n\t(What it does...)[Optional]: "),
'interval' : int(raw_input("\tPlease enter Upload interval, in seconds (choose reasonably)\n\tEg:300: "))
}
authenticate()
try:
for i in range(1,100 * 60 * 35):
print( "File #{}".format(i))
upload(zip_info)
print( "Waiting for next turn.")
time.sleep(zip_info['interval'])
except KeyboardInterrupt, messgae:
print ("Exit requested, Exiting now")
sys.exit(0)
20 changes: 0 additions & 20 deletions auth.py.patch

This file was deleted.

26 changes: 13 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
google-api-python-client==1.4.1
httplib2==0.9.1
oauth2client==1.4.12
py2exe==0.6.9
pyasn1==0.1.8
pyasn1-modules==0.0.7
PyDrive==1.0.1
PyYAML==3.11
rsa==3.2
simplejson==3.8.0
six==1.9.0
uritemplate==0.6
wheel==0.24.0
google-api-python-client==1.4.1
httplib2==0.9.1
oauth2client==1.4.12
py2exe==0.6.9
pyasn1==0.1.8
pyasn1-modules==0.0.7
PyDrive==1.0.1
PyYAML==3.11
rsa==3.2
simplejson==3.8.0
six==1.9.0
uritemplate==0.6
wheel==0.24.0
30 changes: 15 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from distutils.core import setup
import py2exe


setup( console=[
{"script": "app.py"}],
options={
"py2exe":
{
"includes":["BaseHTTPServer"],
'bundle_files': 1,
'compressed': True
}},
data_files=[ ("",["cacert.pem",])],
zipfile = None
from distutils.core import setup
import py2exe


setup( console=[
{"script": "app.py"}],
options={
"py2exe":
{
"includes":["BaseHTTPServer"],
'bundle_files': 1,
'compressed': True
}},
data_files=[ ("",["cacert.pem",])],
zipfile = None
)

0 comments on commit ac27fd3

Please sign in to comment.