-
Notifications
You must be signed in to change notification settings - Fork 1
/
database2.py
87 lines (68 loc) · 2.58 KB
/
database2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import sqlalchemy
from sqlalchemy import Column, ForeignKey, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
# Декларируем базуданных
Base = declarative_base()
class Link0(Base):
__tablename__ = 'google_search_result'
search_id = Column(Integer, primary_key=True)
domain = Column(String(150), nullable=False)
path = Column(String(250), nullable=True)
query = Column(String(999), nullable=True)
baseLinkcount = Column(Integer, nullable=True)
externalLinkcount = Column(Integer, nullable=True)
relativeLinkcount = Column(Integer, nullable=True)
proportion_of_duplicates = Column(Integer, max(0, 100, 99, domain))
class Link(Base):
__tablename__ = 'parse_level_1'
id = Column(Integer, primary_key=True)
url = Column(String(999), unique=True)
domain = Column(String(150), nullable=False)
path = Column(String(250), nullable=True)
query = Column(String(999), nullable=True)
keyword_tags = Column(String(250))
emails = Column(String(999))
baseLinkcount = Column(Integer)
externalLinkcount = Column(Integer)
google_search_id = Column(Integer, ForeignKey('Link0.search_id'))
google_search_result = relationship(Link0)
class Link1(Base):
__tablename__ = 'parse_level_2'
id = Column(Integer, primary_key=True)
domain = Column(String(250))
path = Column(String(250))
query = Column(String(999))
keyword_tags = Column(String(250))
emails = Column(String(999))
baseLinkcount = Column(Integer)
externalLinkcount = Column(Integer)
one_level_req_id = Column(Integer, ForeignKey('Link.id'))
parse_level_1 = relationship(Link)
engine = create_engine('sqlite:///restaurantmenu.db')
Base.metadata.bind = engine
DBSession = sqlalchemy.orm.sessionmaker(bind=engine)
session = DBSession()
def get_all_Link():
all_Link = session.query(Link).all()
return all_Link
def new_Link_db(new_Linkaurant_name):
new_Linkaurant = Link(name=new_Linkaurant_name)
session.add(new_Linkaurant)
session.commit()
return
def get_Link_to_edit(Link_id, new_Link_name=None):
this_Link = session.query(Link).get(Link_id)
if new_Link_name is not None:
this_Link.name = new_Link_name
session.add(this_Link)
session.commit()
else:
return this_Link
def get_Link_to_delete(Link_id, confirm_delete=None):
this_Link = session.query(Link).get(Link_id)
if confirm_delete is not None:
session.delete(this_Link)
session.commit()
else:
return this_Link