def __init__(self, configure_filename): """ Инициализация класса :param configure_filename - путь к конфигурационному файлу """ self.configure = Configure(configure_filename) self.task_factory = TaskFactory() self.task_factory.register_task_creator(HttpTask) self.task_factory.register_task_creator(HttpsTask) self.logger = LoggerFactory.create_logger(queue=last_record_queue, **self.configure.logger)
import tornado.web import tornado.escape import tornado.gen from tornado.httpclient import AsyncHTTPClient, HTTPRequest import requests import re from logger import LoggerFactory from elastic_helper import ElasticHelper import util import traceback from pyquery import PyQuery import lxml from urllib import quote logger = LoggerFactory.getLogger() class XMusicHandler(tornado.web.RequestHandler): headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36' } def set_default_headers(self): self.set_header('Access-Control-Allow-Origin', '*') self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') self.set_header('Access-Control-Allow-Headers', '*') @tornado.web.asynchronous
def post(self): info = self.get_argument('info') LoggerFactory.getLogger().info('IP:'+self.request.headers.get("X-Real-Ip",'') + ' suggest:' + info) self.write('true')
def write_error(self, status_code, **kwargs): LoggerFactory.getLogger().info(kwargs) self.write(status_code)
# -*- coding: utf-8 -*- import tornado.ioloop import tornado.web import config from logger import LoggerFactory from xmusic.xmusic_handler import XMusicHandler from suggest_handler import SuggestHandler import sys application = tornado.web.Application([ (r"/xmusic", XMusicHandler), (r"/suggest", SuggestHandler), (r"/download/(.*)", tornado.web.StaticFileHandler, {"path": config.resource_dir}), ]) if __name__ == "__main__": application.listen(sys.argv[1]) LoggerFactory.getLogger().info("server starting at port: %s" % sys.argv[1]) tornado.ioloop.IOLoop.instance().start()
import tornado.web import tornado.escape import tornado.gen from tornado.httpclient import AsyncHTTPClient,HTTPRequest import requests import re from logger import LoggerFactory from elastic_helper import ElasticHelper import util import traceback from pyquery import PyQuery import lxml from urllib import quote logger = LoggerFactory.getLogger() class XMusicHandler(tornado.web.RequestHandler): headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36'} def set_default_headers(self): self.set_header('Access-Control-Allow-Origin', '*') self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') self.set_header('Access-Control-Allow-Headers', '*') @tornado.web.asynchronous def get(self): try: song_url = self.get_argument('song_url') if len(song_url)==0 :
class ChatHandler(tornado.websocket.WebSocketHandler): clients = set() def check_origin(self, origin): return True def open(self): ChatHandler.clients.add(self) def on_close(self): ChatHandler.clients.remove(self) def on_message(self, message): LoggerFactory.getLogger().info(message) ChatHandler.send_to_all(message) @staticmethod def send_to_all(message): for client in ChatHandler.clients: client.write_message(message) application = tornado.web.Application([ (r"/chat", ChatHandler), ]) if __name__ == "__main__": application.listen(sys.argv[1]) LoggerFactory.getLogger().info("server starting at port: %s" % sys.argv[1]) tornado.ioloop.IOLoop.instance().start()
def on_message(self, message): LoggerFactory.getLogger().info(message) ChatHandler.send_to_all(message)
import argparse import os from datetime import datetime import traceback import time from logger import LoggerFactory from subprocess import Popen import threading from concurrent.futures import ThreadPoolExecutor logger = LoggerFactory() parser = argparse.ArgumentParser(description="This module will create chia plots as defined via params") parser.add_argument("-d1", "--delay1", type=str, required=True, help="Delay of the first phase") parser.add_argument("-d2", "--delay2", type=str, required=True, help="To start new plotting") parser.add_argument("-d", "--distance", type=str, required=False, help="Time between each plot starts") parser.add_argument("-a", "--amount", type=str, required=True, help="Amount of plots Parallel") parser.add_argument("-r", "--cores", type=str, required=False, help="Cores per plot (default: 2)") parser.add_argument("-b", "--ram", type=str, required=False, help="Ram per Plot (default: 3390)") parser.add_argument("-n", "--queued", type=str, required=False, help="Queued Plots (default: 1)") parser.add_argument("-k", "--plot", type=str, required=False, help="Plot (default: 32)") parser.add_argument("-t", "--temporary", type=str, required=True, help="Temporary Devices") parser.add_argument("-f", "--target", type=str, required=True, help="Target Device") parser.add_argument("-m", "--remote", type=bool, required=False, help="Remote Machine") parser.add_argument("-fk", "--farmerkey", type=str, required=False, help="Farmer Key") parser.add_argument("-pk", "--poolkey", type=str, required=False, help="Pool Key") start = datetime.timestamp(datetime.now()) threads = [] args = parser.parse_args() distance = 900 if not args.distance else int(args.distance)
#!/usr/bin/python # -*- coding: utf-8 -*- import tornado.ioloop import tornado.web import os import config import utils from qniu.qiniuApi import QiniuApi from logger import LoggerFactory logger = LoggerFactory.getLogger("miaokan") class UploadFileHandler(tornado.web.RequestHandler): def set_default_headers(self): self.set_header('Access-Control-Allow-Origin', '*') self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') self.set_header('Access-Control-Allow-Headers', '*') def get(self): self.write(config.app_name) def post(self): try: upload_path = os.path.join(os.path.dirname(__file__),config.temp_dir) key = utils.random_str(20) tempfile = os.path.join(upload_path,key) filemeta = self.request.files.get('file')[0] with open(tempfile,'wb') as op: op.write(filemeta.get('body')) self.write(self.__upload(key,tempfile)) except Exception,e: logger.error(e)
import logging from logger import LoggerFactory logger = LoggerFactory.getDefaultLogger() logger = LoggerFactory.getDefaultLogger() logger.setLevel(logging.INFO) #@UndefinedVariable logger.info('Here is info') logger.warning('Here is a warning')
def post(self): info = self.get_argument('info') LoggerFactory.getLogger().info( 'IP:' + self.request.headers.get("X-Real-Ip", '') + ' suggest:' + info) self.write('true')