├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── css
├── inheritance.css
├── inheritance.css.map
├── inheritance.scss
├── nesting.css
├── nesting.css.map
├── nesting.scss
├── variable.css
├── variable.css.map
└── variable.scss
├── html
├── before.html
├── flexbox.html
├── grid.html
├── inheritance.html
├── nesting.html
├── print.html
├── responsive0.html
├── responsive1.html
├── selection.html
└── variable.html
└── python
├── classes.py
├── conditions.py
├── dictionaries.py
├── flaskapps
├── flights
│ ├── application.py
│ └── templates
│ │ ├── error.html
│ │ ├── flight.html
│ │ ├── flights.html
│ │ ├── index.html
│ │ ├── layout.html
│ │ └── success.html
├── forms
│ ├── application.py
│ └── templates
│ │ ├── hello.html
│ │ ├── index.html
│ │ ├── layout.html
│ │ └── more.html
├── notes
│ ├── application.py
│ ├── requirements.txt
│ └── templates
│ │ ├── index.html
│ │ └── layout.html
├── routes0
│ └── application.py
├── routes1
│ └── application.py
├── templates
│ ├── application.py
│ └── templates
│ │ └── index.html
└── variables
│ ├── .gitignore
│ ├── app.py
│ ├── requirements.txt
│ └── templates
│ └── index.html
├── flights
├── flights.csv
├── import.py
├── list.py
└── passengers.py
├── functions.py
├── hello.py
├── loops0.py
├── loops1.py
├── modules.py
├── name.py
├── oop
└── classes
│ ├── classes0.py
│ ├── classes1.py
│ ├── classes2.py
│ └── classes3.py
├── sequences.py
├── sets.py
└── variables.py
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.css linguist-detectable=false
2 | *.html linguist-detectable=false
3 | *.js linguist-detectable=true
4 | *.py linguist-detectable=true
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/flask
3 | # Edit at https://www.gitignore.io/?templates=flask
4 | .vscode/
5 | ### Flask ###
6 | instance/*
7 | !instance/.gitignore
8 | .webassets-cache
9 |
10 | ### Flask.Python Stack ###
11 | # Byte-compiled / optimized / DLL files
12 | __pycache__/
13 | *.py[cod]
14 | *$py.class
15 |
16 | # C extensions
17 | *.so
18 |
19 | # Distribution / packaging
20 | .Python
21 | build/
22 | develop-eggs/
23 | dist/
24 | downloads/
25 | eggs/
26 | .eggs/
27 | lib/
28 | lib64/
29 | parts/
30 | sdist/
31 | var/
32 | wheels/
33 | pip-wheel-metadata/
34 | share/python-wheels/
35 | *.egg-info/
36 | .installed.cfg
37 | *.egg
38 | MANIFEST
39 |
40 | # PyInstaller
41 | # Usually these files are written by a python script from a template
42 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
43 | *.manifest
44 | *.spec
45 |
46 | # Installer logs
47 | pip-log.txt
48 | pip-delete-this-directory.txt
49 |
50 | # Unit test / coverage reports
51 | htmlcov/
52 | .tox/
53 | .nox/
54 | .coverage
55 | .coverage.*
56 | .cache
57 | nosetests.xml
58 | coverage.xml
59 | *.cover
60 | .hypothesis/
61 | .pytest_cache/
62 |
63 | # Translations
64 | *.mo
65 | *.pot
66 |
67 | # Scrapy stuff:
68 | .scrapy
69 |
70 | # Sphinx documentation
71 | docs/_build/
72 |
73 | # PyBuilder
74 | target/
75 |
76 | # pyenv
77 | .python-version
78 |
79 | # pipenv
80 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
81 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
82 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
83 | # install all needed dependencies.
84 | #Pipfile.lock
85 |
86 | # celery beat schedule file
87 | celerybeat-schedule
88 |
89 | # SageMath parsed files
90 | *.sage.py
91 |
92 | # Spyder project settings
93 | .spyderproject
94 | .spyproject
95 |
96 | # Rope project settings
97 | .ropeproject
98 |
99 | # Mr Developer
100 | .mr.developer.cfg
101 | .project
102 | .pydevproject
103 |
104 | # mkdocs documentation
105 | /site
106 |
107 | # mypy
108 | .mypy_cache/
109 | .dmypy.json
110 | dmypy.json
111 |
112 | # Pyre type checker
113 | .pyre/
114 |
115 | # End of https://www.gitignore.io/api/flask
116 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Saed Yousef
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Python(Scratch)
2 |
--------------------------------------------------------------------------------
/css/inheritance.css:
--------------------------------------------------------------------------------
1 | .danger, .warning, .success {
2 | font-size: 18px;
3 | font-family: sans-serif;
4 | font-weight: bold;
5 | border: 1px solid black;
6 | padding: 20px;
7 | margin: 20px;
8 | color: white;
9 | }
10 |
11 | .success {
12 | background-color: cadetblue;
13 | }
14 |
15 | .warning {
16 | background-color: yellow;
17 | color: black;
18 | }
19 |
20 | .danger {
21 | background-color: firebrick;
22 | }
23 |
24 | /*# sourceMappingURL=inheritance.css.map */
25 |
--------------------------------------------------------------------------------
/css/inheritance.css.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sourceRoot":"","sources":["inheritance.scss"],"names":[],"mappings":"AAAA;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGJ;EAEI;;;AAGJ;EAEI;EACA;;;AAGJ;EAEI","file":"inheritance.css"}
--------------------------------------------------------------------------------
/css/inheritance.scss:
--------------------------------------------------------------------------------
1 | %message {
2 | font-size: 18px;
3 | font-family: sans-serif;
4 | font-weight: bold;
5 | border: 1px solid black;
6 | padding: 20px;
7 | margin: 20px;
8 | color: white;
9 | }
10 |
11 | .success {
12 | @extend %message;
13 | background-color: cadetblue;
14 | }
15 |
16 | .warning {
17 | @extend %message;
18 | background-color: yellow;
19 | color: black;
20 | }
21 |
22 | .danger {
23 | @extend %message;
24 | background-color: firebrick;
25 | }
--------------------------------------------------------------------------------
/css/nesting.css:
--------------------------------------------------------------------------------
1 | div {
2 | font-size: 28px;
3 | }
4 | div p {
5 | color: blue;
6 | }
7 | div ul {
8 | color: green;
9 | }
10 |
11 | /*# sourceMappingURL=nesting.css.map */
12 |
--------------------------------------------------------------------------------
/css/nesting.css.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sourceRoot":"","sources":["nesting.scss"],"names":[],"mappings":"AAAA;EACI;;AACA;EACI;;AAEJ;EACI","file":"nesting.css"}
--------------------------------------------------------------------------------
/css/nesting.scss:
--------------------------------------------------------------------------------
1 | div {
2 | font-size: 28px;
3 | p {
4 | color: blue;
5 | }
6 | ul {
7 | color: green;
8 | }
9 | }
--------------------------------------------------------------------------------
/css/variable.css:
--------------------------------------------------------------------------------
1 | ul {
2 | font-size: 14px;
3 | color: green;
4 | }
5 |
6 | ol {
7 | font-size: 18px;
8 | color: green;
9 | }
10 |
11 | /*# sourceMappingURL=variable.css.map */
12 |
--------------------------------------------------------------------------------
/css/variable.css.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sourceRoot":"","sources":["variable.scss"],"names":[],"mappings":"AAEA;EACI;EACA,OAJK;;;AAOT;EACI;EACA,OATK","file":"variable.css"}
--------------------------------------------------------------------------------
/css/variable.scss:
--------------------------------------------------------------------------------
1 | $color : green;
2 |
3 | ul{
4 | font-size: 14px;
5 | color: $color;
6 | }
7 |
8 | ol{
9 | font-size: 18px;
10 | color: $color;
11 | }
--------------------------------------------------------------------------------
/html/before.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | My web page Title
5 |
12 |
13 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/html/flexbox.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
19 |
20 |
21 |
A. Div contains text Div contains text
22 |
B. Div contains text Div contains text
23 |
C. Div contains text Div contains text
24 |
D. Div contains text Div contains text
25 |
E. Div contains text Div contains text
26 |
F. Div contains text Div contains text
27 |
G. Div contains text Div contains text
28 |
H. Div contains text Div contains text
29 |
L. Div contains text Div contains text
30 |
M. Div contains text Div contains text
31 |
N. Div contains text Div contains text
32 |
P. Div contains text Div contains text
33 |
Q. Div contains text Div contains text
34 |
R. Div contains text Div contains text
35 |
S. Div contains text Div contains text
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/html/grid.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
22 |
23 |
24 |
1
25 |
2
26 |
3
27 |
4
28 |
5
29 |
6
30 |
7
31 |
8
32 |
9
33 |
10
34 |
11
35 |
12
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/html/inheritance.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | This is a Success message
8 | This is a warning message
9 | This is a danger message
10 |
11 |
--------------------------------------------------------------------------------
/html/nesting.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
This is a P inside Div
9 |
10 | - Item one
11 | - Item two
12 | - Item three
13 |
14 |
15 |
16 | This is text
17 |
18 |
19 |
--------------------------------------------------------------------------------
/html/print.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | My web page Title
5 |
12 |
13 |
14 | This is a paragraph
15 | This is another paragraph
16 | This paragraph won't appear when you print this page
17 |
18 |
--------------------------------------------------------------------------------
/html/responsive0.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/html/responsive1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/html/selection.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | My web page Title
5 |
12 |
13 |
14 |
15 | When you select this text (Highlight) in the browser, the text color will be red and the background will be yellow
16 |
17 |
18 |
--------------------------------------------------------------------------------
/html/variable.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Unordered list
8 |
9 | - Item one
10 | - Item two
11 | - Item three
12 |
13 | Ordered list
14 |
15 | - Item one
16 | - Item two
17 | - Item three
18 |
19 |
20 |
--------------------------------------------------------------------------------
/python/classes.py:
--------------------------------------------------------------------------------
1 | class Point:
2 | def __init__(self, x, y):
3 | self.x = x
4 | self.y = y
5 |
6 | p = Point(3, 5)
7 | print(p.x)
8 | print(p.y)
9 |
--------------------------------------------------------------------------------
/python/conditions.py:
--------------------------------------------------------------------------------
1 | x = 28
2 |
3 | if x > 0:
4 | print("x is positive")
5 | elif x < 0:
6 | print("x is negative")
7 | else:
8 | print("x is Zero")
--------------------------------------------------------------------------------
/python/dictionaries.py:
--------------------------------------------------------------------------------
1 | ages = {"Alice": 22, "Bob": 27}
2 | ages["Charlie"] = 30
3 | ages["Alice"] += 1 #same as ages["Alice"] = ages["Alice"] + 1
4 | print(ages)
--------------------------------------------------------------------------------
/python/flaskapps/flights/application.py:
--------------------------------------------------------------------------------
1 | import os
2 | from flask import Flask, render_template, request , session
3 | from flask_session import Session
4 | from sqlalchemy import create_engine
5 | from sqlalchemy.orm import scoped_session, sessionmaker
6 |
7 | app = Flask(__name__)
8 |
9 | # app.config["SESSION_PERMANENT"] = False
10 | # app.config["SESSION_TYPE"] = "filesystem"
11 | Session(app)
12 |
13 | engine = create_engine(os.getenv("DATABASE_URL"))
14 | db = scoped_session(sessionmaker(bind = engine))
15 |
16 | @app.route("/")
17 | def index():
18 | flights = db.execute("SELECT * FROM flights").fetchall()
19 | return render_template("index.html", flights=flights)
20 |
21 | @app.route("/book", methods=['POST'])
22 | def book():
23 | """Book a flight. """
24 | name = request.form.get("name")
25 | try:
26 | flight_id = int(request.form.get("flight_id"))
27 | except ValueError:
28 | return render_template("error.html", message="Invalid flight number.")
29 |
30 | if db.execute("SELECT * FROM flights where id = :id", {"id": flight_id}).rowcount == 0:
31 | return render_template("error.html", message="No such flight.")
32 | db.execute("INSERT INTO passengers (name, flight_id) VALUES (:name, :flight_id)", {"name":name, "flight_id": flight_id})
33 | db.commit()
34 | return render_template("success.html", message="Passenger added successfully!")
35 |
36 | @app.route("/flights")
37 | def flights():
38 | """Get all flights. """
39 |
40 | flights = db.execute("SELECT * FROM flights").fetchall()
41 | if len(flights) == 0:
42 | return render_template("error.html", message="No flights found.")
43 | return render_template("flights.html", flights=flights)
44 |
45 | @app.route("/flights/")
46 | def flight(flight_id):
47 | """List Details for a flight"""
48 | flight = db.execute("SELECT * FROM flights WHERE id = :id", {"id": flight_id}).fetchone()
49 | if flight is None:
50 | return render_template("error.html", message="No such a flight.")
51 | passengers = db.execute("SELECT name FROM passengers where flight_id = :fid", {"fid" : flight_id})
52 | return render_template("flight.html", flight=flight, passengers=passengers)
53 |
--------------------------------------------------------------------------------
/python/flaskapps/flights/templates/error.html:
--------------------------------------------------------------------------------
1 | {% extends "layout.html" %}
2 |
3 | {% block title%}
4 | Error
5 | {% endblock %}
6 |
7 | {% block body %}
8 | Error!
9 | {{message}}
10 | {% endblock %}
--------------------------------------------------------------------------------
/python/flaskapps/flights/templates/flight.html:
--------------------------------------------------------------------------------
1 | {% extends "layout.html" %}
2 |
3 | {% block title%}
4 | Flight Details
5 | {% endblock %}
6 |
7 | {% block body %}
8 | Flights Details
9 |
10 | - Origin : {{flight.origin}}
11 | - Destination : {{flight.destination}}
12 |
13 | Passengers List
14 |
15 | {% for passenger in passengers %}
16 | - {{ passenger.name}}
17 | {% endfor %}
18 |
19 |
20 |
21 | {% endblock %}
--------------------------------------------------------------------------------
/python/flaskapps/flights/templates/flights.html:
--------------------------------------------------------------------------------
1 | {% extends "layout.html" %}
2 |
3 | {% block title%}
4 | Flights List
5 | {% endblock %}
6 |
7 | {% block body %}
8 | Flights List
9 |
18 |
19 | {% endblock %}
--------------------------------------------------------------------------------
/python/flaskapps/flights/templates/index.html:
--------------------------------------------------------------------------------
1 | {% extends "layout.html" %}
2 |
3 | {% block title%}
4 | Flights
5 | {% endblock %}
6 |
7 | {% block body %}
8 | Book flight
9 |
25 | {% endblock %}
--------------------------------------------------------------------------------
/python/flaskapps/flights/templates/layout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | {% block title%} {% endblock %}
4 |
5 |
6 |
7 |
8 | {% block body %}
9 | {% endblock %}
10 |
11 |
--------------------------------------------------------------------------------
/python/flaskapps/flights/templates/success.html:
--------------------------------------------------------------------------------
1 | {% extends "layout.html" %}
2 |
3 | {% block title %}
4 | Success
5 | {% endblock %}
6 |
7 | {% block body %}
8 | Success!
9 | {{ message }}
10 | {% endblock %}
--------------------------------------------------------------------------------
/python/flaskapps/forms/application.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, render_template, request
2 |
3 | app = Flask(__name__)
4 |
5 | @app.route("/")
6 | def index():
7 | return render_template("index.html")
8 |
9 | @app.route("/hello", methods=["GET", "POST"])
10 | def hello():
11 | if request.method == "GET":
12 | return "Submit your name instead."
13 | else:
14 | name = request.form.get("name")
15 | return render_template("hello.html", name=name)
--------------------------------------------------------------------------------
/python/flaskapps/forms/templates/hello.html:
--------------------------------------------------------------------------------
1 | {% extends "layout.html" %}
2 |
3 | {% block heading%}
4 | Index Page
5 | {% endblock %}
6 |
7 | {% block body%}
8 | {{ name }}
9 | {% endblock %}
--------------------------------------------------------------------------------
/python/flaskapps/forms/templates/index.html:
--------------------------------------------------------------------------------
1 | {% extends "layout.html" %}
2 |
3 | {% block heading%}
4 | Index Page
5 | {% endblock %}
6 |
7 | {% block body%}
8 |
12 | {% endblock %}
--------------------------------------------------------------------------------
/python/flaskapps/forms/templates/layout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Forms
4 |
5 |
6 | {% block heading %} {% endblock %}
7 | {% block body %}
8 | {% endblock %}
9 |
--------------------------------------------------------------------------------
/python/flaskapps/forms/templates/more.html:
--------------------------------------------------------------------------------
1 | {% extends "layout.html" %}
2 |
3 | {% block heading%}
4 | More Page
5 | {% endblock %}
6 |
7 | {% block body%}
8 | A text A text A text A text A text A text A text A text
9 | Go back
10 | {% endblock %}
--------------------------------------------------------------------------------
/python/flaskapps/notes/application.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, render_template, request, session
2 | from flask_session import Session
3 |
4 | app = Flask(__name__)
5 |
6 | app.config["SESSION_PERMANENT"] = False
7 | app.config["SESSION_TYPE"] = "filesystem"
8 | Session(app)
9 |
10 | @app.route("/", methods=["GET", "POST"])
11 | def index():
12 | if session.get("notes") is None:
13 | session["notes"] = []
14 | if request.method == "POST":
15 | note = request.form.get("note")
16 | session["notes"].append(note)
17 |
18 | return render_template("index.html", notes=session["notes"])
19 |
--------------------------------------------------------------------------------
/python/flaskapps/notes/requirements.txt:
--------------------------------------------------------------------------------
1 | appdirs==1.4.3
2 | astroid==2.3.3
3 | certifi==2020.4.5.1
4 | click==7.1.1
5 | distlib==0.3.0
6 | filelock==3.0.12
7 | Flask==1.1.2
8 | Flask-Session==0.3.1
9 | importlib-metadata==1.6.0
10 | isort==4.3.21
11 | itsdangerous==1.1.0
12 | Jinja2==2.11.2
13 | lazy-object-proxy==1.4.3
14 | MarkupSafe==1.1.1
15 | mccabe==0.6.1
16 | pipenv==2018.11.26
17 | pylint==2.4.4
18 | six==1.14.0
19 | typed-ast==1.4.1
20 | virtualenv==20.0.18
21 | virtualenv-clone==0.5.4
22 | Werkzeug==0.15.3
23 | wrapt==1.11.2
24 | zipp==3.1.0
25 |
--------------------------------------------------------------------------------
/python/flaskapps/notes/templates/index.html:
--------------------------------------------------------------------------------
1 | {% extends "layout.html" %}
2 |
3 | {% block heading%}
4 | Notes ..
5 | {% endblock %}
6 |
7 | {% block body %}
8 |
9 | {% for note in notes %}
10 | - {{ note }}
11 | {% endfor %}
12 |
13 |
17 | {% endblock %}
--------------------------------------------------------------------------------
/python/flaskapps/notes/templates/layout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Notes
4 |
5 |
6 | {% block heading %} {% endblock %}
7 | {% block body %}
8 | {% endblock %}
9 |
--------------------------------------------------------------------------------
/python/flaskapps/routes0/application.py:
--------------------------------------------------------------------------------
1 | from flask import Flask
2 |
3 | app = Flask(__name__)
4 |
5 | @app.route("/")
6 | def index():
7 | return "App Route 1"
--------------------------------------------------------------------------------
/python/flaskapps/routes1/application.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, render_template
2 |
3 | app = Flask(__name__)
4 |
5 | @app.route("/")
6 | def index():
7 | return "Hello, World!"
8 |
9 | @app.route("/")
10 | def hello(name):
11 | name = name.capitalize()
12 | return f"Hello, {name}"
--------------------------------------------------------------------------------
/python/flaskapps/templates/application.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, render_template
2 |
3 | app = Flask(__name__)
4 |
5 | @app.route("/")
6 | def index():
7 | return render_template("index.html")
--------------------------------------------------------------------------------
/python/flaskapps/templates/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | My web page Title
5 |
6 |
7 |
8 | Hello, World!
9 |
10 |
--------------------------------------------------------------------------------
/python/flaskapps/variables/.gitignore:
--------------------------------------------------------------------------------
1 | pyvenv.cfg
2 | .venv
3 | bin/
4 | # Byte-compiled / optimized / DLL files
5 | __pycache__/
6 | *.py[cod]
7 | *$py.class
8 |
9 | # C extensions
10 | *.so
11 |
12 | # Distribution / packaging
13 | .Python
14 | build/
15 | develop-eggs/
16 | dist/
17 | downloads/
18 | eggs/
19 | .eggs/
20 | lib/
21 | lib64/
22 | parts/
23 | sdist/
24 | var/
25 | wheels/
26 | share/python-wheels/
27 | *.egg-info/
28 | .installed.cfg
29 | *.egg
30 | MANIFEST
31 |
32 | # PyInstaller
33 | # Usually these files are written by a python script from a template
34 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
35 | *.manifest
36 | *.spec
37 |
38 | # Installer logs
39 | pip-log.txt
40 | pip-delete-this-directory.txt
41 |
42 | # Unit test / coverage reports
43 | htmlcov/
44 | .tox/
45 | .nox/
46 | .coverage
47 | .coverage.*
48 | .cache
49 | nosetests.xml
50 | coverage.xml
51 | *.cover
52 | *.py,cover
53 | .hypothesis/
54 | .pytest_cache/
55 | cover/
56 |
57 | # Translations
58 | *.mo
59 | *.pot
60 |
61 | # Django stuff:
62 | *.log
63 | local_settings.py
64 | db.sqlite3
65 | db.sqlite3-journal
66 |
67 | # Flask stuff:
68 | instance/
69 | .webassets-cache
70 |
71 | # Scrapy stuff:
72 | .scrapy
73 |
74 | # Sphinx documentation
75 | docs/_build/
76 |
77 | # PyBuilder
78 | .pybuilder/
79 | target/
80 |
81 | # Jupyter Notebook
82 | .ipynb_checkpoints
83 |
84 | # IPython
85 | profile_default/
86 | ipython_config.py
87 |
88 | # pyenv
89 | # For a library or package, you might want to ignore these files since the code is
90 | # intended to run in multiple environments; otherwise, check them in:
91 | # .python-version
92 |
93 | # pipenv
94 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
96 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
97 | # install all needed dependencies.
98 | #Pipfile.lock
99 |
100 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
101 | __pypackages__/
102 |
103 | # Celery stuff
104 | celerybeat-schedule
105 | celerybeat.pid
106 |
107 | # SageMath parsed files
108 | *.sage.py
109 |
110 | # Environments
111 | .env
112 | .venv
113 | env/
114 | venv/
115 | ENV/
116 | env.bak/
117 | venv.bak/
118 |
119 | # Spyder project settings
120 | .spyderproject
121 | .spyproject
122 |
123 | # Rope project settings
124 | .ropeproject
125 |
126 | # mkdocs documentation
127 | /site
128 |
129 | # mypy
130 | .mypy_cache/
131 | .dmypy.json
132 | dmypy.json
133 |
134 | # Pyre type checker
135 | .pyre/
136 |
137 | # pytype static type analyzer
138 | .pytype/
139 |
140 | # Cython debug symbols
141 | cython_debug/
142 | /*_session/
143 |
--------------------------------------------------------------------------------
/python/flaskapps/variables/app.py:
--------------------------------------------------------------------------------
1 | import datetime
2 | from flask import Flask, render_template
3 |
4 | app = Flask(__name__)
5 |
6 | @app.route("/")
7 | def index():
8 | now = datetime.datetime.now()
9 | new_year = now.month == 1 and now.day == 1
10 | return render_template("index.html", new_year=new_year)
11 |
--------------------------------------------------------------------------------
/python/flaskapps/variables/requirements.txt:
--------------------------------------------------------------------------------
1 | click==7.1.1
2 | Flask==1.1.2
3 | itsdangerous==1.1.0
4 | Jinja2==2.11.2
5 | MarkupSafe==1.1.1
6 | Werkzeug==1.0.1
7 |
--------------------------------------------------------------------------------
/python/flaskapps/variables/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | My web page Title
5 |
6 |
7 |
8 | {% if new_year %}
9 | Yes, Happy New Year
10 | {% else %}
11 | No
12 | {% endif %}
13 |
14 |
--------------------------------------------------------------------------------
/python/flights/flights.csv:
--------------------------------------------------------------------------------
1 | Irbid, Moscow, 800
2 | Riyad, Amman, 200
3 | Berlin, Koeln, 60
--------------------------------------------------------------------------------
/python/flights/import.py:
--------------------------------------------------------------------------------
1 | import os
2 | import csv
3 | from sqlalchemy import create_engine
4 | from sqlalchemy.orm import scoped_session, sessionmaker
5 |
6 | engine = create_engine(os.getenv("DATABASE_URL"))
7 | db = scoped_session(sessionmaker(bind = engine))
8 |
9 | def main():
10 | f = open("flights.csv")
11 | reader = csv.reader(f)
12 | for origin, destination, duration in reader:
13 | db.execute("INSERT INTO flights (origin, destination, duration) VALUES (:origin, :destination, :duration)", {"origin" : origin, "destination": destination, "duration" : duration})
14 | print(f"Added flight from {origin} to {destination} lasting {duration} minutes")
15 | db.commit()
16 |
17 |
18 | if __name__ == "__main__":
19 | main()
20 |
--------------------------------------------------------------------------------
/python/flights/list.py:
--------------------------------------------------------------------------------
1 | import os
2 | from sqlalchemy import create_engine
3 | from sqlalchemy.orm import scoped_session, sessionmaker
4 |
5 | engine = create_engine(os.getenv("DATABASE_URL"))
6 | db = scoped_session(sessionmaker(bind = engine))
7 |
8 | def main():
9 | flights = db.execute("SELECT origin, destination, duration FROM flights")
10 | for flight in flights:
11 | print(f"{flight.origin} to {flight.destination} lasting {flight.duration} mintues")
12 |
13 | if __name__ == "__main__":
14 | main()
15 |
--------------------------------------------------------------------------------
/python/flights/passengers.py:
--------------------------------------------------------------------------------
1 | import os
2 | from sqlalchemy import create_engine
3 | from sqlalchemy.orm import scoped_session, sessionmaker
4 |
5 | engine = create_engine(os.getenv("DATABASE_URL"))
6 | db = scoped_session(sessionmaker(bind = engine))
7 |
8 | def main():
9 | # List all flights
10 | flights = db.execute("SELECT origin, destination, duration FROM flights")
11 | for flight in flights:
12 | print(f"{flight.origin} to {flight.destination} lasting {flight.duration} mintues")
13 | # Prompt user to choose a flight.
14 | flight_id = int(input("\nFlight ID: "))
15 | flight = db.execute("SELECT origin, destination, duration from flights WHERE id = :id", {"id": flight_id}).fetchone()
16 |
17 | if flight is None:
18 | print("Error: No such flight.")
19 | return
20 | passengers = db.execute("SELECT name FROM passengers where flight_id = :fid", {"fid" : flight_id}).fetchall()
21 | print("\nPassengers")
22 | for passneger in passengers:
23 | print(passneger.name)
24 | if len(passengers) == 0:
25 | print("No passengers.")
26 |
27 |
28 |
29 | if __name__ == "__main__":
30 | main()
31 |
--------------------------------------------------------------------------------
/python/functions.py:
--------------------------------------------------------------------------------
1 | def square(x):
2 | return x * x
3 |
4 | def main():
5 | for i in range(10):
6 | print("{} square is {}".format(i, square(i)))
7 |
8 | if __name__ == "__main__":
9 | main()
--------------------------------------------------------------------------------
/python/hello.py:
--------------------------------------------------------------------------------
1 | print("Hello World")
--------------------------------------------------------------------------------
/python/loops0.py:
--------------------------------------------------------------------------------
1 | for i in range(5):
2 | print(i)
--------------------------------------------------------------------------------
/python/loops1.py:
--------------------------------------------------------------------------------
1 | names = ["Saeed", "Bob", "Mousa"]
2 | for name in names:
3 | print(name)
--------------------------------------------------------------------------------
/python/modules.py:
--------------------------------------------------------------------------------
1 | from functions import square
2 |
3 | print(square(5))
--------------------------------------------------------------------------------
/python/name.py:
--------------------------------------------------------------------------------
1 | name = input()
2 | print(f"Hello, {name}!")
--------------------------------------------------------------------------------
/python/oop/classes/classes0.py:
--------------------------------------------------------------------------------
1 | class Flight:
2 |
3 | def __init__(self, origin, destination, duration):
4 | self.origin = origin
5 | self.destination = destination
6 | self.duration = duration
7 |
8 | def main():
9 | f = Flight(origin = "New York", destination = "Paris", duration = 540)
10 |
11 | f.duration += 10
12 | print(f.origin)
13 | print(f.destination)
14 | print(f.duration)
15 |
16 | if __name__ == "__main__":
17 | main()
--------------------------------------------------------------------------------
/python/oop/classes/classes1.py:
--------------------------------------------------------------------------------
1 | class Flight:
2 |
3 | def __init__(self, origin, destination, duration):
4 | self.origin = origin
5 | self.destination = destination
6 | self.duration = duration
7 |
8 | def print_info(self):
9 | print(f"Flight Origin: {self.origin}")
10 | print(f"Flight Destination: {self.destination}")
11 | print(f"Flight Duration: {self.duration}")
12 |
13 | def main():
14 | f = Flight(origin = "New York", destination = "Paris", duration = 540)
15 | f.duration += 10
16 | f.print_info()
17 |
18 | if __name__ == "__main__":
19 | main()
--------------------------------------------------------------------------------
/python/oop/classes/classes2.py:
--------------------------------------------------------------------------------
1 | class Flight:
2 |
3 | def __init__(self, origin, destination, duration):
4 | self.origin = origin
5 | self.destination = destination
6 | self.duration = duration
7 |
8 | def print_info(self):
9 | print(f"Flight Origin: {self.origin}")
10 | print(f"Flight Destination: {self.destination}")
11 | print(f"Flight Duration: {self.duration}")
12 |
13 | def delay(self, amount):
14 | self.duration += amount
15 |
16 | def main():
17 | f = Flight(origin = "New York", destination = "Paris", duration = 540)
18 | f.delay(20)
19 | f.print_info()
20 |
21 | if __name__ == "__main__":
22 | main()
--------------------------------------------------------------------------------
/python/oop/classes/classes3.py:
--------------------------------------------------------------------------------
1 | class Flight:
2 |
3 | counter = 1
4 |
5 | def __init__(self, origin, destination, duration):
6 |
7 | # Keep track of id number.
8 | self.id = Flight.counter
9 | Flight.counter += 1
10 |
11 | # Keep track of Passengers.
12 | self.passengers = []
13 |
14 | # Details about flight.
15 | self.origin = origin
16 | self.destination = destination
17 | self.duration = duration
18 |
19 | def print_info(self):
20 | print(f"Flight Origin: {self.origin}")
21 | print(f"Flight Destination: {self.destination}")
22 | print(f"Flight Duration: {self.duration}")
23 |
24 | print()
25 | print("Passengers:")
26 | for passenger in self.passengers:
27 | print(f"{passenger.name}")
28 |
29 | def delay(self, amount):
30 | self.duration += amount
31 |
32 | def add_passenger(self, p):
33 | self.passengers.append(p)
34 | p.flight_id = self.id
35 |
36 |
37 | class Passenger:
38 |
39 | def __init__(self, name):
40 | self.name = name
41 |
42 | def main():
43 | # Create flight.
44 | f = Flight(origin = "New York", destination = "Paris", duration = 540)
45 |
46 | # Create Passengers.
47 | alice = Passenger(name="Alice")
48 | bob = Passenger(name="Bob")
49 |
50 | # Add passengers.
51 | f.add_passenger(alice)
52 | f.add_passenger(bob)
53 | f.print_info()
54 |
55 | if __name__ == "__main__":
56 | main()
--------------------------------------------------------------------------------
/python/sequences.py:
--------------------------------------------------------------------------------
1 | name = "Saeed"
2 | cordinates = (10.0, 20.0)
3 | names = ["Saeed", "Bob", "Mousa"]
--------------------------------------------------------------------------------
/python/sets.py:
--------------------------------------------------------------------------------
1 | s = set()
2 | s.add(1)
3 | s.add(3)
4 | s.add(5)
5 | s.add(3)
6 | print(s)
--------------------------------------------------------------------------------
/python/variables.py:
--------------------------------------------------------------------------------
1 | i = 28
2 | print(f"i is {i}")
3 |
4 | f = 2.8
5 | print(f"f is {f}")
6 |
7 | b = True
8 | print(f"b is {b}")
9 |
10 | n = None
11 | print(f"n is {n}")
--------------------------------------------------------------------------------