Skip to content

Commit

Permalink
Merge branch 'upstream'
Browse files Browse the repository at this point in the history
* upstream:
  fix: use garth package
  fix: reverse bug

# Conflicts:
#	requirements.txt
#	run_page/garmin_sync.py
#	run_page/generator/db.py
  • Loading branch information
ben-29 committed Sep 27, 2023
2 parents 0aba758 + e088d55 commit b35a920
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ numpy
tzlocal
fit-tool
haversine==2.8.0
git+https://github.com/yihong0618/garth.git
garth


bs4
html.parser
Expand Down
6 changes: 1 addition & 5 deletions run_page/garmin_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import json
import logging
import os
import re
import sys
import time
import traceback
Expand All @@ -21,7 +20,6 @@
import httpx
from config import FOLDER_DICT, JSON_FILE, SQL_FILE, config
from garmin_device_adaptor import wrap_device_info
from tenacity import retry, stop_after_attempt, wait_fixed
from utils import make_activities_file_only

# logging.basicConfig(level=logging.DEBUG)
Expand All @@ -44,7 +42,6 @@
"BASE_URL": "https://connectapi.garmin.cn",
"SSO_URL_ORIGIN": "https://sso.garmin.com",
"SSO_URL": "https://sso.garmin.cn/sso",
# "MODERN_URL": "https://connect.garmin.cn/modern",
"MODERN_URL": "https://connectapi.garmin.cn",
"SIGNIN_URL": "https://sso.garmin.cn/sso/signin",
"CSS_URL": "https://static.garmincdn.cn/cn.garmin.connect/ui/css/gauth-custom-v1.2-min.css",
Expand All @@ -70,7 +67,7 @@ def __init__(self, secret_string, auth_domain, is_only_running=False):
else GARMIN_COM_URL_DICT
)
self.modern_url = self.URL_DICT.get("MODERN_URL")
garth.resume_from_string(secret_string)
garth.client.loads(secret_string)
if garth.client.oauth2_token.expired:
garth.client.refresh_oauth2()

Expand Down Expand Up @@ -108,7 +105,6 @@ async def fetch_data(self, url, retrying=False):
"Exception occurred during data retrieval - perhaps session expired - trying relogin: %s"
% err
)
self.login()
await self.fetch_data(url, retrying=True)

async def get_activities(self, start, limit):
Expand Down
14 changes: 5 additions & 9 deletions run_page/generator/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import string
import time

import geopy
from config import TYPE_DICT
from geopy.geocoders import Nominatim
from sqlalchemy import Column, Float, Integer, Interval, String, create_engine
Expand All @@ -11,16 +12,14 @@

Base = declarative_base()

import random
import string


# random user name 8 letters
def randomword():
letters = string.ascii_lowercase
return "".join(random.choice(letters) for i in range(8))
return "".join(random.choice(letters) for i in range(4))


geopy.geocoders.options.default_user_agent = "my-application"
# reverse the location (lan, lon) -> location detail
g = Nominatim(user_agent=randomword())

Expand Down Expand Up @@ -94,14 +93,12 @@ def update_or_create_activity(session, run_activity):
g.reverse(f"{start_point.lat}, {start_point.lon}")
)
# limit (only for the first time)
except:
print("+++++++limit+++++++")
time.sleep(2)
except Exception as e:
try:
location_country = str(
g.reverse(f"{start_point.lat}, {start_point.lon}")
)
except:
except Exception as e:
pass

activity = Activity(
Expand Down Expand Up @@ -138,7 +135,6 @@ def update_or_create_activity(session, run_activity):
except Exception as e:
print(f"something wrong with {run_activity.id}")
print(str(e))
pass

return created

Expand Down
2 changes: 1 addition & 1 deletion run_page/get_garmin_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
if options.is_cn:
garth.configure(domain="garmin.cn")
garth.login(options.email, options.password)
secret_string = garth.save_to_string()
secret_string = garth.client.dumps()
print(secret_string)

0 comments on commit b35a920

Please sign in to comment.