Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuzina committed Apr 12, 2023
2 parents 4db2134 + 4af57ce commit e98a328
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 98 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*Venv*
*venv*

# User uploaded files directory
uploads/
# sensitive auth data
Expand Down
25 changes: 7 additions & 18 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# App launch-point

# ---- Dependency imports ---- #
from enum import unique
import logging
import math
import os
import time
from configparser import ConfigParser, RawConfigParser
from datetime import datetime, timedelta
from os.path import exists
from werkzeug.utils import secure_filename

from flask import (Flask, Response, redirect, render_template, request,
from flask import (Flask, redirect, render_template, request,
send_file, session, url_for)
from flask_assets import Bundle, Environment

Expand All @@ -21,6 +19,9 @@
import glob
import shutil

from dotenv import load_dotenv
load_dotenv()

# ---------------------------- #
ALLOWED_EXTENSIONS = {'png', 'jpeg', 'jpg', 'gpx'}

Expand Down Expand Up @@ -71,13 +72,6 @@
assets.config['PYSCSS_ASSETS_ROOT'] = assets.directory

assets.register('scss_all', scss)
# -------- Read and load config data -------- #
configParser = RawConfigParser()
configFilePath = r'./app.cfg'
configParser.read(configFilePath)

config = ConfigParser()
config.read_file(open(r'./app.cfg'))
# -------------------------------------------- #

import networks.strava # Must be imported after config has been read
Expand All @@ -86,8 +80,8 @@
userCachedData = {}

apis = {
'strava': networks.strava.StravaApi(config, flaskApp),
#'twitter': networks.twitter.twitterApi(config, flaskApp)
'strava': networks.strava.StravaApi(flaskApp),
#'twitter': networks.twitter.twitterApi(flaskApp)
}

shareAuthURLs = {}
Expand Down Expand Up @@ -159,7 +153,6 @@ def render_parameters():
for file in request.files.getlist('gpxFile'):
if file and functions.allowed_file(file.filename, ALLOWED_EXTENSIONS):
filename = secure_filename(functions.randomAlphanumericString(16) + "_" + file.filename)
#print(file)
file.save(os.path.join(flaskApp.config['UPLOAD_FOLDER'] + "/" + uniqueId, filename))

if not uniqueId in userCachedData:
Expand Down Expand Up @@ -340,8 +333,4 @@ def render_privacyPage():
if sessionDataValidationResult == True:
return render_template('privacyPage.html', userData = session['userData'])
else:
return render_template('privacyPage.html')

# Store any config items not related to API logins under app.config
for key in config["DEFAULT"]:
flaskApp.config[key] = config["DEFAULT"][key]
return render_template('privacyPage.html')
17 changes: 9 additions & 8 deletions networks/strava.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
import math
import os
import time
from flask import Flask, redirect, render_template, request, url_for, Response
from flask import redirect, request, url_for
import functions
import generateVis
import polyline
import app as main
import datetime
# ---------------------------- #
class StravaApi:
def __init__(self, cfg, app):
def __init__(self, app):
# Configure strava-specific connection details
self.configCode = 'strava'
self.configDetails = cfg[self.configCode]
self.tokenUrl = self.configDetails['TOKEN_URL'].strip('\'')
self.clientId = self.configDetails['CLIENT_ID'].strip('\'')
self.clientSecret = self.configDetails['CLIENT_SECRET'].strip('\'')
self.authUrl = self.configDetails['AUTH_URL'].strip('\'')
self.tokenUrl = 'https://www.strava.com/oauth/token'.strip('\'')
self.clientId = os.getenv('STRAVA_CLIENT_ID').strip('\'')
self.clientSecret = os.getenv('STRAVA_CLIENT_SECRET').strip('\'')
self.authUrl = "www.strava.com/oauth/authorize?client_id={client_id}&response_type=code&redirect_uri={app_address}/strava-login&approval_prompt=auto&scope=read,activity:read".format(client_id=os.getenv('STRAVA_CLIENT_ID'), app_address=os.getenv('APP_ADDRESS') or 'http://127.0.0.1:5000').strip('\'')
self.verifyToken = str(binascii.hexlify(os.urandom(24)))[2:-1]
self.loginWith = True


# Handle Strava authentication. When users successfully log in to Strava, they are sent to {site-url}/strava-login
@app.route('/' + self.configCode + '-login')
def stravaAuth():
Expand All @@ -41,6 +40,8 @@ def stravaAuth():
# Store user activities
main.userCachedData[uniqueId] = self.getActivitiesInRange()

print(main.userCachedData[uniqueId])

if len(main.userCachedData[uniqueId]) > 0:
# Render parameters page
return redirect(url_for('render_parameters'))
Expand Down
73 changes: 14 additions & 59 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,15 @@
# GPX Visualizer

# Windows Environment Setup
Terminal commands in this section can be executed in Windows Powershell or Microsoft Visual Studio Code.
- Install [Python](https://www.python.org/downloads/).
- Install virtualenv: `pip3 install --user virtualenv`
- Create virtual environment: `python -m virtualenv CapstoneVenv`
- If this command opens the Microsoft Store, follow the instructions [here](https://stackoverflow.com/a/58773979) to make a command exception for Python and repeat the command.
- If this command returns an error result stating that the python command could not be found, follow the instructions [here](https://www.geeksforgeeks.org/how-to-add-python-to-windows-path/).
- Activate virtual environment: `CapstoneVenv/Scripts/activate.bat`
- Clone repo: `git clone https://github.com/joemuzina/capstone`
- Install Flask & its dependencies
- `pip3 install flask`
- `pip3 install Flask-Assets`
- `pip3 install pyscss`
- `pip3 install configparser`
- `pip3 install requests`
- `pip3 install gpxpy`
- `pip3 install pandas`
- `pip3 install tweepy`
- Complete app.cfg
- Log in to the shared Strava account. The app API tokens/etc. are in the [API dashboard](https://www.strava.com/settings/api).
- In `AUTH_URL`: replace `{ID}` with the Client ID from the dashboard
- Replace `CLIENT_ID` with the Client ID from the dashboard
- Replace `CLIENT_SECRET` with the Client Secret from the dashboard
- Replace `SECRET_KEY` with a random string, whatever you like.
- Fill in Twitter credentials using information securely sent via Bitwarden.
- Open Capstone project folder: `cd Capstone`
- Run web server using the flask executable. In my case the command is `python -m flask run` < should start the webserver.

# Linux Environment Setup
- Clone repo: `git clone https://github.com/joemuzina/capstone`
- Install Nginx: `sudo apt-get install nginx`
- Set up Nginx to proxy the Flask server: [instructions](https://stackoverflow.com/questions/11443917/why-does-gunicorn-use-port-8000-8001-instead-of-80)
- Set Nginx upload limit to 50m: [instructions](https://learn.coderslang.com/0018-how-to-fix-error-413-request-entity-too-large-in-nginx/)
- Install Python dependencies
- Python3 venv: `apt install python3.8-venv`
- VirtualEnv: `sudo apt-get install python3-virtualenv`
- Python3: `sudo apt-get install python3`
- Create venv
- `python3 -m venv venv/`
- `.venv/bin/activate`
- Install Flask & its dependencies
- `pip3 install flask`
- `pip3 install Flask-Assets`
- `pip3 install pyscss`
- `pip3 install configparser`
- `pip3 install requests`
- `pip3 install gpxpy`
- `pip3 install pandas`
- `pip3 install tweepy`
- `pip3 install gunicorn`
- Complete app.cfg
- Log in to the shared Strava account. The app API tokens/etc. are in the [API dashboard](https://www.strava.com/settings/api).
- In `AUTH_URL`: replace `{ID}` with the Client ID from the dashboard
- Replace `CLIENT_ID` with the Client ID from the dashboard
- Replace `CLIENT_SECRET` with the Client Secret from the dashboard
- Replace `SECRET_KEY` with a random string, whatever you like.
- Fill in Twitter credentials using information securely sent via Bitwarden.
- Run web server: `bash start.sh`

## Features
* **Activity import**: Authenticate with Strava or load activities from GPX files
* **Activity filtering**: Filter activities by date, activity type, and other attributes
* **Generate custom images**: Turn your activities into images with custom color, background, and style!
------------------
## Building
- Install python dependencies: `pip install -r requirements.txt`
- Set environment variables (.env):
- `APP_ADDRESS`: Base address of the application where it is being served. If unset, the app will use `http://127.0.0.1:5000`.
- Strava auth data (see [Developer Dashboard](https://www.strava.com/settings/api))
- `STRAVA_CLIENT_ID`: Strava OAUTH Client ID
- `STRAVA_CLIENT_SECRET`: Strava OAUTH Client Secret
- Run Flask locally: `python3 -m flask run`
Binary file added requirements.txt
Binary file not shown.
2 changes: 0 additions & 2 deletions start.sh

This file was deleted.

5 changes: 0 additions & 5 deletions startNGINX.sh

This file was deleted.

5 changes: 0 additions & 5 deletions startVM.sh

This file was deleted.

2 changes: 1 addition & 1 deletion templates/aboutPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 id="about-title">About Us</h1>
<p>The GPX Visualizer was created in part by Joe Muzina, James Meyer, Parker Fisher, Adam Petrich and Anothony Moore</p>
<p>Its goal was to reach Strava users around the globe giving them the ability to share their runs in a new and innovative way</p>
<p>
<a class="button btn button-custom hello-button" href="https://github.com/jmuzina/Capstone" target = "_blank" >
<a class="button btn button-custom hello-button" href="https://github.com/jmuzina/gpxvis" target = "_blank" >
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-github" viewBox="0 0 16 16">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"/>
</svg>
Expand Down

0 comments on commit e98a328

Please sign in to comment.