-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspreadsheet.py
165 lines (136 loc) · 4.6 KB
/
spreadsheet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import datetime
headers = ["\t\tTopic: ", "\t\tBible Study Leader: ",
"\t\tWorship Leader: ", "\t\tRemarks: ", "\tBirthday: "]
NO_CG = "No CG this week. Go hang out!"
currentDate = datetime.datetime.now()
currentMonth = currentDate.strftime("%B")
currentDay = datetime.date.today().day
currentWeek = datetime.date.today().isocalendar()[1]
today = datetime.date.today()
endOfWeek = today + datetime.timedelta(days=6 - today.weekday())
endOfWeek = endOfWeek.day
# use creds to create a client to interact with the Google Drive API
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name(
'rachelle-340511-f69cbb14908c.json', scope)
client = gspread.authorize(creds)
# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
sheet = client.open("Copy of YA CG Planner 2021").sheet1
# Extract and print all of the values
# list_of_hashes = sheet.get_all_records()
def getMonthItemsRows(fullMonthName):
rows = []
cell_list = sheet.findall(fullMonthName)
for cell in cell_list:
rows.append(cell.row)
return rows
def getThisMonthItemsRows():
return getMonthItemsRows(currentMonth)
def getCertainMonthItemsRows(fullMonthName):
return getMonthItemsRows(fullMonthName)
def getThisMonthItems():
items = []
monthRows = getThisMonthItemsRows()
for rowValue in monthRows:
item = sheet.row_values(rowValue)
item = item[1:]
if (int(item[1]) < currentDay):
# then do nothing and skip
continue
else:
items.append(item)
return items
def getThisWeekItems():
items = []
remItems = getThisMonthItems()
for item in remItems:
if (int(item[1]) <= endOfWeek):
items.append(item)
return items
def getNextItemFormatted():
items = getThisMonthItems()
toReturn = items[0]
date = toReturn[0] + " " + toReturn[1]
if ("No CG" in toReturn[2]):
if ("CAP" in toReturn[2]):
return "CAPing this week on " + date
return NO_CG
topic = toReturn[2]
if (len(toReturn) < 4):
return date + "\n" + "topic"
BSL = toReturn[3]
WSL = toReturn[4]
isBS = True
if (("-" in BSL) or ("CG" in BSL) or (BSL == "") or (BSL == " ")):
isBS = False
if (isBS):
date = toReturn[0] + " " + toReturn[1]
topic = "Topic: " + toReturn[2]
BSL = "Bible study leader: " + BSL
WSL = "Worship leader: " + WSL
hasRemarks = False
try:
remarks = toReturn[5]
hasRemarks = True
except:
print("No remarks")
if (hasRemarks):
return date + "\n" + topic + "\n" + BSL + "\n" + WSL + "\n" + "Remarks: " + remarks
return date + "\n" + topic + "\n" + BSL + "\n" + WSL
else:
return "No bible study this week! We'll be having " + topic + " instead"
def formatThisMonthItems():
items = getThisMonthItems()
twoLength = len(items)
output = []
for i in range(twoLength):
currentItem = items[i]
length = len(currentItem)
concatDate = "<b>" + currentItem[0] + " " + currentItem[1] + "</b>"
strOutput = concatDate
strOutput += "\n"
for j in range(2, length):
strOutput += headers[j-2] + currentItem[j]
strOutput += "\n"
output.append(strOutput)
return output
def formatThisWeekItems():
items = getThisWeekItems()
twoLength = len(items)
output = []
for i in range(twoLength):
currentItem = items[i]
length = len(currentItem)
concatDate = "<b>" + currentItem[0] + " " + currentItem[1] + "</b>"
strOutput = concatDate
strOutput += "\n"
for j in range(2, length):
if (currentItem[j] == ""):
break
strOutput += headers[j-2] + currentItem[j]
strOutput += "\n"
output.append(strOutput)
return output
def getThisWeekItemsFormatted():
formatted = formatThisWeekItems()
output = ""
for item in formatted:
output += item + "\n"
return output
def getThisMonthItemsFormatted():
formatted = formatThisMonthItems()
output = ""
for item in formatted:
output += item + "\n"
return output
def getUpcoming():
output = formatThisWeekItems()[0]
if ("CAP" in output):
return output
if ("No CG" in output):
date = output.split("\n")[0]
return date + "\nNo CG this week. Go hang out!"