本文整理汇总了Python中db.Db.load_announces方法的典型用法代码示例。如果您正苦于以下问题:Python Db.load_announces方法的具体用法?Python Db.load_announces怎么用?Python Db.load_announces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Db
的用法示例。
在下文中一共展示了Db.load_announces方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import load_announces [as 别名]
class Announcement:
def __init__(self, max_clients, db_name, db_host, db_port, secret):
self.sequence = secret
self.base64_alt = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
self.db = Db(self, db_name, db_host, db_port)
self.announces = self.db.load_announces()
self.announces_time = int(time.time())
log.msg('Announcement __init__')
log.msg(self.announces)
self.crypt = Crypt(self.sequence)
def get_announce(self, protocol, game_name):
result = self.announces.get(game_name, {'result': '0'})
j = json.dumps(result)
c = self.crypt.crypt(j)
log.msg('Send data to client')
protocol.writeData(c)
protocol.transport.loseConnection()
# refresh announces
if int(time.time()) - self.announces_time > 15:
self.announces = self.db.load_announces()
log.msg('Announces updated')
self.announces_time = int(time.time())
示例2: index
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import load_announces [as 别名]
def index():
if not 'username' in session:
flash('Please log in')
return redirect(url_for('login'))
from db import Db
from forms.edit import EditForm
db = Db()
announces = db.load_announces()
a = {}
counter = 0
edit_forms = []
for key in announces:
item = announces[key]
if 'links' in item and 'announces' in item:
links = item['links']
if 'ios' in links and 'android' in links:
a[key] = item
form = EditForm(request.form, csrf_context=request.remote_addr)
form.name.data = key
form.android.data = links['android']
form.ios.data = links['ios']
texts = ''
for key in item['announces']:
texts = texts + key + "|" + item['announces'][key] + "\n"
form.texts.data = texts
edit_forms.append(form)
counter = counter + 1
return render_template('index.html', announces=a, counter=counter, edit_forms=edit_forms)