Ejemplo n.º 1
0
def main():

    controller = router.route(None, "main menu")

    while True:
        controller = router.route(controller, controller.act())
        if controller == None:
            break
Ejemplo n.º 2
0
with open("bot_commands.json", encoding="UTF-8") as bot_commands_file:
    telegram_message_manager.set_bot_commands(bot_commands_file.read())

# the 'game' loop that listens for new messages and responds to them
while True:
    time.sleep(0.1)

    updates = telegram_message_manager.get_latest_messages()

    with sqlite3.connect(DATABASE_NAME) as connection:
        repository = Repository(connection)
        controller = Controller(telegram_message_manager, repository)

        # iterate over the latest messages for update in updates:
        for update in updates:
            (target_handler, handler_arguments) = route(update)
            if target_handler is None:
                continue
            try:
                target_handler(controller, *handler_arguments)
            except KeyboardInterrupt:
                exit()
            except HTTPError as http_error:
                print(
                    "Encountered an HTTP error\n" + "Stack trace:\n" +
                    f"{traceback.format_exc()}\n" +
                    f"URL: {http_error.url}\n" +
                    f"Response: {http_error.file.read().decode('UTF-8')}\n\n")
                controller.handle_error_while_processing_update(update)
            except Exception as error:
                print(traceback.format_exc())
Ejemplo n.º 3
0
from flask import Flask
from api.account.session import MongoSessionInterface
import router
from stations import updater


app = Flask(__name__)
app.debug = True
app.session_interface = MongoSessionInterface()
router.route(app)
stations_updater = updater.StationsUpdater()
stations_updater.start()

app.run(host='127.0.0.1', port=5001)
Ejemplo n.º 4
0
import router, util 




try:
	file_path = raw_input("Please set input file path: ")
except Exception, e:
    print e
    exit()

print 'file path: ' + file_path
start, dest,dimension,faultyLinks = util.readValueFromFile(file_path)
print "Start: " + start
print "Destination: " + dest
print "Dimension of graph: " + str(dimension)
print "Faulty links: " + str(faultyLinks)
print ""




result = router.route(start,dest, dimension,faultyLinks)

print ""
print "Routes: "
for node in result:
	print node
Ejemplo n.º 5
0
import router, util

try:
    file_path = raw_input("Please set input file path: ")
except Exception, e:
    print e
    exit()

print 'file path: ' + file_path
start, dest, dimension, faultyLinks = util.readValueFromFile(file_path)
print "Start: " + start
print "Destination: " + dest
print "Dimension of graph: " + str(dimension)
print "Faulty links: " + str(faultyLinks)
print ""

result = router.route(start, dest, dimension, faultyLinks)

print ""
print "Routes: "
for node in result:
    print node
Ejemplo n.º 6
0
def application(request):
    return router.route(request)
Ejemplo n.º 7
0
    @param msg: message body of reply job in json format
    @type msg: str

    @return: a list consists of `rap_in` or `rap_out`
    @rtype: list
    """

    src = json.loads(msg)
    if not src['post_url']:
        return []
    for pattern, handler in config.dispatch_rule.items():
        if re.search(pattern, src['post_url']):
            logging.info(handler)
            if handler[1] == 'IN':
                return ['rap_in']
            elif handler[1] == 'OUT':
                return ['rap_out']
    # Although no such handler, discarding it will cause some db problems. So
    # pass it to a queue.
    return ['rap_in']


if __name__ == '__main__':
    # Load local configurations.
    CONFIG = yaml.load(open('config.yaml'))
    # Logging config.
    logging.config.dictConfig(CONFIG)

    router.route(['rap_server'], rap_dispatcher, 
                 CONFIG['beanstalk']['ip'], CONFIG['beanstalk']['port'])
    
Ejemplo n.º 8
0
 def do_GET(self):
     """Serve GET requests"""
     self.respond(*router.route(self.path))
     pass
Ejemplo n.º 9
0
 def do_POST(self):
     """Serve POST requests"""
     content_len = int(self.headers.get('Content-Length'))
     buf = self.rfile.read(content_len)
     self.respond(*router.route(self.path, input=buf))
     return