Skip to content

Commit

Permalink
Created second flask app.
Browse files Browse the repository at this point in the history
  • Loading branch information
marvintensuan committed Feb 7, 2021
1 parent 96fd939 commit 6c5f336
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 13 deletions.
6 changes: 6 additions & 0 deletions mrvn_flask/cloudmigrate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
steps:
- name: "gcr.io/cloud-builders/docker"
args: ["build", "-t", "gcr.io/projects-300508/mrvn_flask", "."]

- name: "gcr.io/cloud-builders/docker"
args: ["push", "gcr.io/projects-300508/mrvn_flask"]
4 changes: 3 additions & 1 deletion mrvn_flask/__init__.py → mrvn_flask/flaskapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import google.auth
from google.cloud import secretmanager_v1beta1 as sm
except ImportError:
print("Import Error raised.")
pass

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
env_file = os.path.join(BASE_DIR, ".env")

SETTINGS_NAME = "application_settings"
SETTINGS_NAME = "flask_app_settings"

def create_app(test_config=None):
# create and configure the app
Expand All @@ -33,6 +34,7 @@ def create_app(test_config=None):
env.read_env(env_file)
SECRET_KEY= env('SECRET_KEY'),
# DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "env('GOOGLE_APPLICATION_CREDENTIALS')"
)
if test_config is None:
# load the instance config, if it exists, when not testing
Expand Down
14 changes: 14 additions & 0 deletions mrvn_flask/flaskapp/get_from_firestore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from google.cloud import firestore
try:
import google.auth
from google.cloud import secretmanager_v1beta1 as sm
except ImportError:
print("Import Error raised.")
pass

def my_reddit_comments():
db = firestore.Client()
coll = db.collection('tagapagtuos_submissions').stream()
db = None

return [doc.to_dict() for doc in coll]
15 changes: 5 additions & 10 deletions mrvn_flask/home.py → mrvn_flask/flaskapp/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
from flask import (
Blueprint, flash, g, redirect, render_template, request, session, url_for
)
from google.cloud import firestore

from .get_from_firestore import my_reddit_comments

bp = Blueprint('home', __name__)

@bp.route('/', methods=['GET'])
@bp.route('/sample', methods=['GET'])
def home():
context = my_reddit_comments()
return render_template('sample.html', context=context)

def my_reddit_comments():
db = firestore.Client()
coll = db.collection('tagapagtuos_submissions').stream()
db = None

return [doc.to_dict() for doc in coll]

@bp.route('/cv')
@bp.route('/')
def baseee():
return render_template('home.html')
8 changes: 8 additions & 0 deletions mrvn_flask/flaskapp2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.8-slim
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]
47 changes: 47 additions & 0 deletions mrvn_flask/flaskapp2/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'''
Adapted from "Build and deploy a Flask CRUD API with Firestore and Cloud Run"
Author: @timtech4u
https://cloud.google.com/community/tutorials/building-flask-api-with-cloud-firestore-and-deploying-to-cloud-run
'''

# Required imports
import os
from flask import Flask, request, render_template
#from firebase_admin import credentials, firestore, initialize_app


# Initialize Flask app
app = Flask(__name__)

# Initialize Firestore DB
#cred = credentials.Certificate('key.json')
#default_app = initialize_app(cred)
#db = firestore.client()
#todo_ref = db.collection('todos')
'''
from google.cloud import firestore
try:
import google.auth
from google.cloud import secretmanager_v1beta1 as sm
except ImportError:
print("Import Error raised.")
pass
def my_reddit_comments():
db = firestore.Client()
coll = db.collection('tagapagtuos_submissions').stream()
db = None
return [doc.to_dict() for doc in coll]
@app.route('/sample', methods=['GET'])
def sample():
context = my_reddit_comments()
return render_template('sample.html', context=context)
'''
@app.route('/')
def home():
return render_template('home.html')

port = int(os.environ.get('PORT', 8080))
if __name__ == '__main__':
app.run(threaded=True, host='0.0.0.0', port=port)
26 changes: 26 additions & 0 deletions mrvn_flask/flaskapp2/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cachetools==4.2.0
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
Flask==1.1.2
google-api-core==1.24.1
google-auth==1.24.0
google-cloud-core==1.5.0
google-cloud-firestore==2.0.2
googleapis-common-protos==1.52.0
grpcio==1.34.0
gunicorn==20.0.4
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
proto-plus==1.13.0
protobuf==3.14.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pytz==2020.5
requests==2.25.1
rsa==4.6
six==1.15.0
urllib3==1.26.2
Werkzeug==1.0.1
File renamed without changes.
File renamed without changes.
161 changes: 161 additions & 0 deletions mrvn_flask/flaskapp2/templates/sample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{% extends 'base.html' %}
{% block container %}
<script>
$(".nav-link").eq(0).addClass("active")
</script>

<div class="container mx-auto">
{% for i in context %}
<p><h1>Submission:</h1></p>
<p>
{{ i['subreddit']}}<br>
{{ i['date']}}<br>
{{ i['body']}}<br>
{{ i['url']}}<br>
-----------------
</p>
{% endfor %}
</div>



<!--- Title and Social Media Links -->
<div class="container" style="text-align: center;">
<p style="font-size: 3em; font-weight: bold; margin: 1em auto auto auto;">Marvin D. Tensuan</p>
<p style="font-size: 2em;">Curriculum Vitae</p>
<nav class="btn-group btn-group-justified btn-group" role="group"
style="max-width: 20%; min-width: 256px; margin: auto; background-color: green;">

<button type="button" class="btn btn-secondary">
<a class="btn btn-default" role="button" href="https://www.linkedin.com/in/marvintensuan">
<img src="https://www.republiccapitalaccess.com/wp-content/uploads/2014/07/linkedin-icon.png" height="25px">
</a>
</button>
<button type="button" class="btn btn-secondary">
<a class="btn btn-default" role="button" href="mailto:marvintensuan@outlook.com">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Microsoft_Outlook_2013_logo.svg/1200px-Microsoft_Outlook_2013_logo.svg.png" height="25px">
</a>
</button>
<button type="button" class="btn btn-secondary">
<a class="btn btn-default" role="button" href="https://github.com/marvintensuan">
<img src="https://digitallabs.mmu.ac.uk/wp-content/uploads/2018/04/github_logo.png" height="25px">
</a>
</button>
</nav>
</div>
<!--- Work Experience-->
<div class="container mt-5">
<section class="row">
<div class="col-md-5 contents-label">Work Experience</div>
<div class="col-md-7">
<h3 style="font-weight: bold;">Deutsche Knowledge Services Pte. Ltd.</h3>
<h4 style="font-weight: bold;">Senior Financial Analyst | Central FX Team (October 2020 to <em>present</em>)</h4>
<p>Assist in the creation of a global-scope FX team.</p>
<h4 style="font-weight: bold;">Financial Analyst | FX Management (June 2018 to September 2020)</h4>
<p>
The FX Management team is mandated to hedge cost-related foreign currency transactions incurred from major Deutsche Bank branches across US, UK, and APAC.
<ul>
<li>Process improvements through Excel VBA automations</li>
<li>Cross-team process improvements through lean principles</li>
<li>1x Employee of the Month, May 2020</li>
<li>2x Spot Awardee</li>
<li>1x Gold Medalist, Continuous Improvement Award</li>
</ul>
</p>
</div>
</section>
</div>

<!--- Professional Certifications-->
<div class="container mt-5">
<section class="row mb-5">
<div class="col-md-5 contents-label"> Certifications</div>
<div class="col-md-7">
<!---Licenses-->
<h3>Professional Licenses</h3>
<ul>
<li>
<p style="line-height: 50%; font-weight: bold;">Certified Public Accountant</p>
<p>Philippine Regulatory Board of Accountancy (May 2018 &ndash; <em>present</em>)</p>
</li>
</ul>

<!---Memberships-->
<h3>Memberships</h3>
<ul>
<li>
<p>Philippine Institute of Certified Public Accountants</p>
</li>
</ul>
</div>
</div>

</section>
<!--- Training and Development-->
<div class="container">
<section class="row">
<div class="col-md-5 contents-label">Training and Development</div>
<div class="col-md-7">
<a href="https://marvintensuan.github.io">
<button type="button" class="btn btn-secondary btn-block text-decoration-none mb-5">
Link to Portfolio (GitHub Pages)
</button>
</a>
<a href="https://www.marvintensuan.com/list_of_cpds">
<button type="button" class="btn btn-secondary btn-block text-decoration-none mb-5">
Continuous Professional Education
</button>
</a>
<a href="https://www.marvintensuan.com/list_of_cpds">
<button type="button" class="btn btn-secondary btn-block text-decoration-none mb-5">
Self-Directed Learning
</button>
</a>

</div>
</section>
<section>

</section>
</div>

<!--- Academic Background-->
<div class="container">
<section class="row">
<div class="col-md-5 contents-label">Academic Background</div>
<div class="col-md-7">
<!--- Graduate: empty :( -->
<!---Tertiary-->
<p><h3>Bachelor of Science in Accountancy</h3></p>
<p>Polytechnic University of the Philippines (June 2013 to October 2017)</p>
<p>Extra and co-curricular activities:</p>
<ul>
<li>PWC M&A Challenge (2017)</li>
<li>UP JPIA APEX Challenge (2017)</li>
<li>NFJPIA-NCR 9th Annual Grand Summit (2016)</li>
<li>SYNTHESIS (2016)</li>
<li>COL-JAPI Stock Market Challenge (2015)</li>
<li>Student Representative (2014)</li>
<li>PUP JPIA Mathematics Competition (2013)</li>
</ul>
<!---Secondary-->
<p><h3>Muntinlupa Science High School</h3></p>
<p>(June 2009 to March 2013)</p>
<ul>
<li>Editor-in-Chief, Ang Matyag</li>
<li>Finalist, Philippine Robotics Olympiad 2012</li>
<li>Champion, 9th UP-ERG Dagitab Competition</li>
<li>Outdoorsman, Boy Scouts of the Philippines</li>
</ul>
<!---Primary-->
<p><h3>Itaas Elementary School</h3></p>
<p>(June 2003 to March 2009)</p>
<ul>
<li>8<sup>th</sup> honorable mention</li>
<li>Science News Editor, Rootlets</li>
<li>Patrol Leader, Boy Scouts of the Philippines</li>
</ul>
</div>
</section>
</div>
{% endblock %}
7 changes: 5 additions & 2 deletions mrvn_flask/Dockerfile → mrvn_flask/old_Dockerfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ COPY . .

# Service must listen to $PORT environment variable.
# This default value facilitates local development.
ENV PORT 8080
EXPOSE 5000
ENV PORT 5000

# Setting this ensures print statements and log messages
# promptly appear in Cloud Logging.
ENV PYTHONUNBUFFERED TRUE

ENV FLASK_APP flaskapp

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind 0.0.0.0:$PORT --workers 1 --threads 8 --timeout 0 "mrvn_flask:create_app()"
CMD exec gunicorn --bind 0.0.0.0:$PORT --workers 1 --threads 8 --timeout 0 "flaskapp:create_app()"

0 comments on commit 6c5f336

Please sign in to comment.