Skip to content

Commit

Permalink
Changed sheet key names
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixLuciano committed Nov 8, 2021
1 parent 2295308 commit 5a70890
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ The `config.json` (at project root) file contains essential definitions be for
"sheet": {
"id": "Google Sheet id",
"pages": {
"subscribers": "Subscribers tab name",
"unsibscribers": "Unsubscribers tab name"
"joins": "Subscribers tab name",
"leaves": "Unsubscribers tab name"
},
"columns": {
"date": "Date",
Expand Down
34 changes: 17 additions & 17 deletions scripts/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ def fetch_subscribers_data(credentials, config):
with build("sheets", "v4", credentials=credentials) as service:
sheets = service.spreadsheets().values()

subs_sheet = sheets.get(spreadsheetId=sheet_id, range=pages["subscribers"]).execute()
unsub_sheet = sheets.get(spreadsheetId=sheet_id, range=pages["unsibscribers"]).execute()
joins_sheet = sheets.get(spreadsheetId=sheet_id, range=pages["joins"]).execute()
leaves_sheet = sheets.get(spreadsheetId=sheet_id, range=pages["leaves"]).execute()

subs = to_table(subs_sheet["values"])
unsubs = to_table(unsub_sheet["values"])
joins = to_table(joins_sheet["values"])
leaves = to_table(leaves_sheet["values"])

return subs, unsubs
return joins, leaves


def split_date_iso(date):
Expand All @@ -81,32 +81,32 @@ def get_timestamp(object, config):
return datetime(*split_date_iso(object[date])).timestamp()


def filter_mailing_list(subs, unsubs, config):
def filter_mailing_list(joins, leaves, config):
mail_key = get_col("mail", config)
mailing_list = []

for sub in subs[::-1]:
for join in joins[::-1]:
jump = False
for contact in mailing_list:
if contact[mail_key] == sub[mail_key]:
if contact[mail_key] == join[mail_key]:
jump = True
break

if jump == True:
continue

is_subscribed = True
for unsub in unsubs[::-1]:
if unsub[mail_key] == sub[mail_key]:
sub_timestamp = get_timestamp(sub, config)
unsub_timestamp = get_timestamp(unsub, config)
is_joined = True
for leave in leaves[::-1]:
if leave[mail_key] == join[mail_key]:
join_timestamp = get_timestamp(join, config)
leave_timestamp = get_timestamp(leave, config)

if (unsub_timestamp - sub_timestamp > 0):
is_subscribed = False
if (leave_timestamp - join_timestamp > 0):
is_joined = False
break

if is_subscribed:
mailing_list.append(sub)
if is_joined:
mailing_list.append(join)

return mailing_list[::-1]

Expand Down

0 comments on commit 5a70890

Please sign in to comment.