Skip to content

Commit

Permalink
mac fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benpaddlejones committed Nov 22, 2024
1 parent 39582e2 commit 7793d39
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 77 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion database_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sqlite3 as sql

con = sql.connect(".database/data_source.db")
con = sql.connect("database/data_source.db")
cur = con.cursor()
data = cur.execute('SELECT * FROM extension').fetchall()
con.close()
Expand Down
33 changes: 17 additions & 16 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ A [Progressive Web Apps (PWAs)](https://developer.mozilla.org/en-US/docs/Web/Pro

Because PWAs are websites, they have the same basic features as any other website: at least one HTML page, which loads CSS and JavaScript. Javascript is the language of the web and is exclusively used for the client-side front end; python, in the web context, can only be used in the back end. Like a normal website, the JavaScript loaded by the page has a global Window object and can access all the Web APIs that are available through that object. The PWA standard as defined by [W3C Standards](https://www.w3.org/standards/) has some specific features additional to a website:

| Feature | Purpose |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| manifest.json | An app manifest file, which, at a minimum, provides information that the operating system needs to install the PWA, such as the app name, screen orientation and icon set for different-sized viewports. |
| Feature | Purpose |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| manifest.json | An app manifest file, which, at a minimum, provides information that the operating system needs to install the PWA, such as the app name, screen orientation and icon set for different-sized viewports. |
| serviceworker.js | A service worker, which, at a minimum, manages the caching that enables an online and offline experience whilst also interfacing with API's such as the [notification web API](https://developer.mozilla.org/en-US/docs/Web/API/Notification). It's important to understand that this JS file cannot control the DOM of the application for security reasons. |
| Icons & screenshots | A set of icons and screenshots that are used when uploading to an app store and when installing it as a native application. It is these icons that will be used in the desktop or app launcher when installed. |
| Installable | Because of the information contained in the manifest.json all PWA's can be installed like a native app. They can also be packaged and uploaded to the Google, Microsoft & Apple app stores. |
| Cached locally | Because the service worker details all apps and pages to be cached (all pages must have a \*.html name), the app and its resources can be cached locally for quick load times. _Note backend apps where the web server serves all pages from the DNS root do not meet the PWA specification._ |
| Icons & screenshots | A set of icons and screenshots that are used when uploading to an app store and when installing it as a native application. It is these icons that will be used in the desktop or app launcher when installed. |
| Installable | Because of the information contained in the manifest.json all PWA's can be installed like a native app. They can also be packaged and uploaded to the Google, Microsoft & Apple app stores. |
| Cached locally | Because the service worker details all apps and pages to be cached (all pages must have a \*.html name), the app and its resources can be cached locally for quick load times. _Note backend apps where the web server serves all pages from the DNS root do not meet the PWA specification._ |

The below image illustrates how the servicework manages online and offline behaviour.

Expand All @@ -39,6 +39,7 @@ This screen capture shows how the final PWA will be rendered to the user.

> [!Important]
> MacOS and Linux users may have a `pip3` soft link instead of `pip`, run the below commands to see what path your system is configured with and use that command through the project. If neither command returns a version, then likely [Python 3.x](https://www.python.org/downloads/) needs to be installed.
>
> ```bash
> pip show pip
> pip3 show pip
Expand Down Expand Up @@ -111,10 +112,10 @@ npm install express
### Create files and folders for your node.JS Project
1. Files or folders that start with a dot (`\.*` or `.*.*`) can't be served by the web server. This adds a layer of security for assets that you do not want to be public.
1. Make a folder for all your working documents like photoshop \*.psd files, developer documentation etc.
```bash
mkdir .workingDocuments
mkdir working_documents
```
2. Create a license file.
Expand All @@ -129,8 +130,8 @@ Copy the [GNU GPL license](https://www.gnu.org/licenses/gpl-3.0.txt) text into t
3. Create your directory structure and some base files using BASH scripts reading text files.
```text
├── .database
├── .workingdocuments
├── database
├── working_documents
├── public
│ ├── css
│ ├── icons
Expand Down Expand Up @@ -190,8 +191,8 @@ done < files.txt\
```bash
cd ..
mkdir .database
cd .database
mkdir database
cd database
touch data_source.db
```
Expand Down Expand Up @@ -250,7 +251,7 @@ SELECT * FROM extension WHERE language LIKE '#BASH';
> [!Note]
> Graphic design is not the focus of this course. It is suggested that you do not spend excessive time designing logos and icons.
1. Use Photoshop or [Canva](https://www.canva.com/en_au/signup/?signupRedirect=%2Fedu-signup&loginRedirect=%2Fedu-signup&brandingVariant=edu) to design a simple square logo 1080px X 1080px named logo.png. Save all working files (\*.psd, pre-optimised originals, etc) into the .workingdocuments directory.
1. Use Photoshop or [Canva](https://www.canva.com/en_au/signup/?signupRedirect=%2Fedu-signup&loginRedirect=%2Fedu-signup&brandingVariant=edu) to design a simple square logo 1080px X 1080px named logo.png. Save all working files (\*.psd, pre-optimised originals, etc) into the working_documents directory.
2. Design a simplified app icon 512px X 512px named favicon.png.
3. Web optimise the images using [TinyPNG](https://tinypng.com/).
4. Save the files into the public/images folder.
Expand Down Expand Up @@ -467,7 +468,7 @@ code database_manager.py
```python
import sqlite3 as sql
con = sql.connect(".database/data_source.db")
con = sql.connect("database/data_source.db")
cur = con.cursor()
data = cur.execute('SELECT * FROM extension').fetchall()
con.close()
Expand Down Expand Up @@ -524,7 +525,7 @@ code index.js
```js
const sqlite3 = require("sqlite3").verbose();
const db = new sqlite3.Database(".database/data_source.db");
const db = new sqlite3.Database("database/data_source.db");
let myString = "[\n";
db.all("SELECT * FROM extension", function (err, rows) {
Expand Down Expand Up @@ -905,7 +906,7 @@ app.use(bodyParser.urlencoded({ extended: false }));
```
```js
res.sendFile(path.join(__dirname, ".public/add.html"));
res.sendFile(path.join(__dirname, "public/add.html"));
```
```js
Expand Down
93 changes: 60 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,28 @@
*/

const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('.database/data_source.db');
const sqlite3 = require("sqlite3").verbose();
const db = new sqlite3.Database("database/data_source.db");

let myString = '[\n';
db.all("SELECT * FROM extension", function(err, rows) {
let myString = "[\n";
db.all("SELECT * FROM extension", function (err, rows) {
let myCounter = 0;
rows.forEach(function (row) {
// console.log(row.extID + ": " + row.name + ": " + row.hyperlink + ": " + row.about + ": " + row.image + ": " + row.language);
myString = myString + '{\n"extID":' + row.extID + ',\n"name":"' + row.name + '",\n"hyperlink":"' + row.hyperlink + '",\n"about":"' + row.about + '",\n"image":"' + row.image + '",\n"language":"' + row.language;
// console.log(row.extID + ": " + row.name + ": " + row.hyperlink + ": " + row.about + ": " + row.image + ": " + row.language);
myString =
myString +
'{\n"extID":' +
row.extID +
',\n"name":"' +
row.name +
'",\n"hyperlink":"' +
row.hyperlink +
'",\n"about":"' +
row.about +
'",\n"image":"' +
row.image +
'",\n"language":"' +
row.language;
myCounter++;
if (myCounter == rows.length) {
myString = myString + '"\n}\n';
Expand All @@ -23,36 +36,50 @@ db.all("SELECT * FROM extension", function(err, rows) {
}
});

// console.log(myString);
var fs = require('fs');
fs.writeFile("public/frontEndData.json", myString + "]", function(err) {
// console.log(myString);
var fs = require("fs");
fs.writeFile("public/frontEndData.json", myString + "]", function (err) {
if (err) {
console.log(err);
console.log(err);
}
});
});
});

const express = require("express");
const path = require("path");
const app = express();
app.use(express.static(path.join(__dirname, "public")));
let bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: false}));

app.get("/", function (req, res) {
res.sendFile(path.join(__dirname, "public/index.html"));
res.sendFile(path.join(__dirname,'.public/add.html'));
});

app.post('/add.html', function(req,res){
db.serialize(()=>{
db.run('INSERT INTO contact_list(email,name) VALUES(?,?)', [req.body.email, req.body.name], function(err) {
if (err) {
return console.log(err.message);
}
res.send("Thank you "+req.body.name+" we have added your email "+req.body.email+" to our distribution list.");
});

const express = require("express");
const path = require("path");
const app = express();
app.use(express.static(path.join(__dirname, "public")));
let bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));

app.get("/", function (req, res) {
res.sendFile(path.join(__dirname, "public/index.html"));
res.sendFile(path.join(__dirname, "public/add.html"));
});

app.post("/add.html", function (req, res) {
db.serialize(() => {
db.run(
"INSERT INTO contact_list(email,name) VALUES(?,?)",
[req.body.email, req.body.name],
function (err) {
if (err) {
return console.log(err.message);
}
res.send(
"Thank you " +
req.body.name +
" we have added your email " +
req.body.email +
" to our distribution list."
);
}
);
});
});

app.listen(80, () => console.log("Server is running on Port 80, visit http://localhost:80/ or http://127.0.0.1:80 to access your website") );
app.listen(80, () =>
console.log(
"Server is running on Port 80, visit http://localhost:80/ or http://127.0.0.1:80 to access your website"
)
);
30 changes: 3 additions & 27 deletions public/frontEndData.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,26 @@
[
{
"extID":1,
"name":"Live Server",
"hyperlink":"https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer",
"about":"Launch a development local Server with live reload feature for static & dynamic pages",
"image":"https://ritwickdey.gallerycdn.vsassets.io/extensions/ritwickdey/liveserver/5.7.9/1661914858952/Microsoft.VisualStudio.Services.Icons.Default",
"language":"HTML"
},
{
"extID":2,
"name":"VSCode-SQLite",
"hyperlink":"https://marketplace.visualstudio.com/items?itemName=alexcvzz.vscode-sqlite",
"about":"Explore and query SQLite databases.",
"image":"https://alexcvzz.gallerycdn.vsassets.io/extensions/alexcvzz/vscode-sqlite/0.14.1/1654359416316/Microsoft.VisualStudio.Services.Icons.Default",
"language":"SQL"
},
{
"extID":3,
"name":"Render CR LF",
"hyperlink":"https://marketplace.visualstudio.com/items?itemName=medo64.render-crlf",
"about":"Displays the line ending symbol and optionally extra whitespace when 'Render whitespace' is turned on.",
"image":"https://medo64.gallerycdn.vsassets.io/extensions/medo64/render-crlf/1.7.1/1689315206970/Microsoft.VisualStudio.Services.Icons.Default",
"language":"#BASH"
},
{
"extID":4,
"extID":2,
"name":"Start GIT BASH",
"hyperlink":"https://marketplace.visualstudio.com/items?itemName=McCarter.start-git-bash",
"about":"Adds a bash command to VSCode that allows you to start git-bash in the current workspace's root folder.",
"image":"https://mccarter.gallerycdn.vsassets.io/extensions/mccarter/start-git-bash/1.2.1/1499505567572/Microsoft.VisualStudio.Services.Icons.Default",
"language":"#BASH"
},
{
"extID":5,
"extID":3,
"name":"SQLite3 Editor",
"hyperlink":"https://marketplace.visualstudio.com/items?itemName=yy0931.vscode-sqlite3-editor",
"about":"Edit SQLite3 files like you would in spreadsheet applications.",
"image":"https://yy0931.gallerycdn.vsassets.io/extensions/yy0931/vscode-sqlite3-editor/1.0.85/1690893830873/Microsoft.VisualStudio.Services.Icons.Default",
"language":"SQL"
},
{
"extID":6,
"name":"Start GIT BASH",
"hyperlink":"https://marketplace.visualstudio.com/items?itemName=McCarter.start-git-bash",
"about":"Adds a bash command to VSCode that allows you to start git-bash in the current workspace's root folder.",
"image":"https://mccarter.gallerycdn.vsassets.io/extensions/mccarter/start-git-bash/1.2.1/1499505567572/Microsoft.VisualStudio.Services.Icons.Default",
"language":"#BASH"
}
]
]
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.

0 comments on commit 7793d39

Please sign in to comment.