Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
project-api
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
project-api
Commits
0d82859f
Commit
0d82859f
authored
Mar 29, 2018
by
fangzhipeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加数据库连接
parent
74858298
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
1 deletion
+42
-1
weather/dao/__init__.py
weather/dao/__init__.py
+0
-0
weather/dao/models.py
weather/dao/models.py
+14
-0
weather/dao/sqlengin.py
weather/dao/sqlengin.py
+15
-0
weather/service.py
weather/service.py
+13
-1
No files found.
weather/dao/__init__.py
0 → 100644
View file @
0d82859f
weather/dao/models.py
0 → 100644
View file @
0d82859f
# coding: utf-8
from
sqlalchemy
import
Column
,
Integer
,
String
,
text
from
sqlalchemy.ext.declarative
import
declarative_base
Base
=
declarative_base
()
metadata
=
Base
.
metadata
class
UserInfo
(
Base
):
__tablename__
=
'user_info'
id
=
Column
(
Integer
,
primary_key
=
True
,
nullable
=
False
)
nickname
=
Column
(
String
(
50
),
primary_key
=
True
,
nullable
=
False
,
server_default
=
text
(
"''"
))
weather/dao/sqlengin.py
0 → 100644
View file @
0d82859f
import
sqlalchemy
from
sqlalchemy
import
create_engine
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy
import
Column
,
Integer
,
String
from
sqlalchemy.orm
import
sessionmaker
engine
=
create_engine
(
"mysql+pymysql://root:root@localhost/daylife?charset=utf8mb4"
,
echo
=
True
)
# 创建DBSession类型:
DBSession
=
sessionmaker
(
bind
=
engine
)
def
getSession
():
return
DBSession
()
weather/service.py
View file @
0d82859f
...
...
@@ -3,6 +3,8 @@ from flask import request
import
requests
import
json
from
common
import
BaseRes
from
weather.dao
import
sqlengin
from
weather.dao
import
models
weather
=
Blueprint
(
'weather'
,
__name__
,
url_prefix
=
'/weather'
)
...
...
@@ -21,4 +23,14 @@ def hello_world():
data
=
response
[
'data'
]
return
json
.
dumps
(
BaseRes
(
data
[
'forecast'
]),
default
=
lambda
obj
:
obj
.
__dict__
)
return
json
.
dumps
(
BaseRes
(
status
=
404
,
message
=
'无该城市数据,请检查参数是否正确!'
),
default
=
lambda
obj
:
obj
.
__dict__
)
\ No newline at end of file
return
json
.
dumps
(
BaseRes
(
status
=
404
,
message
=
'无该城市数据,请检查参数是否正确!'
),
default
=
lambda
obj
:
obj
.
__dict__
)
@
weather
.
route
(
'/insert_user_info'
)
def
insert_user_info
():
nickname
=
request
.
args
.
get
(
'nickname'
)
session
=
sqlengin
.
getSession
()
for
i
in
range
(
0
,
10000
):
session
.
add
(
models
.
UserInfo
(
nickname
=
nickname
))
session
.
commit
()
session
.
close
()
return
'操作成功!'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment