Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parameters_path = os.path.join(os.path.dirname(__file__), '..', 'default_parameters.txt')
lines = open(parameters_path, 'r').readlines()
parameters = {}
for line in lines:
key, value = line.split(':')
parameters[key] = value[:-1]
spreadsheet_name = "Sign up form for INF3331/INF43331 (2016) (Responses)"
# or use
# spreadsheet_name = parameters["course"]
# Log on to disk
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name(json_file, scope)
gc = gspread.authorize(credentials)
try:
wks = gc.open(spreadsheet_name).sheet1
except gspread.SpreadsheetNotFound:
json_key = json.load(open(json_file))
print "The spreadsheet document '{}' not found. Maybe it does not exist?".format(spreadsheet_name)
print "Otherwise, make sure that you shared the spreadsheet with {} and try again.".format(json_key['client_email'])
sys.exit(1)
# Store file in ../Attendance/
attendance_location = os.path.join(os.path.dirname(__file__), '..',
*parameters["filepath"].split(os.path.sep)[:-1])
# Create ../Attendance/ if it does not exist
if not os.path.exists(attendance_location):
os.makedirs(attendance_location)
filename = os.path.join(attendance_location, "%s-students_base.txt" % parameters['course'])
def __init__(self, auth_filepath):
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name(auth_filepath, scope)
self._client = gspread.authorize(creds)
def setup_credentials():
scope = ['https://spreadsheets.google.com/feeds']
if on_heroku:
keyfile_dict = setup_keyfile_dict()
credentials = ServiceAccountCredentials.from_json_keyfile_dict(keyfile_dict, scope)
else:
credentials = ServiceAccountCredentials.from_json_keyfile_name('My Project-3b0bc29d35d3.json', scope)
gc = gspread.authorize(credentials)
if on_heroku:
sps = gc.open_by_key("1DdmBaOlGGdgQRaaI3tQCxj3BEd8kPwaGIHVfMpIoH8I")
else:
sps = gc.open_by_key("1DdmBaOlGGdgQRaaI3tQCxj3BEd8kPwaGIHVfMpIoH8I")
return sps
# You will need to create the json file referenced below (starting My Project) and upload it to wherever you are
# hosting this code. You will also need to find the url of your Google sheet, and set it as an ENVIRONMENTAL variable
# instructions for how to create an environmental variable on Heroku are here: https://devcenter.heroku.com/articles/config-vars#setting-up-config-vars-for-a-deployed-application
# If you consistently can't access the sheet you may have not set up the permissions properly
# Try sharing the sheet with your SERVICE ACCOUNT email address and see what happens
# Printing for debugging
json_key = json.load(open('vietnambot-2017-77539de66304.json'))
print (app_code,location_code,sublocation, "json key is: ", json_key)
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('vietnambot-2017-77539de66304.json', scope)
# Opening the relevant google sheet by name (can also open by URL)
gc = gspread.authorize(credentials)
print (app_code,location_code,sublocation,"authorised, gc is: ",gc)
vietnam = gc.open("Vietnamese orders")
print ("sheet is ", vietnam)
orders1 = vietnam.get_worksheet(0)
print (app_code,location_code,sublocation," have called sheet 'orders1' ")
#running the update_sheet program which takes the user information and adds them to the first empty row in the order sheet
row=update_sheet(app_code,location_code,orders1,user_name,food)
#-----------#
# Sending message to slack confirming order and signalling that will update with order status
# (see above for source and reasoning) of the process
params = (
('token', user_token),
def get_worksheet(self, key, sheet):
date = datetime.date.today()
days_until_saturday = 5 - date.weekday()
next_saturday = date + datetime.timedelta(days_until_saturday)
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name(key, scope)
gc = gspread.authorize(credentials)
sheet_name = 'Guildwar %s' % next_saturday.strftime('%m-%d-%Y')
return gc.open(sheet_name)
def oauthSheets():
####--logging.info("Authenticating using OAuth for Google Sheets")
f = file('%s/%s' % (SITE_ROOT,'data/key/sheets.p12'), 'rb')
key = f.read()
f.close()
http = httplib2.Http()
storage = Storage(SITE_ROOT + '/data/sheets.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = SignedJwtAssertionCredentials(google_api_user, key, scope='https://spreadsheets.google.com/feeds/',sub=google_user)
storage.put(credentials)
else:
credentials.refresh(http)
http = httplib2.Http()
http = credentials.authorize(http)
gc = gspread.authorize(credentials)
return gc
def _open_doc(url):
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
settings.GOOGLE_SERVICE_ACCOUNT_KEYFILE_PATH, scope)
gc = gspread.authorize(credentials)
try:
return gc.open_by_url(url)
except gspread.SpreadsheetNotFound:
raise SpreadsheetNotFound