diff --git a/dev-data/Network_fundamentals.md b/dev-data/Network_fundamentals.md deleted file mode 100644 index 2d8456b..0000000 --- a/dev-data/Network_fundamentals.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: Network_fundamentals -tags: [networks, network-protocols] -created: Saturday, August 03, 2024 ---- - -# Network fundamentals - -> A network is a system that allows computing devices to communicate and -> exchange information with each other. - -In order for devices to be able to communicate they must share a common -**communication protocol**. - -A protocol specifies **rules determining how information is to be exchanged**. -(Simply connecting two devices is not sufficient for them to be able to -communicate, they must have a shared language.) - -The nodes of a network are called [hosts](Network_hosts.md). diff --git a/dev-data/Peer_to_peer_network.md b/dev-data/Peer_to_peer_network.md deleted file mode 100644 index 9e14cce..0000000 --- a/dev-data/Peer_to_peer_network.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -title: Peer_to_peer_network -tags: [networks] -created: Friday, August 09, 2024 ---- - -# Peer to peer network - -A decentralised network model where each participant (peer) acts as both a -client and a server. - -Resources are shared directly between peers rather than being coordinated via a -server. - -Under a server architecture, multiple requests are made from different hosts for -resources. The server manages this load and is in control of what is being -shared, to whom, and when. With P2P there is no central authority equivalent to -this. Each peer both shares and consumes resources and in this sense is both a -client and a server. - -A practical example of this is [torrenting](Torrenting.md) - an applicaton of -P2P technology to file sharing. - -## Benefits - -- Decentralisation, no central authority, also means no single point of failure. -- Scalable: the network capacity grows with the number of users (contrast - servers) -- Efficiency: idle resources of peers are put to use -- Improved performance for popular content - -## Drawbacks - -- Security: potential for malicious peers and content -- Inconsistent availability of resources diff --git a/dev-data/Turing_completeness.md b/dev-data/Turing_completeness.md deleted file mode 100644 index f2de6f5..0000000 --- a/dev-data/Turing_completeness.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: Turing_Completeness -tags: [theory-of-computation, Turing] -created: Friday, September 13, 2024 ---- - -# Turing Completeness -We know that a [Turing machine](Turing_machines.md) is a theoretical construct -of a computer that: - -> contains mutable state, executes sequences of simple instructions that read -> and write that state, and can pick different execution paths depending on the -> state (via conditional branch instructions.) - -A Turing Complete (TC) system is a system that abides by, or can be reduced to, -the above description. - -TC also serves as a _definition of computability_ and provides a formal basis -for conceiving of computation at a theoretical level. - -All Turing Complete systems are functionally equivalent. This means they can -simulate each other given enough time and memory. Similarly a TC system can in -principle perform any computation that any other programmable computer can -perform. This is true for _other_ TC systems and also those that are not TC -however the inverse doesn't hold: a non-TC system cannot emulate a TS system. -For instance a calculator cannot do what a TC smart phone can do. But a smart -phone can act as a calculator. - -Completeness applies to the hardware of computers as well as their software. - -Turing Completeness is the theoretical basis of the practical concept of a -"general-purpose computer": a general-purpose computer is such because it is -TC - it can in theory compute anything that is computable. - -Most modern programming languages are Turing Complete in that they can, in -theory, be used to compute anything that is computable. - -What about Universal Turing Machines eh? - - -Within the [hierarchy of the OS](./Basic_model_of_the_operating_system.md), the -kernel acts as the primary mediator between the hardware (CPU, memory) and -[user](./User_Space.md) [processes](Processes.md). Let's look at each of its -responsibilities in greater depth: - diff --git a/src/models/entry.py b/src/models/entry.py new file mode 100644 index 0000000..b4b30c9 --- /dev/null +++ b/src/models/entry.py @@ -0,0 +1,10 @@ +from typing import List, TypedDict + + +class Entry(TypedDict): + title: str + last_modified: str + size: str + tags: List[str] + links: List[str] + body: str diff --git a/src/services/sqlite_service.py b/src/services/sqlite_service.py index 066b2e8..e7e95f1 100644 --- a/src/services/sqlite_service.py +++ b/src/services/sqlite_service.py @@ -1,9 +1,8 @@ -from sql.create_tables import ( - CREATE_BACKLINKS_TABLE, - CREATE_ENTRIES_TABLE, - CREATE_ENTRIES_TAGS_TABLE, - CREATE_TAGS_TABLE, -) +import sqlite3 +from typing import Optional + +from sql.create_tables import tables +from src.models.entry import Entry class SqliteService: @@ -11,17 +10,31 @@ class SqliteService: self.connection = connection self.cursor = connection.cursor() + def __query(self, sql, errorMessage: Optional[str] = None): + try: + self.cursor.execute(sql) + self.connection.commit() + + except sqlite3.Error as sqliteError: + raise Exception(f"ERROR SQLite: {sqliteError}") + + except Exception as e: + if errorMessage: + raise Exception(f"ERROR {errorMessage}: {e}") + else: + raise Exception(f"ERROR Problem with database operation: {e}") + def create_tables(self): - tables = [ - CREATE_ENTRIES_TABLE, - CREATE_TAGS_TABLE, - CREATE_BACKLINKS_TABLE, - CREATE_ENTRIES_TAGS_TABLE, - ] - for create_statement in tables: - self.cursor.execute(create_statement) + for table in tables: + self.__query( + table["create_statement"], f"Problem creating table {table['name']}" + ) + print("INFO Created tables") - self.connection.commit() - - self.cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") - print(self.cursor.fetchall()) + def truncate_tables(self): + for table in tables: + self.__query( + f"DELETE FROM {table['name']}", + f"Problem truncating table {table['name']}", + ) + print("INFO Cleared tables")