Created
February 3, 2018 05:37
-
-
Save phsheth/7bd71e7a5530063d44ea50fd1a09bcd1 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 pylab import * | |
import smtplib | |
templog = "dtop.csv" | |
def main(): | |
dataupload_gs() | |
return 0 | |
def dataupload_gs(): | |
from apiclient.discovery import build | |
from time import strptime, strftime | |
import oauth2client | |
from oauth2client import client, file, tools | |
from httplib2 import Http | |
sheetname = "UploadedData" | |
SCOPES = "https://www.googleapis.com/auth/spreadsheets" | |
CLIENT_SECRET_FILE = "client_secrets.json" | |
APPLICATION_NAME = "pc2googlesheets3" | |
store = file.Storage('storage.json') | |
creds = store.get() | |
if not creds or creds.invalid: | |
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) | |
creds = tools.run_flow(flow,store) | |
NEWSHEET = build('sheets','v4', http=creds.authorize(Http())) | |
DATA = {"properties": {"title": sheetname}} | |
sheet = NEWSHEET.spreadsheets().create(body=DATA).execute() | |
SHEET_ID = sheet['spreadsheetId'] | |
FIELDS = ["lightsensor","year","month","day","hour","minute","sec"] | |
sheetdata = [FIELDS] | |
for row in open(templog): | |
data = row.split(",") | |
lightsensor = float(data[0]) | |
year = float(data[1]) | |
month = float(data[2]) | |
day = float(data[3]) | |
hour = float(data[4]) | |
minute = float(data[5]) | |
sec = float(data[6]) | |
sheetdata.append([lightsensor,year,month,day,hour,minute,sec]) | |
NEWSHEET.spreadsheets().values().update(spreadsheetId=SHEET_ID,range="A1", body={"values":sheetdata},valueInputOption="RAW").execute() | |
return 0 | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment