-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforcing black formatting, adding CI
- Loading branch information
1 parent
31e4f2d
commit 71a63f3
Showing
5 changed files
with
140 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: Lint | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: psf/black@stable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,76 @@ | ||
import csv | ||
import os | ||
#to install fitparse, run | ||
#sudo pip3 install -e git+https://github.com/dtcooper/python-fitparse#egg=python-fitparse | ||
|
||
# to install fitparse, run | ||
# sudo pip3 install -e git+https://github.com/dtcooper/python-fitparse#egg=python-fitparse | ||
import fitparse | ||
import pytz | ||
|
||
allowed_fields = ['timestamp','position_lat','position_long', 'distance', | ||
'enhanced_altitude', 'altitude','enhanced_speed', | ||
'speed', 'heart_rate','cadence','fractional_cadence'] | ||
required_fields = ['timestamp', 'position_lat', 'position_long', 'altitude'] | ||
allowed_fields = [ | ||
"timestamp", | ||
"position_lat", | ||
"position_long", | ||
"distance", | ||
"enhanced_altitude", | ||
"altitude", | ||
"enhanced_speed", | ||
"speed", | ||
"heart_rate", | ||
"cadence", | ||
"fractional_cadence", | ||
] | ||
required_fields = ["timestamp", "position_lat", "position_long", "altitude"] | ||
|
||
UTC = pytz.UTC | ||
CST = pytz.timezone('US/Central') | ||
CST = pytz.timezone("US/Central") | ||
|
||
|
||
def main(): | ||
files = os.listdir() | ||
fit_files = [file for file in files if file[-4:].lower()=='.fit'] | ||
fit_files = [file for file in files if file[-4:].lower() == ".fit"] | ||
for file in fit_files: | ||
new_filename = file[:-4] + '.csv' | ||
new_filename = file[:-4] + ".csv" | ||
if os.path.exists(new_filename): | ||
#print('%s already exists. skipping.' % new_filename) | ||
# print('%s already exists. skipping.' % new_filename) | ||
continue | ||
fitfile = fitparse.FitFile(file, | ||
data_processor=fitparse.StandardUnitsDataProcessor()) | ||
fitfile = fitparse.FitFile( | ||
file, data_processor=fitparse.StandardUnitsDataProcessor() | ||
) | ||
|
||
print('converting %s' % file) | ||
print("converting %s" % file) | ||
write_fitfile_to_csv(fitfile, new_filename) | ||
print('finished conversions') | ||
print("finished conversions") | ||
|
||
|
||
def write_fitfile_to_csv(fitfile, output_file='test_output.csv'): | ||
def write_fitfile_to_csv(fitfile, output_file="test_output.csv"): | ||
messages = fitfile.messages | ||
data = [] | ||
for m in messages: | ||
skip=False | ||
if not hasattr(m, 'fields'): | ||
skip = False | ||
if not hasattr(m, "fields"): | ||
continue | ||
fields = m.fields | ||
#check for important data types | ||
# check for important data types | ||
mdata = {} | ||
for field in fields: | ||
if field.name in allowed_fields: | ||
if field.name=='timestamp': | ||
if field.name == "timestamp": | ||
mdata[field.name] = UTC.localize(field.value).astimezone(CST) | ||
else: | ||
mdata[field.name] = field.value | ||
for rf in required_fields: | ||
if rf not in mdata: | ||
skip=True | ||
skip = True | ||
if not skip: | ||
data.append(mdata) | ||
#write to csv | ||
with open(output_file, 'w') as f: | ||
# write to csv | ||
with open(output_file, "w") as f: | ||
writer = csv.writer(f) | ||
writer.writerow(allowed_fields) | ||
for entry in data: | ||
writer.writerow([ str(entry.get(k, '')) for k in allowed_fields]) | ||
print('wrote %s' % output_file) | ||
writer.writerow([str(entry.get(k, "")) for k in allowed_fields]) | ||
print("wrote %s" % output_file) | ||
|
||
|
||
if __name__=='__main__': | ||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,73 @@ | ||
from selenium import webdriver | ||
import time | ||
driver = webdriver.Chrome(executable_path='<replace>') | ||
|
||
download_dir = '<replace>' | ||
driver = webdriver.Chrome(executable_path="<replace>") | ||
|
||
download_dir = "<replace>" | ||
|
||
options = webdriver.ChromeOptions() | ||
options.add_argument('--ignore-certificate-errors') | ||
options.add_argument("--ignore-certificate-errors") | ||
options.add_argument("--test-type") | ||
options.binary_location = "/usr/bin/chromium-browser" | ||
|
||
options.add_experimental_option('prefs', { | ||
"plugins.plugins_list": [{"enabled":False,"name":"Chrome PDF Viewer"}], | ||
"download": { | ||
"prompt_for_download": False, | ||
"default_directory" : download_dir | ||
} | ||
}) | ||
options.add_experimental_option( | ||
"prefs", | ||
{ | ||
"plugins.plugins_list": [{"enabled": False, "name": "Chrome PDF Viewer"}], | ||
"download": {"prompt_for_download": False, "default_directory": download_dir}, | ||
}, | ||
) | ||
driver = webdriver.Chrome(chrome_options=options) | ||
|
||
usern, passw, id = open('login_info.secret').read().strip().split(',') | ||
usern, passw, id = open("login_info.secret").read().strip().split(",") | ||
|
||
driver.get('http://strava.com/login') | ||
driver.get("http://strava.com/login") | ||
|
||
usern_box = driver.find_element_by_xpath("//input[@name='email' and @type='email']") | ||
usern_box.send_keys(usern) | ||
|
||
passw_box = driver.find_element_by_xpath("//input[@name='password' and @type='password']") | ||
passw_box = driver.find_element_by_xpath( | ||
"//input[@name='password' and @type='password']" | ||
) | ||
passw_box.send_keys(passw) | ||
|
||
submit_button = driver.find_element_by_xpath('//button[@id="login-button"]') | ||
submit_button.click() | ||
|
||
time.sleep(2) | ||
|
||
driver.get("https://www.strava.com/athletes/"+str(id)) | ||
driver.get("https://www.strava.com/athletes/" + str(id)) | ||
|
||
monthly_button = driver.find_element_by_xpath('//a[contains(@class,"button btn-xs") and contains(@href,"month")]') | ||
monthly_button = driver.find_element_by_xpath( | ||
'//a[contains(@class,"button btn-xs") and contains(@href,"month")]' | ||
) | ||
monthly_button.click() | ||
|
||
time.sleep(2) | ||
|
||
bar_list = driver.find_elements_by_xpath('//a[@class="bar" and contains(@href,"interval")]') | ||
bar_list = driver.find_elements_by_xpath( | ||
'//a[@class="bar" and contains(@href,"interval")]' | ||
) | ||
|
||
activity_list = [] | ||
|
||
for bar in bar_list: | ||
bar.click() | ||
time.sleep(3) | ||
|
||
for a in driver.find_elements_by_xpath('.//a[contains(@href, "activities") and not(contains(@href, "twitter")) and not(contains(@href, "#")) and not(contains(@href, "photos")) and not(contains(@href, "segments"))]'): | ||
activity_list.append(a.get_attribute('href')) | ||
for a in driver.find_elements_by_xpath( | ||
'.//a[contains(@href, "activities") and not(contains(@href, "twitter")) and not(contains(@href, "#")) and not(contains(@href, "photos")) and not(contains(@href, "segments"))]' | ||
): | ||
activity_list.append(a.get_attribute("href")) | ||
|
||
activity_list = set(activity_list) | ||
|
||
print('Number of activities found: ',len(activity_list)) | ||
print("Number of activities found: ", len(activity_list)) | ||
|
||
for address in activity_list: | ||
driver.get(address+"/export_gpx") | ||
driver.get(address + "/export_gpx") | ||
time.sleep(1) | ||
|
||
print('Data downloaded to '+download_dir+', quitting.') | ||
print("Data downloaded to " + download_dir + ", quitting.") | ||
|
||
driver.quit() |
Oops, something went wrong.