Last active
December 17, 2015 07:48
-
-
Save nipunbatra/5575418 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from configuration import THRESHOLD_TIME, DATA_BASE_PATH, BASE_UPLOAD_PATH | |
from dbupload import DropboxConnection | |
import db_password | |
import glob | |
import os | |
import time | |
import requests | |
email=db_password.email | |
password=db_password.password | |
dropbox_upload_log=open(DATA_BASE_PATH+"db_log.txt","w") | |
username='Amarjeet' | |
folders=os.listdir(DATA_BASE_PATH) | |
try: | |
# Create the connection | |
#conn = DropboxConnection(email, password) | |
#List of files | |
for folder in folders: | |
list_of_files=glob.glob(str(DATA_BASE_PATH)+str(folder)+str("/*.csv")) | |
for f in list_of_files: | |
if int(time.time())-int(os.stat(f).st_mtime)>THRESHOLD_TIME: | |
dropbox_upload_log=open(DATA_BASE_PATH+"db_log.txt","w") | |
dropbox_upload_log.write(str(f) +" will be uploaded") | |
dropbox_upload_log.close() | |
r=open(f,"r") | |
files = {'myfile': r,'username':username,'date':str(folder)} | |
g = requests.post(url='http://sensoract.iiitd.edu.in:9005/upload',files=files) | |
if g.status_code==200: | |
#conn.upload_file(f,BASE_UPLOAD_PATH+str(folder),f) | |
os.remove(f) | |
except: | |
dropbox_upload_log=open(DATA_BASE_PATH+"db_log.txt","w") | |
dropbox_upload_log.write("Upload failed"+str(int(time.time()))) | |
dropbox_upload_log.close() | |
else: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment