<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2014-12-15 18:07:58
# @Author  : <EMAIL>

import tornado.web
from ..models.data_cache import DataCache
from sqlalchemy.orm.exc import NoResultFound
import json, base64

class SchoolBusHandler(tornado.web.RequestHandler):

    @property
    def db(self):
        return self.application.db

    def get(self):
        self.init_db()
        #self.write('Herald Web Service')

    def post(self):
        try:
            data = self.db.query(DataCache).filter( DataCache.key == 10001 ).one()
            self.write(base64.b64decode(data.data))
            self.db.close()
            self.finish()
        except:
            retjson = {'code':500, 'content':'error'}
            self.write(json.dumps(retjson, ensure_ascii=False, indent=2))
            self.finish()

    def init_db(self):
        bus_json = {
            'weekday' : {
                '进九龙湖' : [
                    {'time': '06:50', 'bus': '2辆九江线、3辆九河直、3辆九河B'},
                    {'time': '07:50', 'bus': '1辆九桥线'},
                    {'time': '08:00', 'bus': '2辆九江线、7辆(周一+1)九河直、7辆(周一+1)九河B'},
                    {'time': '08:30', 'bus': '3辆九河直、3辆九河B'},
                    {'time': '09:30', 'bus': '1辆九河B'},
                    {'time': '13:00', 'bus': '3辆九河直、3辆九河B'},
                    {'time': '14:30', 'bus': '1辆九河B'},
                    {'time': '17:00', 'bus': '1辆九河B'},
                    {'time': '17:30', 'bus': '1辆九河B'},
                    {'time': '19:00', 'bus': '1辆九河B'},
                ],
                '出九龙湖' : [
                    {'time': '08:15', 'bus': '1辆九河B'},
                    {'time': '09:50', 'bus': '2辆九河直、2辆九河B'},
                    {'time': '10:50', 'bus': '2辆九河直、2辆九河B'},
                    {'time': '11:45', 'bus': '3辆九河直、3辆九河B、3辆九江线'},
                    {'time': '13:00', 'bus': '3辆九河直、3辆九河B'},
                    {'time': '15:50', 'bus': '3辆九河直、3辆九河B'},
                    {'time': '17:00', 'bus': '9辆（周一+1）九河直、9辆（周一+1）九河B、9辆（周一+1）九江线、9辆（周一+1）九桥线'},
                    {'time': '17:40', 'bus': '1辆九河B'},
                    {'time': '18:30', 'bus': '1辆九河B'},
                    {'time': '21:30', 'bus': '1辆九河B'},
                ],
            },
            'weekend' : {
                '进九龙湖' : [
                    {'time': '08:00', 'bus': '2辆九河直、2辆九河B'},
                    {'time': '09:00', 'bus': '1辆九河B'},
                    {'time': '10:00', 'bus': '1辆九河直'},
                    {'time': '13:00', 'bus': '1辆九河B'},
                    {'time': '15:00', 'bus': '1辆九河直'},
                    {'time': '17:00', 'bus': '1辆九河直'},
                    {'time': '19:00', 'bus': '1辆九河直'},
                ],
                '出九龙湖' : [
                    {'time': '09:00', 'bus': '1辆九河直'},
                    {'time': '10:00', 'bus': '1辆九河直'},
                    {'time': '13:00', 'bus': '1辆九河B'},
                    {'time': '17:00', 'bus': '2辆九河直、2辆九河B'},
                    {'time': '18:00', 'bus': '1辆九河直'},
                    {'time': '20:00', 'bus': '1辆九河直'},
                ],
            },
        }
        retjson = {'code': 200, 'content': bus_json}
        try:
            data = self.db.query(DataCache).filter( DataCache.key == 10001 ).one()
            data.data = base64.b64encode(json.dumps(retjson, ensure_ascii=False, indent=2))
        except NoResultFound:
            data = DataCache(key=10001, data=base64.b64encode(json.dumps(retjson, ensure_ascii=False, indent=2)))
        self.db.add(data)
        self.db.commit()

<commit_msg>new bus<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2014-12-15 18:07:58
# @Author  : <EMAIL>

import tornado.web
from ..models.data_cache import DataCache
from sqlalchemy.orm.exc import NoResultFound
import json, base64

class SchoolBusHandler(tornado.web.RequestHandler):

    @property
    def db(self):
        return self.application.db

    def get(self):
        self.init_db()
        #self.write('Herald Web Service')

    def post(self):
        try:
            data = self.db.query(DataCache).filter( DataCache.key == 10001 ).one()
            self.write(base64.b64decode(data.data))
            self.db.close()
            self.finish()
        except:
            retjson = {'code':500, 'content':'error'}
            self.write(json.dumps(retjson, ensure_ascii=False, indent=2))
            self.finish()

    def init_db(self):
        bus_json = {
            "weekend":{
                "出九龙湖":[
                    { "time":"8:00-9:30", "bus":"每 30min 一班"},
                    { "time":"9:30-11:30", "bus":"每 1h 一班"},
                    { "time":"11:30-13:00", "bus":"每 30min 一班"},
                    { "time":"13:00-17:00", "bus":"每 1h 一班"},
                    { "time":"17:00-18:30", "bus":"每 30min 一班"},
                    { "time":"18:30-22:00", "bus":"每 1h 一班"}
                ],
                "进九龙湖":[
                    { "time":"8:00-9:30", "bus":"每 30min 一班"},
                    { "time":"9:30-11:30", "bus":"每 1h 一班"},
                    { "time":"11:30-13:00", "bus":"每 30min 一班"},
                    { "time":"13:00-17:00", "bus":"每 1h 一班" },
                    { "time":"17:00-18:30", "bus":"每 30min 一班"},
                    { "time":"18:30-22:00", "bus":"每 1h 一班"}
                ]
            },
            "weekday":{
                "出九龙湖":[
                    { "time":"7:20-9:00", "bus":"每 5min 一班"},
                    { "time":"9:00-11:30", "bus":"每 1h 一班"},
                    { "time":"11:30-13:00", "bus":"每 5min 一班"},
                    { "time":"13:00-17:00", "bus":"每 1h 一班"},
                    { "time":"17:00-18:30", "bus":"每 5min 一班"},
                    { "time":"18:30-22:00", "bus":"每 1h 一班"}
                ],
                "进九龙湖":[
                    { "time":"7:20-9:00", "bus":"每 5min 一班"},
                    { "time":"9:00-11:30", "bus":"每 1h 一班"},
                    { "time":"11:30-13:00", "bus":"每 5min 一班"},
                    { "time":"13:00-17:00", "bus":"每 1h 一班"},
                    { "time":"17:00-18:30", "bus":"每 5min 一班"},
                    { "time":"18:30-22:00", "bus":"每 1h 一班"}
                ]
            }

        }
        retjson = {'code': 200, 'content': bus_json}
        try:
            data = self.db.query(DataCache).filter( DataCache.key == 10001 ).one()
            data.data = base64.b64encode(json.dumps(retjson, ensure_ascii=False, indent=2))
        except NoResultFound:
            data = DataCache(key=10001, data=base64.b64encode(json.dumps(retjson, ensure_ascii=False, indent=2)))
        self.db.add(data)
        self.db.commit()


{'fraction_non_alphanumeric': 0.20621808350856113, 'fraction_numerical': 0.07569840793030941, 'mean_word_length': 1.5611538461538461, 'pattern_counts': {'":': 54, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4478221', 'n_tokens_mistral': 2815, 'n_tokens_neox': 2615, 'n_words': 403}