Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions BackEndChallenge/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/Users/emilymariemiller/Desktop/BackEndChallenge/myproject/bin/python"
}
69 changes: 69 additions & 0 deletions BackEndChallenge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

<!-- PROJECT LOGO -->
<br />
<p align="center">

<h3 align="center">Headstorm Engineering Back End Challenge</h3>

<p align="center">
I made a rest API using flask for the /data entry point.
</p>
</p>



<!-- TABLE OF CONTENTS -->
<details open="open">
<summary><h2 style="display: inline-block">Table of Contents</h2></summary>
<ol>
<li><a href="#built-with">Built With</a></li>
<li>
<a href="#run-it">Run the project</a>
</li>
<li><a href="#usage">Improvements</a></li>
<li><a href="#contact">Contact</a></li>
</ol>
</details>




### Built With

* []() Python
* []() HTML

### Using

* []() Flask, python microframework
* []() Flask's SQLAlchemy & Flask's Restful API


<!-- GETTING STARTED -->
## Getting Started

To get a local copy up and running follow these simple steps.

### Prerequisites

You will need to have python 3.8.5 & flask installed along with the flask dependencies that are listed at the top of the app.py file. Specifically install flask_sqlalchemy & flask_restful along with flask.

### Installation

1. Clone my repo :)
2. Install flask & flask requirements
3. I set up a virtual environment & installed flask & the dependencies that way
4. To run my virtual environment, type "source bin/activate" from the myproject directory

### Run The Project
4. Type "python app.py"

### Improvements
* I did not get a chance to add the requirements about the input being 500 numbers as json input. My current program takes in 5 numbers. It checks that there are exactly 5 integers, but does not check that there are 500 or the input. It only works if there are 5 numbers separated by commas. This addition to meet the 500 json requirements could be
* met with more time.

### Contact
Please contact me with any issues running the code:
* email: emm190@pitt.edu
* phone: 330-987-0225
* linkedIn: https://www.linkedin.com/in/emilymiller21/
95 changes: 95 additions & 0 deletions BackEndChallenge/myproject/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from flask import Flask
from flask_restful import Resource, Api
from flask import render_template
from flask import request
from flask import jsonify
from flask import redirect
from flask import url_for
from flask_sqlalchemy import SQLAlchemy
import re
from flask import flash


app = Flask(__name__)
api = Api(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = SQLAlchemy(app)


class Number(db.Model):
id = db.Column(db.Integer, primary_key=True)
numbers = db.Column(db.String(80), unique=False, nullable=False)

def __repr__(self):
return '%s' % (
self.numbers)

def __init__(self, numbers):
self.numbers = numbers

db.create_all()

@app.route('/')
def home_page():
example_embed='Hello! Welcome to my submission for the backend challenge.'
return render_template('index.html', embed=example_embed)

@app.route('/data',methods = ['POST', 'GET'])
def data():
if request.method == 'POST':
numbers = request.form['numbers']
stringList = numbers
number1 = Number(stringList)
db.session.add(number1)
db.session.commit()
idNumber = number1.id
listOfNumbers = str(stringList)
user = listOfNumbers.split(',')
for x in user:
try:
int(x)
except:
error_msg='There is something wrong with your formatting. Make sure you did not enter any letters. The only acceptable input is numbers separated by commas (with no space at the end)'
return render_template('index.html', embed=error_msg)
intList = [int(x) for x in user]
print(intList)
if (len(intList)!=5):
error_msg='You have to enter 5 numbers. You did not. Try again'
return render_template('index.html', embed=error_msg)
print(idNumber)
return redirect(url_for('success',listOfNumbers = Number.query.filter_by(id=idNumber).all()))
else:
user = request.args.get('numbers')
lastQuery = Number.query.count()
print(Number.query.all())
return redirect(url_for('success',listOfNumbers = Number.query.filter_by(id=lastQuery).all()))

@app.route('/getValue',methods = ['POST'])
def getValue():
numbers = request.form['numbersOfRequest']
return redirect(url_for('success',listOfNumbers = Number.query.filter_by(id=numbers).all()))

@app.route('/success/<listOfNumbers>')
def success(listOfNumbers):
listOfNumbers = str(listOfNumbers)
user = listOfNumbers.split(',')
print(user)
intList = [int(x) for x in user]
intList.sort()
print(intList)
return 'This is your sorted list of numbers:%s' % str(intList)

@app.route('/showAll', methods = ['POST', 'GET'])
def showAll():
print(Number.query.count())
list = []
for x in range(Number.query.count()):
print(Number.query.filter_by(id=x).all())
list.append("%d:" %x)
list.append(Number.query.filter_by(id=x).all())
listOfNumbers = Number.query.all()
print(listOfNumbers)
return 'This is all of the submissions:%s' % list

if __name__ == '__main__':
app.run(debug=True)
Loading