Commit 52a01975 authored by Raquel's avatar Raquel 💬

final push

parent a4941a38
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/WEEK4/week4day1/venv/lib/python3.7/site-packages/django/forms/templates" />
</list>
</option>
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (venv)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/COURSE.iml" filepath="$PROJECT_DIR$/.idea/COURSE.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
#anaconda - packages of python the user can use
#bash and zsh% are comand line langages (similar to eah other)
#python package: has modules (ie files), and init file --> package allows to import all the files in it at the same time
#put all the importa paths of the files in the packege in the init file, and then in the file we are working in, just import the package and call any function in the init fikle we want
#when the interpreter goes inside the package it reads the init file and gives the baility to reference all the files to the environemtn where the pacage is imported to and installed
#pip is a package installer
\ No newline at end of file
Metadata-Version: 1.0
Name: sorting-algorithms-v3
Version: 0.1
Summary: sorting algorithms in python3
Home-page: https://gitlab.propulsion-home.ch/
Author: Raquelcodes
Author-email: Raquelcodes@example.com
License: MIT
Description: UNKNOWN
Platform: UNKNOWN
setup.py
sorting_algorithms_v3/Bubble_Sort.py
sorting_algorithms_v3/Insertion_Sort.py
sorting_algorithms_v3/Quick_Sort.py
sorting_algorithms_v3/Selection_Sort.py
sorting_algorithms_v3/__init__.py
sorting_algorithms_v3.egg-info/PKG-INFO
sorting_algorithms_v3.egg-info/SOURCES.txt
sorting_algorithms_v3.egg-info/dependency_links.txt
sorting_algorithms_v3.egg-info/not-zip-safe
sorting_algorithms_v3.egg-info/top_level.txt
\ No newline at end of file
"""
class Animal:
legs = 4
def __init__(self, type):
self.type = type
def __str__(self):
return f"I am a {self.type} with {Animal.legs} legs"
mammal = Animal("Mammal")
print(mammal)
"""
array=[1,2,3,4]
print(array[3])
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="a3286fd0-cb20-4f28-bfba-dcfb8806afb4" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/../DAY 4/sorting_algorithms_v3/MANIFEST.in" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../DAY 4/sorting_algorithms_v3/README.rst" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/DAy5.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/mywebsite/mywebsite.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/notes.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/requirements.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../DAY 4/setup.py" beforeDir="false" afterPath="$PROJECT_DIR$/../DAY 4/setup.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../DAY 4/sorting_algorithms_v3/Bubble_Sort.py" beforeDir="false" afterPath="$PROJECT_DIR$/../DAY 4/sorting_algorithms_v3/Bubble_Sort.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../DAY 4/sorting_algorithms_v3/Insertion_Sort.py" beforeDir="false" afterPath="$PROJECT_DIR$/../DAY 4/sorting_algorithms_v3/Insertion_Sort.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../DAY 4/sorting_algorithms_v3/README.md" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../DAY 4/sorting_algorithms_v3/Selection_Sort.py" beforeDir="false" afterPath="$PROJECT_DIR$/../DAY 4/sorting_algorithms_v3/Selection_Sort.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../DAY3/Books.py" beforeDir="false" afterPath="$PROJECT_DIR$/../DAY3/Books.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../DAY3/restaurant_costumers.py" beforeDir="false" afterPath="$PROJECT_DIR$/../DAY3/restaurant_costumers.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../DAY3/restaurant_vF/.gitignore" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../DAY3/restaurant_vF/restaurant.py" beforeDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/notes.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="296">
<caret line="46" column="59" selection-start-line="46" selection-start-column="59" selection-end-line="46" selection-end-column="59" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/mywebsite/mywebsite.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="210">
<caret line="14" column="7" lean-forward="true" selection-start-line="14" selection-start-column="7" selection-end-line="14" selection-end-column="7" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/requirements.yml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="90">
<caret line="6" selection-start-line="6" selection-end-line="6" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/requirements.yml" />
<option value="$PROJECT_DIR$/notes.py" />
<option value="$PROJECT_DIR$/mywebsite/mywebsite.html" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="y" value="23" />
<option name="width" value="1440" />
<option name="height" value="873" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="DAy5" type="b2602c69:ProjectViewProjectNode" />
<item name="DAy5" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="DAy5" type="b2602c69:ProjectViewProjectNode" />
<item name="DAy5" type="462c0819:PsiDirectoryNode" />
<item name="mywebsite" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="a3286fd0-cb20-4f28-bfba-dcfb8806afb4" name="Default Changelist" comment="" />
<created>1559286344947</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1559286344947</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="0" y="23" width="1440" height="873" extended-state="6" />
<layout>
<window_info id="Favorites" side_tool="true" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.24947146" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Python Console" />
<window_info active="true" anchor="bottom" id="Terminal" visible="true" weight="0.3298153" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/requirements.yml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="90">
<caret line="6" selection-start-line="6" selection-end-line="6" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/notes.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="296">
<caret line="46" column="59" selection-start-line="46" selection-start-column="59" selection-end-line="46" selection-end-column="59" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/mywebsite/mywebsite.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="210">
<caret line="14" column="7" lean-forward="true" selection-start-line="14" selection-start-column="7" selection-end-line="14" selection-end-column="7" />
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
*.sqlite
.DS_Store
.idea
# Flask Live coding
## Flask migrate
Install:
```bash
pip install Flask-Migrate
```
**Note**: Make sure you have the FLASK_APP env variable exported before you run these commands!
Generate migration folder structure:
```bash
flask db init
```
Create first migration file:
```bash
flask db migrate
```
Apply schema changes to database:
```bash
flask db upgrade
```
import click
from flask import Flask
from flask_migrate import Migrate
from models import db, User, Post
import views
from urls import posts_urls
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app_db.sqlite'
migrate = Migrate(app, db)
db.init_app(app)
db.create_all(app=app)
@app.cli.command()
def generatedata():
db.create_all(app=app)
for i in range(10):
user = User(username=f'test_user{i}', email=f'test_user{i}@email.com')
for j in range(10):
post = Post(user=user, body=f'Post {j} by user {user.username}')
user.posts.append(post)
db.session.add(user)
db.session.commit()
click.echo('Init db done!')
app.add_url_rule('/users/', view_func=views.users, methods=['GET', 'POST'])
app.register_blueprint(posts_urls, url_prefix='/posts' )
if __name__ == '__main__':
app.run(host='localhost', port=5000, debug=True)
import json
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import relationship
db = SQLAlchemy()
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=True)
posts = relationship("Post")
def __str__(self):
return self.username
class UserSerializer:
@staticmethod
def serialize(user, many=False):
if many:
res = []
for user in user:
user_dict = {
'username': user.username,
'email': user.email
}
res += [user_dict]
return json.dumps(res)
user_dict = {
'username': user.username,
'email': user.email
}
return json.dumps(user_dict)
@staticmethod
def desirialize(data):
user_dict = json.loads(data)
new_user = User(**user_dict)
return new_user
@staticmethod
def save(user):
db.session.add(user)
db.session.commit()
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
user = db.Column(
db.Integer,
db.ForeignKey('user.id'),
nullable=False,
)
body = db.Column(db.Text, nullable=False)
def __repr__(self):
return f'<Post {self.title}>'
class PostSerializer:
@staticmethod
def serialize(post, many=False):
if many:
res = []
for post in post:
user_dict = {
'user': post.user,
'body': post.body
}
res += [user_dict]
return json.dumps(res)
user_dict = {
'user': post.user,
'body': post.body
}
return json.dumps(user_dict)
name: flask_livecoding
dependencies:
- python=3.6
- pip:
- Flask==1.0.3
- flask-sqlalchemy==2.4.0
- flask-migrate==2.5.2
\ No newline at end of file
from flask import Blueprint
import views
posts_urls = Blueprint('posts', 'posts')
posts_urls.add_url_rule('/<int:user_id>/posts/', view_func=views.get_posts_user, methods=['GET'])
import json
from flask import request
from flask.views import MethodView
from models import User, UserSerializer, Post, PostSerializer
def users():
if request.method == 'GET':
users = User.query.all()
return UserSerializer.serialize(users, many=True)
if request.method == 'POST':
new_user = UserSerializer.desirialize(request.data)
UserSerializer.save(new_user)
return '', 201
def get_posts_user(user_id):
if request.method == 'GET':
posts = Post.query.filter_by(user=user_id)
return PostSerializer.serialize(posts, many=True)
# class Users(MethodView):
# def get(self):
# users = User.query.all()
# return UserSerializer.serialize(users, many=True)
#
# def post(self):
# pass
import click
from flask import Flask
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
from models import *
import views
from urls import posts_urls
import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app_db.sqlite'
migrate = Migrate(app, db)
db.init_app(app)
db.create_all(app=app)
#click command to initialize the database
@app.cli.command()
def generatedata():
db.create_all(app=app)
for i in range(10):
user = User(id=f'id{i}', username=f'test_user{i}')
#for z in range(10):
# user= User(created=f'test{z}', due_date=f'duedate{z}', done_flag=f'doneflag{z}', posts=f'Post {z}')
# for j in range(10):
# post = Post(user=user, body=f'Post {j}')
# user.posts.append(post)
db.session.add(user)
db.session.commit()
click.echo('Init db done!')
app.add_url_rule('/users/', view_func=views.users, methods=['GET', 'POST'])
app.register_blueprint(posts_urls, url_prefix='/posts' )
if __name__ == '__main__':
app.run(host='localhost', port=6000, debug=True)
import json
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import relationship
db = SQLAlchemy()
import datetime
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
#email = db.Column(db.String(120), unique=True, nullable=True)
def __str__(self):
return self.username
"""
#class lists
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
#user_lists=relationship("User")
#each user list
class User_lists(db.Model):
created = db.Column(db.String(80), unique=True, nullable=False)
due_date = db.Column(db.String(80), unique=False, nullable=True)
done_flag = db.Column(db.String(80), unique=False, nullable=False)
posts = db.Column(db.String(80), unique=False, nullable=False)
#posts=TODOs
"""
#serialize for GET method
class UserSerializer:
@staticmethod
def serialize(user, many=False):
if many:
res = []
for user in user:
user_dict = {
'id': user.id,
'username': user.username
}
res += [user_dict]
return json.dumps(res)
user_dict = {
'id': user.id,
'username': user.username
}
return json.dumps(user_dict)
#deserialize for POST method
@staticmethod
def desirialize(data):
user_dict = json.loads(data)
new_user = User(**user_dict)
return new_user
#to commit each row to the table
@staticmethod
def save(user):
db.session.add(user)
db.session.commit()
#to allocate each post of a user to that user id
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
user = db.Column(
db.Integer,
db.ForeignKey('user.id'),
nullable=False,
)
body = db.Column(db.Text, nullable=False)
def __repr__(self):
return f'<Post {self.title}>'
"""
#to GET the posts, ie the TODOs for each user
class PostSerializer:
@staticmethod
def serialize(post, many=False):
if many:
res = []
for post in post:
user_dict = {
'user': post.user,
'body': post.body
}
res += [user_dict]
return json.dumps(res)
user_dict = {
'user': post.user,
'body': post.body
}
return json.dumps(user_dict)
"""
\ No newline at end of file
......@@ -5,11 +5,15 @@ app = Flask(__name__)
def hello_world():
return 'Hello, World!'
"""
def greet(name):
return f'Hello' (name)
app.add.url etc
"""
\ No newline at end of file
import click
# ...
@app.cli.command()
def initdb():
"""Initialize the database."""
db.create_all()
click.echo('Init db done!')
from flask import Blueprint
import views
posts_urls = Blueprint('posts', 'posts')
posts_urls.add_url_rule('/<int:user_id>/posts/', view_func=views.get_posts_user, methods=['GET'])
from flask import request
from models import *
#get all lists
def users():
if request.method == 'GET':
users = User.query.all()
return UserSerializer.serialize(users, many=True)
if request.method == 'POST':
new_user = UserSerializer.desirialize(request.data)
UserSerializer.save(new_user)
return '', 201
#get a user list
def get_posts_user(user_id):
if request.method == 'GET':
posts = Post.query.filter_by(user=user_id)
return PostSerializer.serialize(posts, many=True)
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6pilKxBM9zm4aJbUqA0qFZkaPOZINcmLGlWix03ucFyMqj/+E/z0v9d+pVy6UJ5AClKGjZRJhL+5S7zyZcCCPWnVlXb4Ed5KZbbsrroIWl7h/XqycWpDLpuEbTZnLFvwUfee69srMx/j6Tfe+yjlei6Zbu/9ZlAXDoKqPvZSmyNAucCs4+QzffvqKuluKbJK3slWapTiOfoqyh0AmjqkrRsDkPFyWAkrjR2ZA8VPP79QbdamCOxYGTyME6HZaZbWiYQvpxkRl9HG85BljVXXl3DYFYipHlXQDOk55DzUs+/N677SKnlLLNzDrvx+3sJV+Ha/la3vVO8P39HOH6EBd raquel@raquels-Air
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment