Skip to content

Commit 2a2612f

Browse files
committed
activity fetching
1 parent 70d8b10 commit 2a2612f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

runkeeper/Account.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import typing
1010

11+
1112
class Account(User):
1213
def __init__(self, email: str, password: str):
1314
self.session = requests.Session()
@@ -56,7 +57,7 @@ def get_activity_list(self) -> typing.Dict[int, typing.Dict[int, int]]:
5657
"""
5758
Example Return:
5859
{2020: {1: 10, 2: 11, 3: 15}}
59-
10 activities in January 2020, 11 in February 2020, and 15 in March 2020
60+
this would mean 10 activities in January 2020, 11 in February 2020, and 15 in March 2020
6061
6162
:return: number of activities for each month with at least one activity
6263
:rtype: dict

runkeeper/User.py

+27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
import requests
2+
3+
from datetime import datetime
4+
5+
import typing
6+
7+
18
class User:
29
def __init__(self, username: str):
310
self.username = username
11+
12+
def get_activities(self, month: int = None, year: int = None) -> typing.List[typing.Dict[str, str]]:
13+
"""
14+
:param month: month of specified year to fetch activities for
15+
:type month: int
16+
:param year: year to fetch activities for
17+
:type year: int
18+
:return: list of activities from the specified month
19+
:rtype: dict
20+
"""
21+
if month is None:
22+
month = datetime.now().month
23+
if year is None:
24+
year = datetime.now().year
25+
26+
start_date = datetime(year, month, 1)
27+
return requests.get('https://runkeeper.com/activitiesByDateRange', params={
28+
'userName': self.username,
29+
'startDate': start_date.strftime('%b-%d-%Y')
30+
}).json()['activities'][str(start_date.year)][start_date.strftime('%b')]

0 commit comments

Comments
 (0)