Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (86)
Showing
with 89 additions and 127 deletions
......@@ -2,51 +2,11 @@
Welcome to the lab exercises repo!
Here you'll find all the example code which accompanies weeks 1-10 of **Data, Networks & the Web**. The example code is for a music store app, so you will need to adapt it for whatever app you're developing. Remember to comment the code to show your understanding.
Here you'll find all the example code which accompanies **Data, Networks & the Web**. If you adapt the example code, remember to comment it to show your understanding.
For *individual lab instructions*, please refer to the [Lab Exercise Wiki](http://gitlab.doc.gold.ac.uk/data-networks-web/lab-exercises/wikis/home).
## Topic finder
Here's a reminder of the topics covered in each lab session. Please note, topics may be subject to change if a lab has not yet occurred.
### Lab 1: Setting up your development environment (6/7 Oct)
- creating a project repo
- cloning your repo to IGOR and/or locally
- mounting IGOR (if applicable)
### Lab 2: Introduction to relational databases and SQL (13/14 Oct)
- Designing a schema
- Defining a schema in SQL (TABLE CREATE)
- Inserting data (INSERT INTO)
- Basic querying (SELECT)
### Lab 3: SQL sequel! (Advanced querying) (20/21 Oct)
- Sorting (ORDER BY)
- Table joins
- Aggregate functions
- Comparison operators
### Lab 4: Security and integrity! (27/28 Oct)
- Data normalisation
- Backup/restore
### Lab 5: Using PHP to interact with a MySQL database (10/11 Nov)
- mysqli API
- Displaying data
### Lab 6: Basic Application Design (17/18 Nov)
- Code organisation ('separation of concerns')
- Single Point of Entry (SPOE)
- Creating and changing 'views'
- Passing parameters in GET
### Lab 7: Form handling and data manipulation (24/25 Nov)
- POST method
- Basic data sanitization methods
### Lab 8: Implementing transactions & read locking in PHP (1/2 Dec)
- Transaction & read locking examples
### Lab 9: Introduction to MongoDB (non-assessed) (8/9 Dec)
- Document structure
- Creating a collection
- MongoDB CRUD operations
images/api.png

51 KiB

images/flask-login.png

127 KiB

images/flask-restless-api.png

62.6 KiB

images/flask_and_forms.png

80.4 KiB

images/flask_and_forms_with_questions.png

143 KiB

images/http-request-response-hand-drawn.png

201 KiB

images/internet_protocol.png

60 KiB

images/login.png

102 KiB

images/pythonclass.contentmap.2017-2018.jpg

624 KiB

*********************************
* A TEST APPLICATION *
*********************************
Description
-----------
This is a test PHP application. You can upload use it to test your LAMP stack. You can also browse the directory structure to get an idea of how PHP web applications are commonly structured. You can also read this README file to find out the sorts of things that should be included in a README file!
Author & Contact
----------------
Sorrel Harriet s.harriet@gold.ac.uk
Installation Instructions
-------------------------
Upload the application to your web root folder. No further actions needed!
Configuration Instructions
--------------------------
There is nothing to configure.
\ No newline at end of file
<?php
# Write some helper functions here...
?>
<?php
// Code to detect whether index.php has been requested without query string
// If no page parameter detected...
if (!isset($_GET['page'])) {
$id = 'home'; // display home page
} else {
$id = $_GET['page']; // else requested page
}
$content = '';
// Switch statement to decide content of page will go here.
// Regardless of which "view" is displayed, the variable $content will
switch ($id) {
case 'home' :
include 'views/home.php';
break;
case 'page_2' :
include 'views/page_2.php';
break;
default :
include 'views/404.php';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test Application</title>
</head>
<body>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="index.php?page=page_2">Page 2</a></li>
</ul>
<?php
// Display content for requested view.
echo $content;
?>
</body>
</html>
<?php
$content = "<h1>Page not found</h1>";
$content .= "<p>Sorry, the page you requested could not be found.</p>";
?>
<?php
$content = '<h1>Hello world!</h1>';
$content .= '<p>If you\'re reading this, it means you have successfully launched the <b>test app</b>.</p>'
?>
<?php
$content = '<h1>Welcome to page 2!</h1>';
?>
def a_decorator(a_function):
def wrapper():
print("this gets done before a_function() is called.")
a_function()
print("this gets done after a_function() is called.")
return wrapper
def an_actual_function():
print("i am an_actual_function!")
an_actual_function = a_decorator(an_actual_function)
an_actual_function()
import time
def timing_function(some_function):
"""
Outputs the time a function takes
to execute.
"""
def wrapper():
t1 = time.time()
some_function()
t2 = time.time()
return "Time it took to run the function: " + str((t2 - t1)) + "\n"
return wrapper
@timing_function
def my_function():
num_list = []
for num in (range(0, 10000)):
num_list.append(num)
print("\nSum of all the numbers: " + str((sum(num_list))))
print(my_function())
from flask import Flask
import feedparser # this module reads the rss feeds
from random import randint
app = Flask(__name__)
BBC_FEED = "http://feeds.bbci.co.uk/news/rss.xml"
@app.route("/")
def headline():
feed = feedparser.parse(BBC_FEED)
article = feed['entries'][0]
return """<html>
<body>
<h1> BBC headline </h1>
<b>{0}</b> <br/>
<i>{1}</i> <br/>
<p>{2}</p> <br/>
</body>
</html>""".format(article.get("title"),
article.get("published"), article.get("summary"))
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8000)
from flask import Flask, render_template
import feedparser
app = Flask(__name__)
BBC_FEED = "http://feeds.bbci.co.uk/news/rss.xml"
@app.route("/")
def headlines():
feed = feedparser.parse(BBC_FEED)
articles = feed['entries']
return render_template('headlines.html',articles=articles)
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8000)