Skip to content

Commit c97ab20

Browse files
Feat: Add a function to kill a process (ZwiftApp.exe)
1 parent ff5cd1e commit c97ab20

8 files changed

+489
-247
lines changed

Pipfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ pyyaml = "*"
1818
[dev-packages]
1919

2020
[requires]
21-
python_version = "3.8"
21+
python_version = "3.9"

Pipfile.lock

+464-238
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Thanks!:heart: and Cheers!:beers:
9595
---
9696

9797
### Contact
98-
If you have any question or suggestion, feel free to contact me at huaming.huang.tw@gmail.com. Contributions are also welcomed. Please open a [pull-request](https://github.com/hmhuang0501/Strava-Tool/compare) or an [issue](https://github.com/hmhuang0501/Strava-Tool/issues/new) in this repository.
98+
If you have any question or suggestion, feel free to contact me at huaming.huang.tw@gmail.com. Contributions are also welcomed. Please open a [pull-request](https://github.com/huaminghuangtw/Strava-Tool/compare) or an [issue](https://github.com/huaminghuangtw/Strava-Tool/issues/new) in this repository.
9999

100100
---
101101

StravaTool.bat

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
"C:\Users\USER\miniconda3\python.exe" "G:\My Drive\sourcecode\pythonscripts\StravaTool\src\StravaUploadTool_Main.py"
1+
@echo off
2+
cmd /k "cd /d G:\My Drive\sourcecode\pythonscripts\Strava-Tool\src & pipenv run python StravaUploadTool_Main.py"
23
pause

src/StravaAnalysisTool_Main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# https://www.strava.com/api/v3/athlete/activities?access_token=access_token_from_previous_step
2020
#
21-
# 3) Use refresh token to get new access tokens (i.e., getNewAccessTokens())
21+
# 4) Use refresh token to get new access tokens (i.e., getNewAccessTokens())
2222
#
2323
# https://www.strava.com/oauth/token?client_id=your_client_id&client_secret=your_client_secret&refresh_token=your_refresh_token_from_previous_step&grant_type=refresh_token
2424
#
@@ -27,7 +27,7 @@
2727

2828
def main():
2929
"""
30-
Since access tokens expire after 5 hours and you dont want to have to do all the manual work (step 1&2) all over again.
30+
Since access tokens expire after 5 hours and you don't want to have to do all the manual work (step 1&2) all over again.
3131
So, We first makes a call using the refresh token to retrieve the the most recent access token to ensure your program will always run!
3232
"""
3333
print(r"""

src/StravaUploadTool_Kernel.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,25 @@
33
from alive_progress import alive_bar
44
import requests, urllib3
55
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
6-
import os, glob, time
6+
import os, subprocess, glob, time
77
from typing import Any, Tuple
88

99

1010

11+
# --------------------------
12+
# function to kill a process
13+
# --------------------------
14+
def kill_process(process_name: str):
15+
# print(subprocess.getoutput('tasklist'))
16+
process_list = subprocess.Popen('tasklist', stdout=subprocess.PIPE).communicate()[0]
17+
if process_name.encode() in process_list:
18+
os.system("taskkill /im " + process_name + " /f") # Or: subprocess.call("taskkill /f /im " + process_name)
19+
print("Successfully kill the running process: " + process_name)
20+
else:
21+
print("Error: " + process_name + " is not running\n" + "Aborting...")
22+
raise SystemExit(0)
23+
24+
1125
# ------------------------------------
1226
# activity uploading related functions
1327
# ------------------------------------
@@ -86,7 +100,7 @@ def check_Upload_Status(access_token: str, filename: str, upload_ID: str) -> Tup
86100
print("ERROR - " + error + '\n')
87101
return (True, activity_id)
88102
else: # Possibility 3: Your activity is ready.
89-
print(status + ' ( ' + filename + ' )' + '\n')
103+
print(status + ' (' + filename + ')' + '\n')
90104
return (False, activity_id)
91105

92106

src/StravaUploadTool_Main.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#
2020
# https://www.strava.com/api/v3/athlete/activities?access_token=access_token_from_previous_step
2121
#
22-
# 3) Use refresh token to get new access tokens (i.e., getNewAccessTokens())
22+
# 4) Use refresh token to get new access tokens (i.e., getNewAccessTokens())
2323
#
2424
# https://www.strava.com/oauth/token?client_id=your_client_id&client_secret=your_client_secret&refresh_token=your_refresh_token_from_previous_step&grant_type=refresh_token
2525
#
@@ -28,9 +28,10 @@
2828

2929
def main():
3030
"""
31-
Since access tokens expire after 5 hours and you dont want to have to do all the manual work (step 1&2) all over again.
31+
Since access tokens expire after 5 hours and you don't want to have to do all the manual work (step 1&2) all over again.
3232
So, We first makes a call using the refresh token to retrieve the the most recent access token to ensure your program will always run!
3333
"""
34+
kill_process("ZwiftApp.exe")
3435
print(r"""
3536
_____ _ _ _ _ _ _______ _
3637
/ ____|| | | | | | | | | ||__ __| | |

webdriver/geckodriver.exe

-184 KB
Binary file not shown.

0 commit comments

Comments
 (0)