예제 #1
0
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
0
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)