Skip to content

Commit

Permalink
Merge pull request #2 from YanivDorGalron/saving_token
Browse files Browse the repository at this point in the history
Saving token
  • Loading branch information
YanivDorGalron authored Sep 28, 2024
2 parents bf4a0ec + ac8adde commit 1b67dff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To create an executable file using PyInstaller, follow these steps:

2. Command to create executable:
```
pyinstaller --add-data "sounds;sounds" FocusApp.py --name FocusApp --noconsole --add-data "cred.json;. --onefile"
pyinstaller --add-data "sounds;sounds" FocusApp.py --name FocusApp --noconsole --add-data "cred.json;." --onefile"
```
3. The executable file will be generated in the `dist` folder.
Expand Down
Binary file renamed dist/FocusApp1.exe → dist/FocusApp.exe
Binary file not shown.
7 changes: 4 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@

def authenticate_google_calendar():
creds = None
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file(get_resource_path('token.json'), SCOPES)
token_path = os.path.join(os.path.expanduser('~'), 'focus_app_token.json') # Store in home directory
if os.path.exists(token_path):
creds = Credentials.from_authorized_user_file(token_path, SCOPES)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(get_resource_path('cred.json'), SCOPES)
creds = flow.run_local_server(port=0)
with open(get_resource_path('token.json'), 'w') as token:
with open(token_path, 'w') as token: # Use updated token path
token.write(creds.to_json())
return build('calendar', 'v3', credentials=creds)

Expand Down

0 comments on commit 1b67dff

Please sign in to comment.