diff --git a/Flask/1.text b/Flask/1.text new file mode 100644 index 0000000..9b6a77c --- /dev/null +++ b/Flask/1.text @@ -0,0 +1,4 @@ +import requests + +requests.post('http://localhost:5000/api/v1/users', json={}, headers={'Content-Type': 'application/json'}) +requests.get('http://localhost:5000/api/v1/users').json() \ No newline at end of file diff --git a/Flask/README.md b/Flask/README.md new file mode 100644 index 0000000..ceeb317 --- /dev/null +++ b/Flask/README.md @@ -0,0 +1 @@ +# GigaAsessor \ No newline at end of file diff --git a/Flask/__pycache__/db.cpython-38.pyc b/Flask/__pycache__/db.cpython-38.pyc new file mode 100644 index 0000000..ba7aaa8 Binary files /dev/null and b/Flask/__pycache__/db.cpython-38.pyc differ diff --git a/Flask/__pycache__/user_resources.cpython-38.pyc b/Flask/__pycache__/user_resources.cpython-38.pyc new file mode 100644 index 0000000..7bafa7c Binary files /dev/null and b/Flask/__pycache__/user_resources.cpython-38.pyc differ diff --git a/Flask/db.py b/Flask/db.py new file mode 100644 index 0000000..5247a56 --- /dev/null +++ b/Flask/db.py @@ -0,0 +1,13 @@ +import sqlite3 + +con = sqlite3.connect('db.sqlite', check_same_thread=False) + + +def db_init(path): + global con + + with con: + con.execute("""CREATE TABLE IF NOT EXISTS User ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + login TEXT + )""") diff --git a/Flask/db.sqlite b/Flask/db.sqlite new file mode 100644 index 0000000..3a090e6 Binary files /dev/null and b/Flask/db.sqlite differ diff --git a/Flask/main.py b/Flask/main.py new file mode 100644 index 0000000..4a72645 --- /dev/null +++ b/Flask/main.py @@ -0,0 +1,22 @@ +from flask import Flask, render_template +from flask_restful import Api + +from user_resources import UserListResource +from db import db_init, con + +app = Flask(__name__) +app.config['DEBUG'] = True + +api = Api(app) +api.add_resource(UserListResource, '/api/v1/users') + + +@app.route('/') +def index(): + return render_template('index.html') + + +if __name__ == '__main__': + db_init('db.sqlite') + print(con) + app.run('127.0.0.1', 5000) \ No newline at end of file diff --git a/Flask/requirements.txt b/Flask/requirements.txt new file mode 100644 index 0000000..02ee5eb --- /dev/null +++ b/Flask/requirements.txt @@ -0,0 +1,25 @@ +aniso8601==9.0.1 +blinker==1.6.2 +certifi==2023.5.7 +charset-normalizer==3.1.0 +click==8.1.3 +colorama==0.4.6 +exceptiongroup==1.1.1 +Flask==2.3.2 +Flask-RESTful==0.3.9 +idna==3.4 +importlib-metadata==6.6.0 +iniconfig==2.0.0 +itsdangerous==2.1.2 +Jinja2==3.1.2 +MarkupSafe==2.1.2 +packaging==23.1 +pluggy==1.0.0 +pytest==7.3.1 +pytz==2023.3 +requests==2.30.0 +six==1.16.0 +tomli==2.0.1 +urllib3==2.0.2 +Werkzeug==2.3.3 +zipp==3.15.0 diff --git a/Flask/static/assets/background.jpg b/Flask/static/assets/background.jpg new file mode 100644 index 0000000..293a7be Binary files /dev/null and b/Flask/static/assets/background.jpg differ diff --git a/Flask/static/assets/dc.jpeg b/Flask/static/assets/dc.jpeg new file mode 100644 index 0000000..2847d1f Binary files /dev/null and b/Flask/static/assets/dc.jpeg differ diff --git a/Flask/static/assets/tg.jpeg b/Flask/static/assets/tg.jpeg new file mode 100644 index 0000000..dda7730 Binary files /dev/null and b/Flask/static/assets/tg.jpeg differ diff --git a/Flask/static/css/index.css b/Flask/static/css/index.css new file mode 100644 index 0000000..4548d2e --- /dev/null +++ b/Flask/static/css/index.css @@ -0,0 +1,18 @@ +.banner { + background: url(../assets/background.jpg); + color: white; + margin: 15px 0; +} + +.use { + color: white; +} + +.bot { + max-width: 500px; + flex-grow: 1; + outline: solid #94b9f1 2px; + + border-radius: 21px; +} + diff --git a/Flask/static/favicon.png b/Flask/static/favicon.png new file mode 100644 index 0000000..a6fc97c Binary files /dev/null and b/Flask/static/favicon.png differ diff --git a/Flask/templates/index.html b/Flask/templates/index.html new file mode 100644 index 0000000..79349ad --- /dev/null +++ b/Flask/templates/index.html @@ -0,0 +1,96 @@ + + + + + + + GigaAsessor + + + + + + +
+
+ + + GigaAsessor + + + +
+
+
+ + + + +
+
+
+

Telegram

+

Переходи по ссылке

+ Перейти в чат-бот +
+
+ +
+
+
+

Discord

+

Переходи по ссылке

+ Перейти в чат-бот +
+
+ +
+
+
+ + + +
+ +
+ + + + diff --git a/Flask/test_post_requests.py b/Flask/test_post_requests.py new file mode 100644 index 0000000..ea38bdc --- /dev/null +++ b/Flask/test_post_requests.py @@ -0,0 +1,6 @@ +import requests + +for _ in range(3): + requests.post('http://localhost:5000/api/v1/users', json={'login': 'dudavik', 'ginger': 123}, headers={'Content-Type': 'application/json'}).json() +response = requests.get('http://localhost:5000/api/v1/users').json() +print(response) \ No newline at end of file diff --git a/Flask/test_rest_api.py b/Flask/test_rest_api.py new file mode 100644 index 0000000..df595ab --- /dev/null +++ b/Flask/test_rest_api.py @@ -0,0 +1,43 @@ +import requests +import unittest + +from db import con + + +def post_test(*args, **kwargs): + return requests.post(*args, **kwargs).json() + + + +class RESTApiTestPost(unittest.TestCase): + def test_null_post(self): + response = post_test('http://localhost:5000/api/v1/users', json={}, headers={'Content-Type': 'application/json'}) + self.assertEqual(response['success'], 'OK') + + def test_post_with_data(self): + response = post_test('http://localhost:5000/api/v1/users', json={'login': 'dudavik'}, headers={'Content-Type': 'application/json'}) + self.assertEqual(response['success'], 'OK') + + def test_post_with_many_data(self): + response = post_test('http://localhost:5000/api/v1/users', json={'login': 'dudavik', 'ginger': 123}, headers={'Content-Type': 'application/json'}) + self.assertEqual(response['success'], 'OK') + + +class RESTApiTestGet(unittest.TestCase): + def test_get(self): + response = requests.get('http://localhost:5000/api/v1/users').json() + self.assertTrue(response['users_count'] >= 0) + + def test_many_get(self): + with con: + con.execute('DELETE FROM User') + for _ in range(3): + post_test('http://localhost:5000/api/v1/users', json={'login': 'dudavik', 'ginger': 123}, headers={'Content-Type': 'application/json'}) + response = requests.get('http://localhost:5000/api/v1/users').json() + self.assertEqual(response['users_count'], 3) + + +if __name__ == '__main__': + with con: + con.execute('DELETE FROM User') + unittest.main() diff --git a/Flask/user_resources.py b/Flask/user_resources.py new file mode 100644 index 0000000..df443aa --- /dev/null +++ b/Flask/user_resources.py @@ -0,0 +1,34 @@ +from flask import jsonify +from flask_restful import reqparse, abort, Resource +from db import con +from loguru import logger + +def abort_if_user_not_found(user_id): + abort(404, message=f'User {user_id} not found') + +class UserResource(Resource): + pass + + +class UserListResource(Resource): + parser = reqparse.RequestParser() + parser.add_argument('login') + + def get(self): + with con: + users_count = con.execute('SELECT COUNT(*) FROM User').fetchone()[0] + return jsonify({ + 'success': 'OK', + 'users_count': users_count + }) + + def post(self): + args = self.parser.parse_args() + with con: + sql = 'INSERT INTO User (login) VALUES (?)' + data = (args['login'], ) + con.execute(sql, data) + return jsonify({ + 'success': 'OK' + }) + \ No newline at end of file