Ver Fonte

intitial commit

Eren Yilmaz há 6 anos atrás
commit
60eaba2e31
7 ficheiros alterados com 70 adições e 0 exclusões
  1. 3 0
      .gitignore
  2. 8 0
      client.py
  3. 1 0
      connection.py
  4. 41 0
      db.py
  5. 1 0
      login.py
  6. 15 0
      server.py
  7. 1 0
      util.py

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+.idea
+*.db
+venv

+ 8 - 0
client.py

@@ -0,0 +1,8 @@
+import http.client as httplib
+import subprocess
+import connection
+
+c = httplib.HTTPConnection('localhost', connection.port)
+c.request('POST', '/login', '{}')
+doc = c.getresponse().read()
+print(doc)

+ 1 - 0
connection.py

@@ -0,0 +1 @@
+port = 8451

+ 41 - 0
db.py

@@ -0,0 +1,41 @@
+import sqlite3 as db
+import sys
+
+
+def setup():
+    con = None
+    try:
+        con = db.connect('boerse.db')
+
+        cur = con.cursor()
+
+        # Database setup
+        print('Database setup...')
+        cur.execute('''
+                    CREATE TABLE IF NOT EXISTS users(
+                        username VARCHAR(10) UNIQUE NOT NULL, 
+                        password VARCHAR(6) NOT NULL)
+                    '''
+                    )
+        cur.execute('''
+                    CREATE TABLE IF NOT EXISTS stocks(
+                        name VARCHAR(10) UNIQUE NOT NULL, 
+                        total_available INTEGER NOT NULL)
+                    '''
+                    )
+        cur.execute('''
+                    CREATE TABLE IF NOT EXISTS ownership(
+                        user_id INTEGER NOT NULL,
+                        amount INTEGER NOT NULL DEFAULT 0,
+                        FOREIGN KEY (user_id) REFERENCES users(rowid)
+                    )
+                    '''
+                    )
+
+    except db.Error as e:
+        print("Database error %s:" % e.args[0])
+        sys.exit(1)
+
+    finally:
+        if con is not None:
+            con.close()

+ 1 - 0
login.py

@@ -0,0 +1 @@
+print('login successful')

+ 15 - 0
server.py

@@ -0,0 +1,15 @@
+import connection
+import db
+import subprocess
+from bottle import run, post, request, response, get, route
+
+if __name__ == '__main__':
+    print('sqlite3.version', db.db.version)
+
+    db.setup()
+
+    @route('/<path>', method='POST')
+    def process(path):
+        return subprocess.check_output(['python', path + '.py'], shell=True)
+
+    run(host='localhost', port=connection.port, debug=True)

+ 1 - 0
util.py

@@ -0,0 +1 @@
+def print_variable