コード例 #1
0
ファイル: ui.py プロジェクト: XroixHD/MCBE-Win10-FOV-Changer
    def create_notebook(self):
        """ The notebook which contains settings and more is
            Gets execute in createContent
        """
        notebook = ttk.Notebook(self.main_frame, width=600, takefocus=False)
        notebook.grid(column=3, row=1, sticky="WENS", ipadx=0)

        # Create instances
        self.feature_frame = tk.Frame(notebook)
        self.settings_frame = tk.Frame(notebook)
        self.log_frame = tk.Frame(notebook)
        self.info_frame = tk.Frame(notebook)

        # Update to get height
        self.update()

        # Add them before to be then able to calculate the height
        notebook.add(self.feature_frame, text="Features")
        notebook.add(self.settings_frame, text="Settings")
        notebook.add(self.log_frame, text="Log")
        notebook.add(self.info_frame, text="Info")

        # Notebook Features
        # If there are features, render them
        if features := self.storage.features:
            self.create_tab_features(features)
            Logger.log("Rendered Features!")
コード例 #2
0
ファイル: ui.py プロジェクト: XroixHD/MCBE-Win10-FOV-Changer
    def on_settings_save_button(self):
        """ Save settings
        """
        if self.storage.settings.tk_vars:
            settings = self.storage.settings.data

            for name, value in self.storage.settings.tk_vars.items():
                try:
                    # Try to cast
                    value = type(settings[name])(value.get())

                    # Set new value
                    settings[name] = value

                except ValueError:
                    Logger.log(
                        msg :=
                        f"Invalid value for {' '.join(x[0].upper() + x[1:] for x in name.split('_'))}"
                    )
                    queue_alert_message(self.references, msg, warning=True)
                    return

            Logger.log("Saved new settings!")
            queue_alert_message(self.references, "Saved new settings!")

        self.storage.update_file()
コード例 #3
0
    def process(self):
        filepath = os.getcwd() + '/watch/' + self.filename
        if os.path.isfile(filepath):

            print("Muncipality import started")

            conn = pyodbc.connect(
                r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=' +
                filepath)
            cursorAD = conn.cursor()
            cursorAD.execute('SELECT * FROM GEMEENTEN')

            # Create cursor queries
            header = "SET IDENTITY_INSERT muncipality ON " \
                     "INSERT INTO muncipality (muncipality_code, muncipality_name) VALUES "

            cursor = self.db.conn.cursor()
            Logger().errors['Muncipalities'] = dict()
            for row in cursorAD.fetchall():
                query = header + "("
                query += "'" + str(row[0]) + "', "
                query += "'" + row[1] + "'"
                query += ")"

                try:
                    cursor.execute(query)
                except Exception as e:
                    code = e.args[0]
                    if code in Logger().errors['Muncipalities']:
                        Logger().errors['Muncipalities'][code] += 1
                    else:
                        Logger().errors['Muncipalities'][code] = 1

            cursor.commit()
コード例 #4
0
ファイル: flash_dialog.py プロジェクト: zhanggyhz/uPyLoader
    def _flash_finished(self, code):
        Logger.log("Flash output contents:\r\n")
        Logger.log(self._flash_output)

        if code == 0:
            self._flash_output.extend(b"Rebooting from flash mode...\n")
            self._update_output()
            try:
                s = serial.Serial(self._port, 115200)
                s.dtr = False
                s.rts = True
                time.sleep(0.1)
                s.rts = False
                time.sleep(0.1)
                self._flash_output.extend(
                    b"Done, you may now use the device.\n")
                self._update_output()
            except (OSError, serial.SerialException):
                QMessageBox.critical(self, "Flashing Error",
                                     "Failed to reboot into working mode.")

        elif code == -1:
            QMessageBox.critical(
                self, "Flashing Error",
                "Failed to run script.\nCheck that path to python is correct.")
        else:
            QMessageBox.critical(self, "Flashing Error",
                                 "Failed to flash new firmware")
        self.eraseButton.setEnabled(True)
        self.flashButton.setEnabled(True)
        self._flashing = False
コード例 #5
0
    def run(self) -> None:
        """ Start everything because the tray controls most of the components
        """
        try:
            self.tray = ps.Icon(
                "FOV Changer",
                icon=self.icon_image,
                title="FOV Changer",
                menu=ps.Menu(
                    ps.MenuItem("FOV Changer", self.void,
                                enabled=False), ps.Menu.SEPARATOR,
                    ps.MenuItem("Open Window", self.action),
                    ps.MenuItem("Enabled",
                                self.action,
                                checked=lambda item: self.states["Enabled"]),
                    ps.Menu.SEPARATOR, ps.MenuItem("Exit", self.action)))

            # Start GUI
            self.root_thread.start()

            # Start Processing stuff
            self.processing_thread.start()

            # Start tray
            Logger.log("System Tray", add=True)
            self.tray.run()
            Logger.log("System Tray", add=False)

            self.on_shutdown()

        except Exception:
            exceptions.handle_error(self.references)
コード例 #6
0
 def search(query):
     try:
         logging.info(Logger.message('Twitter', f'Searching for {query}'))
         return Twitter.__api.GetSearch(raw_query=query, return_json=True)
         # TODO handle timeouts and limits
     except TwitterError:
         logging.error(Logger.message('Twitter', 'Search failed'))
コード例 #7
0
    def send_mail(self, to, subject, body, attachments=None):
        msg = MIMEMultipart()
        msg['From'] = self.user
        msg['To'] = ', '.join(to)
        msg['Date'] = formatdate(localtime=True)
        msg['Subject'] = subject
        msg.attach(MIMEText(body, 'plain'))

        if attachments is not None:
            for attachment in attachments:
                part = MIMEBase('application', 'octet-stream')
                part.set_payload(attachment[1].read())
                encoders.encode_base64(part)
                part.add_header('Content-Disposition',
                                'attachment; filename = ' + attachment[0])
                msg.attach(part)

        content = msg.as_string()
        try:
            self.server.sendmail(self.user, to, content)
        except Exception as error:
            logger = Logger()
            logger.send(
                f'An Error occurred while sending the mail! ERROR: {error}')
            sys.exit(6)
コード例 #8
0
                def callback():
                    """ End of the start part, own method, so it can be invoked after the creation of features tab
                    """
                    try:
                        # Get addresses
                        self.gateway.get_addresses()

                        # Set up and start listener
                        self.listener = listener.Listener(self.references)
                        self.listener.register_keys()
                        self.listener.start()

                        # Change start and tray button
                        self.references["SystemTray"].states["Enabled"] = True
                        self.references["SystemTray"].tray.update_menu()
                        root.start_button_var.set("■ Stop")

                        # Cooldown, need to copy
                        root.after(self.storage.get("settings")["attach_cooldown"],
                                   (lambda: button.configure(state="active")))
                        root.config(cursor="arrow")

                    except (pymem.exception.ProcessNotFound, pymem.exception.WinAPIError,
                            pymem.exception.CouldNotOpenProcess) as e:
                        Logger.log(f"Minecraft not found! {e}")
                        ui.queue_alert_message(self.references, "Minecraft not found!", warning=True)
コード例 #9
0
ファイル: server.py プロジェクト: watsonthecat/encyclopedia
def search():
    'Route to search'
    if request.method == 'GET':
        term = request.args.get('term')
        services_string = request.args.get('services')
        services = services_string.split(',')
        Logger.log(services)
    else:
        # try and get the term
        term = request.form.get('term', None)
        # try and get the selected services as a list
        services = request.form.getlist('services', None)
    # add the search to the user's profile
    USER_MANAGER.add_search(session['username'], term, services)
    # initialize the api service
    requestor = Requestor()
    # create a blank result
    results = Result()
    # check for each of the available selected service
    if 'Twitter' in services or 'twitter' in services:
        Logger.log('Twitter')
        results.tweets = requestor.search_twitter(term)
    if 'Giphy' in services or 'giphy' in services:
        Logger.log('Giphy')
        results.gifs = requestor.search_giphy(term)
    if 'Wikipedia' in services or 'wikipedia' in services:
        Logger.log('Wikipedia')
        results.articles = requestor.search_wiki(term)
    Logger.log('returning dict of results %s' % results)
    return render_template('home.html', results=results)
コード例 #10
0
    def __init__(self, references: dict, loop):
        """ Initialize
        :param references: (dict) the references
        """
        self.references = references

        try:
            self.rpc = pypresence.Presence(client_id="733376215737434204",
                                           loop=loop)
            self.rpc.connect()

        # Discord not open (or not installed)
        except pypresence.InvalidPipe:
            self.rpc = None

        self.last_server = None
        self.last_time = None

        self.partner_servers = {
            "hivebedrock.network": "The Hive",
            "inpvp.net": "Mineville",
            "mineplex.com": "Mineplex",
            "galaxite.net": "Galaxite",
            "lbsg.net": "Lifeboat",
            "cubecraft.net": "CubeCraft"
        }

        self.feature = None

        # For ui
        self.tk_vars = {}

        # Add to references
        self.references.update({"Discord": self})
        Logger.log("Discord", add=True)
コード例 #11
0
def send_gmail(recipients: Iterable[str],
               subject: str,
               body: str,
               debug: bool = False):
    recipients_string = ", ".join(recipients)
    Logger.log("Sending {:s} to {:s}:\n{:s}".format(subject, recipients_string,
                                                    body))

    if debug:
        return

    user, pwd = get_credentials()

    # Prepare actual message
    #message = """From: %s\nTo: %s\nSubject: %s\n\n%s
    #""" % (user, ", ".join(recipient), subject, body)

    # message = f"From: {user:s}\nTo: {recipients_string:s}\nSubject: {subject:s}\n\n{body:s}"
    message = MIMEText(body, "html")
    message["From"] = user
    message["To"] = recipients_string
    message["Subject"] = subject

    server = smtplib.SMTP("smtp.gmail.com", 587)
    server.ehlo()
    server.starttls()
    server.login(user, pwd)
    server.sendmail(user, recipients, message.as_string())
    server.close()
コード例 #12
0
ファイル: server.py プロジェクト: watsonthecat/encyclopedia
def home():
    '''search form'''
    if check_for_user():
        Logger.log('user logged in, sending to home')
        return render_template('home.html', results=list())
    Logger.log('user not logged in, sending to index')
    return redirect('index.html')
コード例 #13
0
ファイル: database.py プロジェクト: carlhtorres/py-twit
 def __table_hashtags_create():
     try:
         Database.__database.execute('CREATE TABLE hashtags (hashtag text primary key)')
         Database.__database.commit()
         logging.info(Logger.message('Database', 'Created hashtags table'))
     except sqlite3.OperationalError:
         logging.warning(Logger.message('Database', 'Failed to create table hashtag'))
コード例 #14
0
def main():
    conf_path = path.dirname(path.abspath(__file__)) + '/config.json'
    conf = json.load(open(conf_path, 'r'))

    Logger.print_info('Preparing for screen capture...')
    capturing_mgr = CapturingManager(
        display_num=conf['vnc']['number'],
        width=conf['vnc']['width'],
        height=conf['vnc']['height'],
        depth=conf['vnc']['depth'],
        loglevel=conf['ffmpeg']['loglevel'],
        fps=conf['ffmpeg']['record_fps'],
        comp_thre_num=conf['compression']['thread_num'],
        raw_queue_size=conf['compression']['raw_frame_queue'],
        comp_queue_size=conf['compression']['comp_frame_queue'],
        quality=conf['compression']['quality'])
    capturing_mgr.init()

    Logger.print_info('Preparing for server connection...')
    ws_io = WebSocketIO(ip=conf['server']['ip'],
                        port=conf['server']['port'],
                        ws_tag=WS_TAG,
                        ws_id=WS_ID,
                        ws_timeout=WS_TIMEOUT)

    streamer = FrameStreamer(ws_io=ws_io,
                             capturing_mgr=capturing_mgr,
                             width=conf['vnc']['width'],
                             height=conf['vnc']['height'])
    ws_io.open(streamer.on_open)
コード例 #15
0
    def __init__(self, user, data):

        self.logger = Logger(user)

        super().__init__('sessions/' + user,
                         API_ID,
                         API_HASH,
                         update_workers=4)

        self.phone = PHONE

        self.chats = {}

        self.state = State.IDLE

        self.level = 0

        self.exhaust = time.time()

        # Adventure quest location
        self.adventure = None

        # All locations
        self.locations = create_locations()

        self.logger.log('Сеанс {} открыт'.format(user))
コード例 #16
0
    def load_logger(self, verbose):
        if not verbose:
            lg = Logger(level='ERROR')
        else:
            lg = Logger()

        return lg.get()
コード例 #17
0
ファイル: database.py プロジェクト: carlhtorres/py-twit
 def hashtags():
     try:
         dataset = Database.__database.execute('SELECT hashtag FROM hashtags;').fetchall()
         logging.info(Logger.message('Database', 'Selected all hashtags from table'))
         return dataset
     except sqlite3.OperationalError:
         logging.warning(Logger.message('Database', 'Problem querying hashtags'))
コード例 #18
0
ファイル: server.py プロジェクト: watsonthecat/encyclopedia
def signout():
    '''sign the current user out'''
    if check_for_user():
        Logger.log('user logged in, signing out')
        sign_user_out()
    Logger.log('redirecting to index')
    return redirect('/')
コード例 #19
0
    def at_start(self):
        """ Gets called before the loop
        """
        Logger.log("ProcessingThread", add=True)

        # Create basic ui to be able to display events
        self.references["RootThread"].queue.append(
            {"cmd": "create_widgets", "params": [], "kwargs": {}})

        # Initialize storage
        self.storage = storage.Storage(self.references)

        # Initialize network
        self.network = network.Network(self.references)

        # Initialize gateway
        self.gateway = Gateway(self.references)

        # Not initialize listener, because its a thread

        # Initialize discord (rich presence) and event loop
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        self.discord = Discord(self.references, loop=loop)

        # Finish UI content
        self.references["RootThread"].queue.append(
            {"cmd": "create_content", "params": [], "kwargs": {}})
コード例 #20
0
ファイル: server.py プロジェクト: watsonthecat/encyclopedia
def index():
    'Main template route'
    if check_for_user():
        # make sure that we go to home if the user is logged in
        Logger.log('user exists sending home.html')
        return redirect('/home.html')
    Logger.log('user does not exist, returning index.html')
    return render_template('index.html')
コード例 #21
0
ファイル: bot.py プロジェクト: sangmoon/cyworld-bot
    def run(self, parser=2, downloader=2):
        self._logger.info('이미지 다운로드 작업 시작')
        start = time.time()

        # 멀티 프로세싱 처리를 위한 매니저
        with Manager() as manager:
            # 프로세스 목록
            processes = []

            # 공유 메모리 변수
            content_list = manager.list()
            image_list = manager.list()
            count = manager.Value('i', 0)
            lock = manager.Lock()
            feeder_running = manager.Value('i', 1)
            parser_running = manager.Value('i', 1)

            parser_logger = Logger('cybot_parser.log')
            downloader_logger = Logger('cybot_downloader.log')
            main_cookies = self._driver.get_cookies()
            cookie = []

            for c in main_cookies:
                cookie.append({'name': c['name'], 'value': c['value']})

            # 파서 프로세스 생성 및 시작
            for idx in range(parser):
                parser_instance = Parser(self._chromedriver, cookie,
                                         parser_logger, self._delay)
                parser_process = Process(target=parser_instance.parse, \
                    args=(content_list, image_list, feeder_running, parser_running)
                )
                parser_process.name = 'Parser::' + str(idx)
                parser_process.start()
                processes.append(parser_process)
                self._logger.info('Parser', str(idx), '프로세스 시작')

            # 다운로더 프로세스 생성 및 시작
            for idx in range(downloader):
                downloader_instance = Downloader(downloader_logger)
                downloader_process = Process(target=downloader_instance.downloader, \
                    args=(image_list, count, lock, parser_running))
                downloader_process.name = 'Downloader::' + str(idx)
                downloader_process.start()
                processes.append(downloader_process)
                self._logger.info('Downloader', str(idx), '프로세스 시작')

            # 피더 프로세스 시작
            self._logger.info('Feeder 시작')
            self.feeder(content_list, feeder_running)

            # 파서, 다운로더 프로세스가 종료되지않은 경우 대기
            for p in processes:
                p.join()

            self._logger.info('작업 소요시간: {}초'.format(
                round(time.time() - start, 2)))
            self._logger.info('전체 이미지 수: {}'.format(count.value))
コード例 #22
0
 def __init__(self, segments, settings, segment_generator, effects):
     self.segments = segments
     self.settings = settings
     self.breath_pause = segment_generator.generate_breath_pause()
     self.effects = effects
     self.segment_selector = SegmentSelector(segments)
     self.logger = Logger()
     self.result = Result()
     self.init()
コード例 #23
0
 def __init__(self):
     self.api_key = ""
     self.api_secret_key = ""
     self.get_api_key()
     self.api_endpoint = "https://api.liquid.com"
     self.balance = None
     self.connect_timeout = 3.0  # サーバとのコネクトタイムアウト
     self.read_timeout = 10.0  # サーバからの読み込みタイムアウト
     self.logger = Logger()
コード例 #24
0
ファイル: server.py プロジェクト: watsonthecat/encyclopedia
def searches():
    '''get the search history for this user'''
    if check_for_user():
        username = session['username']
        Logger.log(username)
        user = USER_MANAGER.get_user_profile(username)
        Logger.log(user.searches)
        return jsonify(
            searches=list(map(lambda s: s.search_text, user.searches)))
    return jsonify(searches=list())
コード例 #25
0
    def __init__(self, references: dict):
        """ Initialize
        :param references: the references
        """
        self.references = references

        self.storage = references["Storage"]

        # Add to references
        self.references.update({"Network": self})
        Logger.log("Network", add=True)
コード例 #26
0
ファイル: database.py プロジェクト: carlhtorres/py-twit
 def get_tweet(id):
     try:
         tweet = Database.__database.execute(f'SELECT * FROM tweets WHERE id={id}').fetchone()
         if tweet is not None:
             logging.debug(Logger.message('Database', f'Retrieved get_tweet {id} from table'))
             return Database.__tweet_tuple_to_dict(tweet)
         raise ValueError('Invalid ID')
     except sqlite3.OperationalError:
         logging.warning(Logger.message('Database', 'Operational error'))
     except sqlite3.ProgrammingError:
         logging.warning(Logger.message('Database', 'Invalid query'))
コード例 #27
0
ファイル: database.py プロジェクト: carlhtorres/py-twit
 def get_user_top_followers():
     users = []
     try:
         raw = Database.__database.execute('SELECT * FROM users ORDER BY followers DESC').fetchmany(5)
         for user in raw:
             users.append(Database.__user_tuple_to_dict(user))
     except sqlite3.OperationalError:
         logging.warning(Logger.message('Database', 'Operational error'))
     except sqlite3.ProgrammingError:
         logging.warning(Logger.message('Database', 'Invalid query'))
     return users
コード例 #28
0
def init(cam_ip):
    path_to_log_file = base_path_to_log_file + log_file_name_pattern.format(
        cam_ip)

    create_directory_for(path_to_log_file)
    create_directory_for(get_path_to_video_archive(cam_ip))

    Logger.init_logger(write_logs, path_to_log_file, MAX_BYTES_LOG_FILE_SIZE,
                       MAX_LOG_FILES_COUNT)

    CameraSdk.init(DEFAULT_TIMEOUT_SECONDS)
コード例 #29
0
 def add_search(self, username, term, services):
     '''add a search to the user's profile'''
     if username is None or\
     services is None or\
     term is None or\
     len(services) < 1:
         return
     user = self.database.get_user(username)
     if term in list(map(lambda s: s.search_text, user.searches)):
         Logger.log('term already used, not saving')
     else:
         self.database.add_search(UserSearch(None, term, services, user.user_id ))
コード例 #30
0
 def __init__(self, **kwargs):
     self.parameters = kwargs
     self.logger = Logger(**kwargs)
     self.data_loader = DataLoader(**kwargs)
     self.model = GCN(input_dim=self.data_loader.get_input_feat_size(),
                      hidden_dim=kwargs['hidden_dim'],
                      num_classes=self.data_loader.get_num_classes(),
                      dropout_prob=kwargs['dropout_prob'],
                      bias=kwargs['bias'])
     self.optimizer = torch.optim.Adam(params=self.model.parameters(),
                                       lr=kwargs['lr'])
     self.cross_entropy = torch.nn.NLLLoss()
コード例 #31
0
import shutil
import hashlib
import argparse
import exifread
import Image

# some fun to get to the src dir
this_file = os.path.realpath(__file__)
this_dir = os.path.dirname(this_file)
sys.path.append(os.path.realpath(os.path.join(this_dir, "..", "wsgi")))
from src.database import *
from src.model import Photo
from src.logger import Logger as L
import src.util
from src.settings import Settings as S
L.init(sys.stderr, L.WARNING)

WORKING_BASE_DIR = "."
DEST_BASE_DIR = "/home/josh/Dropbox/Photos"
WRITE = True
SUPPORTED_IMG_EXTENSIONS = [
	"jpeg",
	"jpg",
	#"mov",
	#"avi",
	"bmp",
	"png",
	"gif",
	"tiff",
	#"mp4",
	#"nef"