I was hoping to run a script from Open Office Calc, with my script using 3 arguments that would be determined from the sheet, I have created my python script and it works via cmd I completely forgot to check on OO.
The excel sheet is used to generate barcodes, but I want to store extra data (using sheets ) as a backup but to include the date/time on it to keep a log when a # is scanned.
I would like it to be run on a form event.
Is this possible? This is my python script:
[spoiler]
Code: Select all
from __future__ import print_function
import os.path
import sys
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google.oauth2 import service_account
import datetime
# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
SERVICE_ACCOUNT_FILE = 'X'
id = None
product_name = ""
barcode_number = ""
creds = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE,
scopes=SCOPES)
service = build('sheets', 'v4', credentials=creds)
def writeValues(id, product_name, barcode_number):
currentDate = datetime.datetime.now()
currentTime = datetime.datetime.now()
values = [
[
id, product_name, barcode_number, currentDate.strftime('%m/%d/%Y'), currentTime.strftime("%H:%M:%S")
],
# Additional rows ...
]
body = {
'values': values
}
result = service.spreadsheets().values().append(
spreadsheetId=SAMPLE_SPREADSHEET_ID, range=SAMPLE_RANGE_NAME,
valueInputOption="USER_ENTERED", body=body).execute()
print('{0} cells appended.'.format(result
.get('updates')
.get('updatedCells')))
# The ID and range of a sample spreadsheet.
SAMPLE_SPREADSHEET_ID = 'X'
SAMPLE_RANGE_NAME = 'Sheet1!A1:D'
def main():
id = int(sys.argv[1])
product_name = str(sys.argv[2])
bardcode_number1 = str(sys.argv[3])
writeValues(id, product_name, bardcode_number1)
print ('Number of arguments:', len(sys.argv), 'arguments.')
print ('Argument List:', str(sys.argv))
# Call the Sheets API
sheet = service.spreadsheets()
if __name__ == '__main__':
main()