Skip to content

Instantly share code, notes, and snippets.

View Olisss's full-sized avatar

Olisss Olisss

View GitHub Profile
#!/usr/bin/python
from pyramid.config import Configurator
from pyramid.response import Response
from jinja2 import FileSystemLoader,Template,Environment
from wsgiref.simple_server import make_server
env = Environment(loader=FileSystemLoader('HTML'))
Задание:
1. Create a class/mapping for this table, call the class Network
CREATE TABLE network (
network_id INTEGER PRIMARY KEY,
name VARCHAR(100) NOT NULL,
)
2. emit Base.metadata.create_all(engine) to create the table
3. commit a few Network objects to the database:
Network(name='net1'), Network(name='net2')
-----------------------------------------------------------------------------
@Olisss
Olisss / Лабораторная №5
Created November 17, 2017 20:45
03_sql_expressions.py
Задание:
Produce these expressions using "user_table.c.fullname",
"user_table.c.id", and "user_table.c.username":
1. user.fullname = 'ed'
2. user.fullname = 'ed' AND user.id > 5
3. user.username = 'edward' OR (user.fullname = 'ed' AND user.id > 5)
----------------------------------------------------------------------
Код:
from sqlalchemy import create_engine, MetaData
Задание:
1. Write a Table construct corresponding to this CREATE TABLE statement.
engine = create_engine("sqlite://some.db")
metadata.create_all(engine)
network_id INTEGER PRIMARY KEY,
name VARCHAR(100) NOT NULL,
created_at DATETIME NOT NULL,
owner_id INTEGER,
FOREIGN KEY owner_id REFERENCES user(id)
)
@Olisss
Olisss / Лабораторная №5
Last active November 18, 2017 11:12
01_engine_usage.py
Задание:
Assuming this table:
CREATE TABLE employee (
emp_id INTEGER PRIMARY KEY,
emp_name VARCHAR(30)
}
And using the "engine.execute()" method to invoke a statement:
1. Execute an INSERT statement that will insert the row with emp_name='dilbert'.
The primary key column can be omitted so that it is generated automatically.
Запрос:
from webob import Request
req = Request.blank('/post')
req.host = 'httpbin.org/post'
req.accept = 'multipart/form-data'
req.http_version = 'HTTP/1.1'
req.method = 'POST'
req.text = 'firstname: Olga\nlastname: Umutbaeva\ngroup: FO-350005\nmessage: Hurray!\nmyimg: img'
Запрос 1:
from webob import Request, Response
req = Request.blank('/ip')
req.host = 'httpbin.org'
req.accept = '*/*'
req.http_version = 'HTTP/1.1'
print(req)
Запрос:
from webob import Request, Response
req = Request.blank('/wiki/stranica')
req.host = 'ru.wikipedia.org'
req.accept = 'text/html'
req.headers['connection'] = 'close'
req.user_agent = 'Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9b5)'
req.http_version = 'HTTP/1.1'
print(req)
1. Запускаем в терминале файл SWGI.py (название моего файла, в котором хранится код).
Сам код выглядет так:
class WsgiTopBottomMiddleware(object):
def __init__(self, app):
self.app = app
self.assets = [
'app.js',
'react.js',
'leaflet.js',
'D3.js',
В терминале ввели команду 'ifconfig', далее команду 'sudo tcpdump -X -i enp0s3host httpbin.org and port 80'
Во втором терминале открыли файлик с кодом:
#!/usr/bin/python
#codin: utf8
import requests
response = requests.post("http://httpbin.org/post", data={"github": "Olisss", "Name": "Olga", "Surname": "Umutbaeva"})
print(response.headers)
И получили ответ: