Skip to content

Commit

Permalink
fix: #443
Browse files Browse the repository at this point in the history
  • Loading branch information
yihong0618 committed Jul 6, 2023
1 parent fda0a1d commit d76bf39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
42 changes: 22 additions & 20 deletions scripts/generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, db_path):
self.client_id = ""
self.client_secret = ""
self.refresh_token = ""
self.only_run = False

def set_strava_config(self, client_id, client_secret, refresh_token):
self.client_id = client_id
Expand All @@ -42,7 +43,7 @@ def check_access(self):
self.client.access_token = response["access_token"]
print("Access ok")

def sync(self, force, only_run=False):
def sync(self, force):
self.check_access()

print("Start syncing")
Expand All @@ -58,7 +59,7 @@ def sync(self, force, only_run=False):
filters = {"before": datetime.datetime.utcnow()}

for activity in self.client.get_activities(**filters):
if only_run and activity.type != "Run":
if self.only_run and activity.type != "Run":
continue
if IGNORE_BEFORE_SAVING:
activity.summary_polyline = filter_out(activity.summary_polyline)
Expand Down Expand Up @@ -113,25 +114,26 @@ def load(self):
streak = 0
last_date = None
for activity in activities:
if self.only_run and activity.type != "Run":
continue
# Determine running streak.
if activity.type == "Run":
date = datetime.datetime.strptime(
activity.start_date_local, "%Y-%m-%d %H:%M:%S"
).date()
if last_date is None:
streak = 1
elif date == last_date:
pass
elif date == last_date + datetime.timedelta(days=1):
streak += 1
else:
assert date > last_date
streak = 1
activity.streak = streak
last_date = date
if not IGNORE_BEFORE_SAVING:
activity.summary_polyline = filter_out(activity.summary_polyline)
activity_list.append(activity.to_dict())
date = datetime.datetime.strptime(
activity.start_date_local, "%Y-%m-%d %H:%M:%S"
).date()
if last_date is None:
streak = 1
elif date == last_date:
pass
elif date == last_date + datetime.timedelta(days=1):
streak += 1
else:
assert date > last_date
streak = 1
activity.streak = streak
last_date = date
if not IGNORE_BEFORE_SAVING:
activity.summary_polyline = filter_out(activity.summary_polyline)
activity_list.append(activity.to_dict())

return activity_list

Expand Down
3 changes: 2 additions & 1 deletion scripts/strava_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def run_strava_sync(client_id, client_secret, refresh_token, only_run=False):
generator = Generator(SQL_FILE)
generator.set_strava_config(client_id, client_secret, refresh_token)
# if you want to refresh data change False to True
generator.sync(False, only_run=only_run)
generator.only_run = only_run
generator.sync(False)

activities_list = generator.load()
with open(JSON_FILE, "w") as f:
Expand Down

1 comment on commit d76bf39

@vercel
Copy link

@vercel vercel bot commented on d76bf39 Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

running-page – ./

running-page-git-master-yihong0618.vercel.app
running-page.vercel.app
running-page-yihong0618.vercel.app

Please sign in to comment.