# coding: utf-8
import json

import flask
from flask import request
import redis
from redis_wrap import get_hash, get_list
import telegram

from utils import *

__name__ = u'eth0_bot'
__author__ = u'Joker_Qyou'
__config__ = u'config.json'

app = flask.Flask(__name__)
app.debug = True

with open(__config__, 'r') as cfr:
    config = json.loads(cfr.read())

path = '/%s' % '/'.join(config.get('server').replace('https://', '').replace('http://', '').split('/')[1:])

raw_redis = redis.StrictRedis(**config.get('redis'))

def init_redis():
    admins = get_list('admins')
    if not admins:
        [admins.append(admin) for admin in config.get('admins')]

init_redis()

@app.route('%s/%s' % (path, config.get('token').split(':')[-1], ), methods=('POST', ))
def webhook():
    ''' WebHook API func '''
    update = request.json
    handle_message(update.get('message'))
    return ''

def handle_message(message):
    text = message.get('text', '').strip()
    photo = message.get('photo', {})
    if text:
        if text.startswith('/'):
            handle_command(text, message)
        else:
            handle_text(text, message)
    if photo:
        send_reply(text='很好，我收到了一张图片，然而这并没有什么卯月', message=message)

def handle_command(text, message):
    text = u'%s 命令现在并没有什么卯月' % text
    send_reply(text=text, message=message)

def handle_text(text, message):
    text = u'%s: %s' % (u'复读机', text, )
    send_reply(text=text, message=message)

def send_reply(text=None, photo=None, emoji=None, audio=None, message=None, reply=True):
    if not message:
        raise RuntimeError('Dont know the chat id')
    if not text: return
    bot.sendMessage(text=smart_text(text), 
                    chat_id=message.get('chat').get('id'), 
                    reply_to_message_id=message.get('id'))

bot = telegram.Bot(token=config.get('token'))
bot.setWebhook('%s/%s' % (config.get('server'), config.get('token').split(':')[-1], ))

app.run(host='0.0.0.0', port=config.get('port'))


@@ -575,18 +575,24 @@
  if 
-not 
+len(
 admins
+) == 0
 :%0A  
@@ -659,22 +659,8 @@
 )%5D%0A%0A
-init_redis()%0A%0A
 @app
@@ -1781,16 +1781,50 @@
 'id'))%0A%0A
+def main():%0A    init_redis()%0A%0A    
 bot = te
@@ -1861,16 +1861,20 @@
 oken'))%0A
+    
 bot.setW
@@ -1953,16 +1953,20 @@
 1%5D, ))%0A%0A
+    
 app.run(
@@ -2003,12 +2003,50 @@
 t('port'))%0A%0A
+if __name__ == '__main__':%0A    main()%0A

Fix redis config init; Add main function