Exemplo n.º 1
0
def set_song_info(file_name, user, path='.'):
    try:
        song = eyed3.load(path + '/downloads/' + file_name + '.mp3')
        song_artist, song_title = file_name.split(' - ')
        song.tag.artist = song_artist
        # song.tag.album = "Free For All Comp LP"
        if song.tag.album_artist is None:
            song.tag.album_artist = song_artist
        song.tag.title = song_title
        # song.tag.track_num = 3
        song.tag.save()
        Logging('Complete changing of description of song: "{0}"'.format(file_name), user.logfile)
    except Exception as err:
        Logging("[ERROR] (Can't change song description) " + str(err), user.logfile)
Exemplo n.º 2
0
def download_song(infofile_name, user, path='.'):
    # function to download song by filename (data file), user (session) and path (song will save in this place)
    Logging('Try to download song: "{0}". Getting url'.format(
        infofile_name), user.logfile)
    with open('./data/{0}/Normal_Songs/{1}.json'.format(user.user_id, infofile_name), 'r') as info:
        song = json.load(info)
    Logging('Start download: "{0}"'.format(infofile_name), user.logfile)
    r = requests.get(song["url"])
    if not os.path.exists(path + '/downloads'):
        os.mkdir(path + '/downloads')
    if r.status_code == 200:
        with open(path + '/downloads/{0} - {1}.mp3'.format(song["artist"], song["title"]), 'wb') as song_mp3:
            song_mp3.write(r.content)
            Logging('Download complete successfull. Starting description changing', user.logfile)
            set_song_info(infofile_name, user, path)
Exemplo n.º 3
0
 def __init__(self, user, log=None):
     self.safeid = user.safeid
     self.req = user.req
     if log is None:
         self.log = Logging(user.username)
     else:
         self.log = log
Exemplo n.º 4
0
 def authorization(self):
     login = self.inputLogin.text()
     password = self.inputPassword.text()
     try:
         self.user = auth.auth(login, password, True)
         self.user.session_start()
         Logging('Load main GUI', self.user.logfile)
         self.mainroot = mainroot.Root(self.user)
         self.mainroot.show()
         self.mainroot.get_all_songs()
         Logging('Main file loading complete', self.user.logfile)
         self.close()
     except Exception as err:
         self.errors.setText(str(err))
         self.errors.setFont(QFont('Arial', 12))
         self.errors.setStyleSheet("color: rgb(255, 0, 0)")
Exemplo n.º 5
0
	def __init__(self, user, useType, sellType, log = None):
		self.safeid = user.safeid
		self.req = user.req
		self.useType = useType
		self.sellType = sellType
		if log is None:
			self.log = Logging(user.username)
		else:
			self.log = log
Exemplo n.º 6
0
 def download(self):
     counter = 0
     counter_broak = 0
     max_counter = len(self.to_download)
     self.progress.setMinimum(counter)
     self.progress.setMaximum(max_counter)
     for i in self.to_download:
         try:
             music.download_song(i, self.user, self.path)
             counter += 1
         except OSError:
             Logging("Can't download song: {0}".format(i[:-5:]),
                     self.user.logfile)
             counter_broak += 1
         self.progress.setValue(counter)
     self.progress.reset()
     text_info = '''Complete downloading. Total: {0}. Successful: {1}. Broak: {2}'''.format(
         max_counter, counter, counter_broak)
     Logging(text_info, self.user.logfile)
Exemplo n.º 7
0
 def __init__(self, username, password, log=None):
     self.loginStatus = False
     self._safeid = None
     self.username = username
     self.password = password
     self.req = KfReq()
     if log is None:
         self.log = Logging(username)
     else:
         self.log = log
Exemplo n.º 8
0
def get_songs_info(user):
    '''
    This function get all info about user music
    It put its into JSON-files (data files)
    If song has bad-decoding name or author (not-unicode), its put
    it in folder "Bad_Songs" with song ID as name
    Else its put it in folder "Normal_Songs" (Name = 'Author' - 'Title')
    '''
    if not os.path.exists('./data/{0}'.format(user.user_id)):
        os.makedirs('./data/{0}'.format(user.user_id))
    with open('./data/{0}/vk_audio_list.txt'.format(user.user_id), 'w') as f:
        bad_songs = 0
        Logging('Looking for a user songs. It may take time if you have a lot of music', user.logfile)
        songs = user.music.get(owner_id=user.user_id)
        Logging('Find {0} songs. Trying get info about it'.format(
            len(songs)), user.logfile)
        counter = 0
        for i in songs:
            counter += 1
            try:
                f.write(i["artist"] + ' - ' + i["title"] + '\n')
                if not os.path.exists('./data/{0}/Normal_Songs'.format(user.user_id)):
                    os.makedirs('./data/{0}/Normal_Songs'.format(user.user_id))
                normal_song = make_name_normal(
                    str(i['artist'] + ' - ' + i['title']))
                with open('./data/{0}/Normal_Songs/'.format(user.user_id) + normal_song + '.json', 'w') as good_file:
                    json.dump(i, good_file, indent=2, ensure_ascii=False)
                Logging('Get info about {0}/{1} songs. Current song: "{2} - {3}"'.format(
                    counter, len(songs), i["artist"], i["title"]), user.logfile)
            except UnicodeEncodeError:
                bad_songs += 1
                if not os.path.exists('./data/{0}/Broken_Songs'.format(user.user_id)):
                    os.makedirs('./data/{0}/Broken_Songs'.format(user.user_id))
                with open('./data/{0}/Broken_Songs/'.format(user.user_id) + str(i['id']) + '.json', 'w') as bad_file:
                    json.dump(i, bad_file, indent=2, ensure_ascii=True)
                Logging('[WARNING]Get info about {0}/{1} songs. Bad decoding name error'.format(
                    counter, len(songs)), user.logfile)
        if bad_songs:
            f.write("\nCan't write songs(bad name decoding): " + str(bad_songs))
    Logging('Songs info received', user.logfile)
Exemplo n.º 9
0
def create_app(config):
    """AUTH app factory method."""
    app = Flask(__name__)
    app.config.from_object(config)
    app.config.from_envvar("CONFIG_ENV", silent=True)
    db = SQLAlchemy(app)
    Session(app)
    Autodoc(app)
    handler = RotatingFileHandler(app.config.get('FLASK_LOG_PATH', "{0}/{1}". \
            format(os.path.abspath(os.path.dirname(__file__)), "authapp.log")), maxBytes=1024 * 1024 * 10, backupCount=13)
    app.config.setdefault('LOG_NAME', 'authapp')
    Logging(app, handler)
    return app, AppBuilder(app, db.session, security_manager_class=security_manager.SecurityManager, \
                            update_perms=app.config['AUTO_UPDATE_PERM'], indexview=security_manager.IndexView)
Exemplo n.º 10
0
 def session_start(self):
     self.session = vk_api.VkApi(login=self.login,
                                 password=self.password,
                                 auth_handler=two_factor_auth_handler,
                                 captcha_handler=captcha_handler,
                                 config_filename='vk_config.json')
     clear_last_log()
     self.set_logfile_name()
     Logging("Trying to start session", self.logfile)
     self.session.auth()
     Logging("Session started", self.logfile)
     Logging("Getting music api", self.logfile)
     self.api = self.session.get_api()
     self.music = audio.VkAudio(self.session)
     Logging("Complete successfully", self.logfile)
     self.get_id()
     with open('user.json', 'w') as f:
         user_data = {
             'login': self.login,
             'password': tools.encode(self.password)
         }
         json.dump(user_data, f, indent=2, ensure_ascii=False)
     return (self)
Exemplo n.º 11
0
    def __init__(self):
        super(DataCollectUI, self).__init__()
        self.setupUi(self)

        # sqlite
        self.sqlite = SqlLiteManage()

        # 日志
        self.logger = Logging()

        # 摄像头
        self.capture = cv2.VideoCapture()

        # 定时器
        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.update_frame)

        # 当前人脸ID
        self.faceID = 0

        # 是否进行人脸采集
        self.isCollect = False
        self.isContinueCollect = False

        # 是否打开摄像头
        self.isOpenCapture = False

        # 自定义参数
        self.count = 0  # 人脸采集计数
        self.MaxCount = 50  # 采集人脸数量
        self.scale_factor = 1.1  # 数值越大计算越快,太快会丢失人脸
        self.minNeighbors = 3  # 控制着误检测

        # 预处理选择
        self.isGaussianBlur = False  # 高斯
        self.isBlur = False  # 均值
        self.isMedianBlur = False  # 中值
        self.isEqualizeHist = False  # 直方图均衡

        # 级联分类器
        self.face_detector = cv2.CascadeClassifier(
            "E:\Opencv\opencv-master\data\haarcascades\haarcascade_frontalface_default.xml"
        )

        # 人脸数量
        self.max_face_count = 1
Exemplo n.º 12
0
 def __init__(self,
              username,
              password,
              openBoxType=[True, True, True, True],
              smeltEquipType=[True, True, True, False],
              useItemType=[True, True, True, True, True, True],
              sellItemType=[True, True, True, True, True, True],
              buyExp=True,
              log=None):
     self.username = username
     self.password = password
     self.openBoxType = openBoxType
     self.smeltEquipType = smeltEquipType
     self.useItemType = useItemType
     self.sellItemType = sellItemType
     if log is None or len(logfilePath) == 0:
         self.log = Logging(self.username)
     else:
         self.log = log
     self.buyExp = buyExp
     self.statistic = {"username": self.username}
Exemplo n.º 13
0
from log import Logging
import ConfigParser
import importlib
from os import walk
import printer
import re
import utilities
log = Logging()
uf = utilities.Utilities()


class Controller(object):
    def __init__(self):
        self.reloadClasses = False
        self.Printer = printer.Printer()  #Controller has a Printer

    def start(self):
        log.header(
            " _____      _       ____      _            ___     ___      ___  ",
            False)
        log.header(
            "|  __ \    | |     |___ \    | |          / _ \   |__ \    / _ \ ",
            False)
        log.header(
            "| |__) |___| |_ _ __ __) | __| |  __   __| | | |     ) |  | | | |",
            False)
        log.header(
            "|  _  // _ \ __| '__|__ < / _` |  \ \ / /| | | |    / /   | | | |",
            False)
        log.header(
            "| | \ \  __/ |_| |  ___) | (_| |   \ V / | |_| |_  / /_  _| |_| |",
Exemplo n.º 14
0
from cloudprovider import CloudProvider
import cloudfiles
import cloudfiles.errors
from log import Logging
_log = Logging().log


class Swift(CloudProvider):
    def __init__(self,
                 username=None,
                 api_key=None,
                 timeout=5,
                 servicenet=False,
                 useragent='com.whmcr.cloudsync',
                 auth_url=cloudfiles.uk_authurl):
        """
        Accepts keyword args for Swift Username and API Key

        @type username: str
        @param username: Swift Username
        @type api_key: str
        @param api_key: Swift API Key
        @type servicenet: bool
        @param servicenet: Use Service net - Rackspace Cloud files specific
        @type user_agent: str
        @param user_agent: A user agent string used for all requests
        @type timeout: int
        @param timeout: Timeout value in seconds for a request
        """
        self.connection_pool = None
        self.username = username
Exemplo n.º 15
0
import sys
sys.path.insert(0, "./libs")
sys.path.insert(1, "./libs/gui")
import login
from log import Logging
from PyQt5.QtWidgets import *
from PyQt5.QtCore import pyqtRemoveInputHook
from logging import getLogger
getLogger().setLevel('ERROR')
pyqtRemoveInputHook()

try:
    app = QApplication(sys.argv)
    ui = login.Log_root()
    ui.show()
    sys.exit(app.exec_())
except KeyboardInterrupt:
    Logging("Stop programm by yourself", user.logfile)
    raise SystemExit
except Exception as err:
    Logging('[ERROR]' + str(err), user.logfile)
    raise SystemExit
Exemplo n.º 16
0
from log import Logging
from tools import GlobalMap as Gl
from manager.communication import Image
from manager.communication import Container
from manager.communication import System
from etc.sys_set import WEB_RESPONSE_HOST, WEB_RESPONSE_PORT

app = Flask(__name__)
# 镜像操作实例
_image = Image()
# 容器操作实例
_container = Container()
# 系统信息获取实例
_system = System()
# 日志操作实例
_logger = Logging('web_flask')
_logger.set_file('web_flask.txt')


@app.route('/')
def hello_world():
    return 'Hello World!'


def get_node_num(cluster_id):
    """  获取指定集群的节点个数

    :param cluster_id: 集群IP
    :return: 集群个数(int)
    """
    return Gl.get_value('CLUSTER_ALL_INFO_VAR',
Exemplo n.º 17
0
            ["ec.txt", "0", "gwy"],
                hierarchy="sub",
                subfolder_name="_data",
        ):
            l.log_p(10, ">>> No data files were not moved.")
        if not multiple_move(
                proc_dir, src_dir, ["png"], hierarchy="sub",
                subfolder_name="_png"):
            l.log_p(10, ">>> No images files were not moved.")
        if not multiple_move(proc_dir, src_dir, ["html"], hierarchy="parent"):
            l.log_p(10, ">>> No HTML report was moved.")
    elif prep.check_network_file(src_dir[0]):
        l.log_p(9, ">>> Move data and remove temporary folder")
        multiple_move(proc_dir, src_dir, ["png", "0", "ec.txt", "html"])

    l.log_p(0, ">>>                  DONE                   <<<")


if __name__ == "__main__":
    temp = tempfile.mkdtemp(prefix="python_", suffix="_temp")
    l = Logging()

    try:
        src, fs, labj = prompt()
        pdir, proc = prepare(src, fs, temp)
        main(src, pdir, proc, labj)
        cleanup(src, pdir)
        l.save_log(src, config.log_f_name)
    finally:
        shutil.rmtree(temp)
Exemplo n.º 18
0
 def __init__(self):
     self.mail_host = 'smtp.qq.com'
     self.mail_pass = ''  # 授权码
     self.sender = ''  # 发送人
     self.receiver, self.sender_name, self.receiver_name = self.read_conf()
     self.logger = Logging()
Exemplo n.º 19
0
You should have received a copy of the GNU General Public License
along with aclh.  If not, see <http://www.gnu.org/licenses/>.
"""

import os
import sys
import time
import argparse
from urllib.parse import urlparse
from vinanti import Vinanti
from log import Logging
from bs4 import BeautifulSoup
from functools import partial

logger = Logging(__name__)


class ACLH:
    def __init__(self, args_list):
        self.args_list = args_list
        self.method_list = [
            'get', 'post', 'put', 'head', 'patch', 'delete', 'options', 'crawl'
        ]
        self.parser = argparse.ArgumentParser(
            description='Asynchronous Command-Line HTTP Client')
        self.__add_arguments__()

    def __get_page__(self, *args):
        result = args[-1]
        url = args[-2]
Exemplo n.º 20
0
import yaml
from key_generator import KeyGenerating

from log import Logging

HOME_KEY_DIR = "/home/yauheni/PyCharmProjects/student/security/RSA/key_capacity"

logger = Logging(name=__name__).get_logger()


class RSA:
    def __init__(self):
        self.q = None
        self.p = None
        self.n = None
        self.e = None
        self.public_exponent = None
        self.private_exponent = None

        self.key_gen = KeyGenerating()

    @staticmethod
    def euclid_checker(number_1: int, number_2: int) -> int:
        while number_1 != 0:
            number_1, number_2 = number_2 % number_1, number_1
        return number_2

    @staticmethod
    def save_key(key: list, file_name: str) -> None:
        with open('{}/{}'.format(HOME_KEY_DIR, file_name), 'w') as file:
            yaml.dump({'key': key}, file, default_flow_style=False, sort_keys=False)
 def __init__(self):
     super(EmailUI, self).__init__()
     self.setupUi(self)
     self.logger = Logging()
     self.read_email_conf()
Exemplo n.º 22
0
    def an_packet(self):
        _ip = self.__get_netcard()
        _mysql_packet_op = mysql_packet(**dict({'_type':self._type},**{'_ip':_ip}))
        session_status = {}
        while 1:
            if not self.queue.empty():
                buf,_cur_time = self.queue.get()
                eth = dpkt.ethernet.Ethernet(buf)

                if not isinstance(eth.data, dpkt.ip.IP):
                    Logging(msg='Non IP Packet type not supported %s\n' % eth.data.__class__.__name__,level='error')
                    continue

                ip = eth.data
                tcp = dpkt.tcp.TCP(str(ip.data))
                if (tcp.dport == self.kwargs['port'] or tcp.sport == self.kwargs['port']) and len(tcp.data) > 0 \
                        and 'interface' not in tcp.data and 'tbl_sessions' not in tcp.data:
                    if len(tcp.data) > 5:
                        session, packet_response, client_packet_text, packet_header, packet_seq_id,response_type,response_status=_mysql_packet_op.Unpacking(
                                                                                data=tcp.data,srchost=self.inet_to_str(ip.src),
                                                        srcport=tcp.sport,dsthost=self.inet_to_str(ip.dst),dstport=tcp.dport)
                    else:
                        continue

                    if client_packet_text:
                        session_status[session] = {'start_time':_cur_time,'request_text':client_packet_text,
                                                   'request_header':packet_header,'seq_id':packet_seq_id,'response_type':response_type}
                        if packet_header == 0x16:
                            session_status[session]['com_pre'] = True
                        elif packet_header == 0x17 and 'com_pre' in session_status[session]:
                            del session_status[session]['com_pre']
                    elif packet_response:
                        if session in session_status and packet_response in session_status[session]['response_type']:
                            if packet_seq_id - 1 == session_status[session]['seq_id'] and 'com_pre' not in session_status[session]:
                                session_status[session]['end_time'] = _cur_time
                                session_status[session]['status'] = self.check_packet_type(packet_response)
                                session_status[session]['response_status'] = response_status

                del_session = []
                for session in session_status:
                    if 'status' in session_status[session]:
                        execute_time = float('%.5f' % (session_status[session]['end_time'] - session_status[session]['start_time']))
                        if session_status[session]['request_header'] == 0x03:
                            sql, values = self.sql_parser(session_status[session]['request_text'])
                        else:
                            sql, values = session_status[session]['request_text'],None
                        _session = eval(session)

                        Logging(msg=
                            'source_host: {} source_port: {} destination_host: {} destination_port: {} sql: {} values: {} '
                            'execute_time:{}  status:{}'.format(_session[0], _session[1], _session[2],_session[3],
                                                                sql, values,
                                                                execute_time,
                                                                session_status[session]['response_status']),level='info')
                        del_session.append(session)

                for session in del_session:
                    del session_status[session]

            else:
                time.sleep(0.01)
Exemplo n.º 23
0
def main():
    data_config_file = 'data_config.json'
    email_config_file = 'email_config.json'
    stored_posts_file = 'stored_posts.json'
    log_file = datetime.now().strftime('%Y-%m-%dT%H:%M:%S%z') + '.log'

    global Log
    Log = Logging(log_file)

    data_config = LoadJson(data_config_file)
    email_config = LoadJson(email_config_file)

    if int(data_config['logging_enabled']):
        Log.start()

    cl_listings = []

    if not IsEmpty(stored_posts_file):
        sp = LoadJson(stored_posts_file)
        [cl_listings.append(CL_Post(stored_post)) for stored_post in sp]
        Log.log('Imported ' + str(len(cl_listings)) + ' saved posts')

    socket.setdefaulttimeout(10)

    threads_required = 0
    for _ in data_config['locations']:
        for __ in data_config['categories']:
            threads_required += 1

    threads = [None] * threads_required
    results = [None] * threads_required

    index = 0
    for location in data_config['locations']:
        for category in data_config['categories']:
            threads[index] = Thread(target=PullFeeds, args=(location, category, results, index))
            threads[index].start()
            index += 1

    [threads[i].join() for i in range(threads_required)]
    [ParseFeed(feed, data_config, cl_listings) for feed in results]

    if len(cl_listings) > 0:
        if CheckNotityInterval(data_config['notification_intervals']):
            email = CL_Email(email_config)
            email.write(cl_listings)
            email.send()
            Log.log('Email sent to ' + str(email.recipient))

            if not IsEmpty(stored_posts_file):
                MakeEmpty(stored_posts_file)
                Log.log('Emptied contents of ' + str(stored_posts_file))
        else:
            Log.log('Storing posts to ' + str(stored_posts_file))
            WriteJson(stored_posts_file, cl_listings)
            Log.log('Successful write to ' + str(stored_posts_file))
    else:
        Log.log('No new posts detected')

    data_config['notification_intervals'] = UpdateIntervals(data_config['notification_intervals'])
    WriteJson(data_config_file, data_config)
    Log.log('Updated contents of ' + str(data_config_file))