Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
##add new admins
add_admins = list(set(cur_admins) - set(prev_admins))
manage_users('add', blogsite_admins_list, add_admins)
##remove old admins
del_owners = list(set(prev_admins) - set(cur_admins))
manage_users('del', blogsite_admins_list, del_owners)
#out= open('all.pickle', 'wb')
#pickle.dump(all,out)
#out.close()
#update google spreadsheet
try:
g = gspread.login(g_user, g_password)
except:
print 'failed to auth, spreadsheet update failed'
exit(1)
try:
doc = g.open_by_key(g_doc_key)
sheet = doc.get_worksheet(0)
except:
msg = 'Failed to open spreadsheet'
exit(1)
#f = open('all.pickle','rb')
#a = pickle.load(f)
total_domains = len(all.keys())+1 #include the row heading
cell_list_domains = sheet.range('A1:A' + str(total_domains))
import urllib
import codecs
from config import config
#config
username = config['USERNAME']
password = config['PASSWORD']
docs = [
{"doc": "My 1st Spreadsheet Name"},
{"doc":"My 2nd Spreadsheet Name"}
]
# login first
client = gspread.login(username, password)
#process doc list
for doc in docs:
spreadsheet = client.open(doc["doc"])
for i, worksheet in enumerate(spreadsheet.worksheets()):
filename = path + doc["doc"] + '-worksheet' + str(i) + '.csv'
with open(filename, 'wb') as f:
writer = csv.writer(f)
content = worksheet.get_all_values()
for row in content:
new_row=[]
for record in row:
record=record.encode('utf8')
new_row.append(record)
try:
writer.writerow(new_row)
def PostChallenge(DifficultyIndex):
# Save what the difficulty string is
DifficultyString = ['Easy', 'Intermediate', 'Hard'][DifficultyIndex]
### Part 1: Retrieve challenge
# Login with your Google account
gc = gspread.login(AccountDetails.GSPREAD_USERNAME, AccountDetails.GSPREAD_PASSWORD)
# Open a worksheet from spreadsheet with one shot
wks = gc.open("r/DailyProgrammer Challenge Submissions").sheet1
# Set to a valid row index if target is found, else set to -1
TargetRowIndex = -1
# For each row, check if there exists any non-posted easy-level challenges..
for RowIndex in range(2, wks.row_count):
# Get the difficulty type and post-status
DifficultyType = wks.acell('C%d' % RowIndex).value
PostStatus = wks.acell('M%d' % RowIndex).value
# If no data at all, then we're done parsing..
if DifficultyType == None:
def initGS(self, GD_SHEET_NAME): #TODO: check why are we passing sheet name and not self. reference?
""" Sets which WorkSheet to use within a Document
this feature can be used for sessions or threads """
#auth to google
try:
gc = gspread.login(self.GD_ACCT, self.GD_PASS)
docLogger.debug('initGS(): Success Authenticating to Google Acc')
except gspread.AuthenticationError:
raise Exception('initGS(): could not auth, check creds')
#open buffer && return handle to object
try:
baseDOC = gc.open(self.GD_DOC_NAME) #original
bufferSheet = baseDOC.worksheet(GD_SHEET_NAME) #added
return bufferSheet
except:
raise Exception('initGS(): could not open "%s", check sheet name' % GD_SHEET_NAME)
def gspread_input_login():
username = raw_input("Username: ")
password = getpass.getpass()
return gspread.login(username, password)
def syncSpreadSheets(dbUtils, spreadSheetKey= '1fXS6D8crBo9p-xWyFG4keqHI5P8-9qqi230IKlcw5Iw',syncSpecific = ["tags"] , excludeSheets=[] , username=None , password=None):
#def syncSpreadSheets(dbUtils, spreadSheetKey= '18vi7Glhc_4qb8v1nMbnFz3NeYPamcVTQV0g7OzTQBZU',syncSpecific = ["tags"] , excludeSheets=[]):
if(username and password):
gc = gspread.login(username, password)
wb = gc.open_by_key(spreadSheetKey)
worksheets = wb.worksheets()
'tags'
tagWorksheet = None
for i in worksheets:
if(i.title.lower().startswith('tags') and (not syncSpecific or i.title.lower() in syncSpecific) and not (i.title.lower in excludeSheets)):
tagWorksheet = i
records = tagWorksheet.get_all_records()
count = len(records)
for i in range(0,count): #exclude heading
row = records[i]
#after updating
if(IS_NEW_DB or row.get("isDirty",False)):
print row
if(dbUtils.addOrModifyTag(**row)):
def PostChallenge(DifficultyIndex):
# Save what the difficulty string is
DifficultyString = ['Easy', 'Intermediate', 'Hard'][DifficultyIndex]
### Part 1: Retrieve challenge
# Login with your Google account
gc = gspread.login(AccountDetails.GSPREAD_USERNAME, AccountDetails.GSPREAD_PASSWORD)
# Open a worksheet from spreadsheet with one shot
wks = gc.open("r/DailyProgrammer Challenge Submissions").sheet1
# Set to a valid row index if target is found, else set to -1
TargetRowIndex = -1
# For each row, check if there exists any non-posted easy-level challenges..
for RowIndex in range(2, wks.row_count):
# Get the difficulty type and post-status
DifficultyType = wks.acell('C%d' % RowIndex).value
PostStatus = wks.acell('M%d' % RowIndex).value
# If no data at all, then we're done parsing..
if DifficultyType == None: