-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.14.0 - support save interactive data into database sqlite (#51)
* support save interactive data * support create table when init * change file path * remove wrong path of sqlite * fix Nonetype error * fix Nonetype error2
- Loading branch information
Showing
11 changed files
with
96 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,4 +60,5 @@ def raw(self): | |
|
||
|
||
def root_dir(): | ||
return _cm.ROOT | ||
if _cm: | ||
return _cm.ROOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ def save(self): | |
|
||
|
||
application = Application() | ||
|
||
db = None | ||
|
||
def make_ok_response(**kwargs): | ||
ok_resp = { | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
class DataBase: | ||
def __init__(self, app): | ||
self._db = SQLAlchemy(app) | ||
self._db.init_app(app) | ||
|
||
@property | ||
def model(self): | ||
return self._db.Model | ||
|
||
@property | ||
def session(self): | ||
return self._db.session | ||
|
||
def create_all(self): | ||
self._db.create_all() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
import datetime | ||
import lyrebird | ||
from lyrebird.mock import context | ||
from sqlalchemy import Column, Table, String, Integer, DateTime, Text | ||
|
||
|
||
class Flow(context.db.model): | ||
|
||
id = Column(Integer, primary_key=True, autoincrement=True) | ||
channel = Column(String(16)) | ||
content = Column(Text) | ||
ts = Column(DateTime(timezone=True), default=datetime.datetime.now) | ||
|
||
def __init__(self, channel, content): | ||
self.channel = channel | ||
self.content = content | ||
|
||
def active_db_listener(): | ||
lyrebird.subscribe('any', save_data_into_db, event=True) | ||
context.db.create_all() | ||
|
||
def save_data_into_db(event): | ||
message, channel = event.message, event.channel | ||
content = json.dumps(message) | ||
data = Flow(channel, content) | ||
context.db.session.add(data) | ||
context.db.session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
IVERSION = (0, 13, 9) | ||
IVERSION = (0, 14, 0) | ||
VERSION = ".".join(str(i) for i in IVERSION) | ||
LYREBIRD = "Lyrebird " + VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters