Ejemplo n.º 1
0
    async def on_ready(self):
        try:
            win_unicode_console.enable()
        except:
            0

        await self.change_status(game=discord.Game(name='with Eruru\'s tail'))

        print('Connected!\n')
        print('Username: %s' % self.user.name)
        print('Bot ID: %s' % self.user.id)
        print()

        print('Command prefix is %s'% self.config.command_prefix)
        print()

        print('--Connected Servers List--')
        if self.servers:
            [print(s) for s in self.servers]
        else:
            print('No servers have been joined yet.')
        print()
        
        print('--Users Registered--')
        if len(self.users) > 0:
            for user in self.users:
                print(user.id + ' - ' + user.kissUrl)
        else:
            print('No users have registered yet.')
        print()
        
        print('--Log--')
        handler = getattr(self, 'event_loop', None)
        await handler()
Ejemplo n.º 2
0
    def enable_win_unicode_console(self):
        if sys.version_info >= (3, 6):
            # Since PEP 528, Python uses the unicode APIs for the Windows
            # console by default, so WUC shouldn't be needed.
            return

        import win_unicode_console

        if PY3:
            win_unicode_console.enable()
        else:
            # https://github.com/ipython/ipython/issues/9768
            from win_unicode_console.streams import (TextStreamWrapper,
                                 stdout_text_transcoded, stderr_text_transcoded)

            class LenientStrStreamWrapper(TextStreamWrapper):
                def write(self, s):
                    if isinstance(s, bytes):
                        s = s.decode(self.encoding, 'replace')

                    self.base.write(s)

            stdout_text_str = LenientStrStreamWrapper(stdout_text_transcoded)
            stderr_text_str = LenientStrStreamWrapper(stderr_text_transcoded)

            win_unicode_console.enable(stdout=stdout_text_str,
                                       stderr=stderr_text_str)
    def enable_win_unicode_console(self):
        if sys.version_info >= (3, 6):
            # Since PEP 528, Python uses the unicode APIs for the Windows
            # console by default, so WUC shouldn't be needed.
            return

        import win_unicode_console
        win_unicode_console.enable()
Ejemplo n.º 4
0
def setup_win_unicode_console(enable):
    """"Enables or disables unicode display on windows."""
    enable = to_bool(enable)
    if ON_WINDOWS and win_unicode_console:
        if enable:
            win_unicode_console.enable()
        else:
            win_unicode_console.disable()
    return enable
Ejemplo n.º 5
0
    async def on_ready(self):
        win_unicode_console.enable()

        print('Connected!\n')
        print('Username: '******'ID: ' + self.user.id)
        print('--Server List--')

        for server in self.servers:
            print(server.name)

        print()
def main(argv):
    # parse config file
    configfile = './config.cfg'
    if len(argv) == 2:
        configfile = argv[1]
    config = parse_config(configfile)

    win_unicode_console.enable()
    result = check_update(config)
    win_unicode_console.disable()

    return result
Ejemplo n.º 7
0
def setup_win_unicode_console(enable):
    """"Enables or disables unicode display on windows."""
    try:
        import win_unicode_console
    except ImportError:
        win_unicode_console = False
    enable = to_bool(enable)
    if ON_WINDOWS and win_unicode_console:
        if enable:
            win_unicode_console.enable()
        else:
            win_unicode_console.disable()
    return enable
Ejemplo n.º 8
0
def main():
    try:
        if os.name == 'nt':
            import win_unicode_console
            win_unicode_console.enable()
        fmt = '%(name)-20s%(lineno)-3s %(funcName)-17s: %(message)s'.format()
        logging.basicConfig(format=fmt, level=logging.INFO)
        functionName, args = simple_parse_args(sys.argv)
        functionObject = get_function_from_name(functionName)
        log.info("%s(%s) ...", functionObject.__name__, ", ".join(args))
        functionObject(*args)
        return 0
    except KeyboardInterrupt:
        print("\n... bye!")
Ejemplo n.º 9
0
    def init_io(self):
        if sys.platform not in {'win32', 'cli'}:
            return

        import win_unicode_console
        import colorama

        win_unicode_console.enable()
        colorama.init()

        # For some reason we make these wrappers around stdout/stderr.
        # For now, we need to reset them so all output gets coloured.
        # https://github.com/ipython/ipython/issues/8669
        from IPython.utils import io
        io.stdout = io.IOStream(sys.stdout)
        io.stderr = io.IOStream(sys.stderr)
Ejemplo n.º 10
0
def run():
    """ Run as CLI command """

    try:
        import win_unicode_console
        win_unicode_console.enable(use_unicode_argv=True)
    except ImportError:
        pass

    try:
        import colorama
        colorama.init()
    except ImportError:
        pass

    import warnings
    warnings.simplefilter("ignore")

    sys.exit(main())
Ejemplo n.º 11
0
def set_colors():
	global G, Y, B, R, W , M , C , end ,Bold,underline
	if os.name=="nt":
		try:
			import win_unicode_console , colorama
			win_unicode_console.enable()
			colorama.init()
			#green - yellow - blue - red - white - magenta - cyan - reset
			G,Y,B,R,W,M,C,end= '\033[92m','\033[93m','\033[94m','\033[91m','\x1b[37m','\x1b[35m','\x1b[36m','\033[0m'
			Bold = "\033[1m"
			underline = "\033[4m"
		except:
			G = Y = B = R = W = G = Y = B = R = Bold = underline = ''
	else:
		#import colorama
		#colorama.init()
		#green - yellow - blue - red - white - magenta - cyan - reset
		G,Y,B,R,W,M,C,end= '\033[92m','\033[93m','\033[94m','\033[91m','\x1b[37m','\x1b[35m','\x1b[36m','\033[0m'
		Bold = "\033[1m"
		underline = "\033[4m"
Ejemplo n.º 12
0
    def enable_win_unicode_console(self):
        import win_unicode_console

        if PY3:
            win_unicode_console.enable()
        else:
            # https://github.com/ipython/ipython/issues/9768
            from win_unicode_console.streams import (TextStreamWrapper,
                                 stdout_text_transcoded, stderr_text_transcoded)

            class LenientStrStreamWrapper(TextStreamWrapper):
                def write(self, s):
                    if isinstance(s, bytes):
                        s = s.decode(self.encoding, 'replace')

                    self.base.write(s)

            stdout_text_str = LenientStrStreamWrapper(stdout_text_transcoded)
            stderr_text_str = LenientStrStreamWrapper(stderr_text_transcoded)

            win_unicode_console.enable(stdout=stdout_text_str,
                                       stderr=stderr_text_str)
Ejemplo n.º 13
0
    async def on_ready(self):
        win_unicode_console.enable()

        print('Connected!\n')
        print('Username: %s' % self.user.name)
        print('Bot ID: %s' % self.user.id)
        print('Owner ID: %s' % self.config.owner_id)
        print()

        print("Command prefix is %s" % self.config.command_prefix)
        # print("Days active required to use commands is %s" % self.config.days_active) # NYI
        print("Skip threshold at %s votes or %g%%" % (self.config.skips_required, self.config.skip_ratio_required*100))
        print("Whitelist check is %s" % ['disabled', 'enabled'][self.config.white_list_check])
        print("Now Playing message @mentions are %s" % ['disabled', 'enabled'][self.config.now_playing_mentions])
        print("Autosummon is %s" % ['disabled', 'enabled'][self.config.auto_summon])
        print("Auto-playlist is %s" % ['disabled', 'enabled'][self.config.auto_playlist])
        print()

        if self.servers:
            print('--Server List--')
            [print(s) for s in self.servers]
        else:
            print("No servers have been joined yet.")

        print()

        if self.config.owner_id == self.user.id:
            print(
                "[Notice] You have either set the OwnerID config option to the bot's id instead "
                "of yours, or you've used your own credentials to log the bot in instead of the "
                "bot's account (the bot needs its own account to work properly).")

        # maybe option to leave the ownerid blank and generate a random command for the owner to use

        if self.config.auto_summon:
            as_ok = await self._auto_summon()

            if self.config.auto_playlist and as_ok:
                await self.on_finished_playing(await self.get_player(self._get_owner_voice_channel()))
Ejemplo n.º 14
0
import tensorflow as tf
import matplotlib.pyplot as plt
import matplotlib.image as img
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data
import os
from sys import platform

#some things are different depending on windows vs mac
if platform == "win32":
    import win_unicode_console as wc
    wc.enable()
    clear = lambda: os.system('cls')
else:
    clear = lambda: os.system('clear')
mnist = input_data.read_data_sets('tmp/data/', one_hot=True)

n_classes = 10
batch_size = 100

# placeholder variables for x and y (in and out)
x_ = tf.placeholder(tf.float32, shape=[None, 784])
y_ = tf.placeholder(tf.float32)
p_ = tf.placeholder_with_default(0.0, shape=())

#parameters for dropout
drop_rate = 0.5


def conv_model():
    #input layer
Ejemplo n.º 15
0
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
# pylint: disable=redefined-variable-type

try:
    import win_unicode_console
    win_unicode_console.enable(use_unicode_argv=True)
except ImportError:
    pass

import logging
import sys
import time

from contextlib import ExitStack, suppress

from path import Path
from volapi import Room, listen_many

from .constants import ADMINFAG, PARROTFAG
from ._version import __fulltitle__, __version__
from .arb import ARBITRATOR
Ejemplo n.º 16
0
#!/usr/bin/python
import argparse, codecs, colorama, os, requests, urllib, sysfrom bs4 import BeautifulSoupfrom mako.template import Template
if sys.platform == 'win32': import win_unicode_console	win_unicode_console.enable()
colorama.init()
import readline
try:	readline.read_history_file(os.path.expanduser('~/.wash.history'))except IOError: pass
buffer = []
def write_html(fp):	template = Template('''<!doctype html><html>	<head>		<meta charset="utf-8"/>		<title>W|ASH Workbook</title>		<link href='https://fonts.googleapis.com/css?family=PT+Sans+Caption:400,700' rel='stylesheet' type='text/css'>		<link href='http://fonts.googleapis.com/css?family=Anonymous+Pro' rel='stylesheet' type='text/css'>		<style>		body {			background-color: #E4E9EB;			font-family: 'PT Sans Caption', sans-serif;			margin-left: 60px;			margin-right: 60px;		}		h1 {			color: #004B63;			margin-left: -40px;		}		article {			margin-top: 2em;			margin-bottom: 1em;		}		h2 {			margin-bottom: 1em;		}		h3 {			background-color: #def;			margin-top: 0;			margin-bottom: 0;			padding-left: 10px;			padding-right: 10px;			padding-top: 1.5px;			padding-bottom: 1.5px;			font-size: 1.02em;			border: 1px solid #69a;			border-collapse: collapse;		}		pre {			font-family: 'Anonymous Pro', serif;			background-color: white;			padding-top: .75em;			padding-bottom: .6em;			padding-left: 10px;			padding-right: 10px;			margin-top: 0;			margin-bottom: 0;			border-left: 1px solid #9ac;			border-right: 1px solid #9ac;			border-collapse: collapse;			white-space: pre-wrap;		}		article > h3:nth-of-type(1) {			border-top-left-radius: 4px;			border-top-right-radius: 4px;		}		article > *:last-child {			border-bottom: 1px solid #69a;			border-bottom-left-radius: 4px;			border-bottom-right-radius: 4px;		}		a {			color: #004B63;			text-decoration: none;			border-bottom: 1px dashed black;		}		a:hover {			border-bottom: 1px solid black;		}		</style>	</head>	<body>		<h1>W|ASH Workbook</h1> % for query, pods in data:			<article class="query">				<h2><a href="http://www.wolframalpha.com/input/?i=${quote(query.encode('utf-8'))}">${query}</a></h2> % for name, texts in pods:					<h3>${name}</h3> % for text in texts:						<pre>${indent(text, prefix='')}</pre> % endfor % endfor			</article> % endfor	</body></html>''')	fp.write(template.render(data=buffer, quote=urllib.quote, indent=indent))
def write_markdown(fp):	template = Template('''W|ASH Workbook==============% for query, pods in data:${query}${'-' * len(query)} % for name, texts in pods:${'###'} ${name} % for text in texts:${indent(text)} % endfor % endfor% endfor''')	fp.write(template.render(data=buffer, indent=indent))
def indent(text, prefix=' '):	lines = text.split('\n')	initial = min(len(line) - len(line.lstrip()) for line in lines) return '\n'.join(prefix + x[initial:].rstrip() for x in lines)
def clean(text):	text = text.replace(u'\uf7d9', '=') return text
url = 'http://api.wolframalpha.com/v2/query'def wa_query(query):	xml = requests.get(url, params=dict(input=query, appid=appid, format='plaintext')).content if args.verbose: print xml return BeautifulSoup(xml, 'html.parser')
def main(): global appid, args	parser = argparse.ArgumentParser(description='Wolfram|Alpha interactive shell')	parser.add_argument('-v', '--verbose', action='store_true', help='Output XML for each response')
	args = parser.parse_args()
	fn = os.path.expanduser('~/.wash.appid') try:		appid = file(fn).read()		first_run = False except:		first_run = True print '\033[93m-- No Wolfram|Alpha app ID' print 'If you do not already have one, go to:' print '  https://developer.wolframalpha.com/portal/apisignup.html\033[0m' while True:			appid = raw_input('Please enter your app ID: ').strip()			bs = wa_query('Cody Brocious') print '\033[93mVerifying App ID...' if bs.queryresult['success'] == 'true' and bs.queryresult['error'] == 'false': print '\033[92mApp ID is correct\033[0m' with file(fn, 'w') as fp:					fp.write(appid) break else: print '\033[91mApp ID is invalid\033[0m'
 if first_run: print print '\033[92mWelcome to W|ASH\033[0m' print '\033[93mTo get started, simply type a query here as if you are on the Wolfram|Alpha site.' print 'For instance, try this: the 15th prime number * 20\033[0m' print
	result = None
 while True: try:			query = raw_input('W|A> ').strip() except EOFError: print break except KeyboardInterrupt: print continue		readline.write_history_file(os.path.expanduser('~/.wash.history')) if query == '': continue elif query == 'quit' or query == 'exit': print '\033[91mTo quit W|ASH, press Ctrl-D\033[0m' continue elif query == 'help': print '\033[1m\033[92mW|ASH Help\033[0m' print '\033[93m - Type a query to send it to Wolfram|Alpha' print ' - $$ in a query will be replaced by the previous result' print ' - save <filename> will save the current buffer to a file as HTML or Markdown' print '   - To save HTML, simply add .html to the filename' print ' - Ctrl-D to quit\033[0m' print continue elif query.startswith('save '):			fn = query[5:].strip() print '\033[92mSaving to', fn, '\033[0m' with codecs.open(fn, 'w', 'utf-8') as fp: if fn.lower().endswith('.html'):					write_html(fp) else:					write_markdown(fp) continue
 if '$$' in query: if result is not None:				query = query.replace('$$', ' (%s) ' % result) else: print '\033[91m$$ in query with no previous result!\033[0m' print continue
		bs = wa_query(query) if bs.queryresult['success'] == 'true':			element = (query, [])			buffer.append(element) for pod in bs.find_all('pod'):				numsubpods = int(pod['numsubpods']) if numsubpods == 0 or ''.join(''.join(subpod.plaintext.contents) for subpod in pod.find_all('subpod')).strip() == '': continue				epod = (pod['title'], [])				element[1].append(epod) print ' \033[1m\033[92m%s\033[0m' % pod['title'] for i, subpod in enumerate(pod.find_all('subpod')): if len(subpod.plaintext.contents):						text = clean('\n'.join(subpod.plaintext.contents)) print indent(text)						epod[1].append(text)
 if pod['title'] == 'Result':							result = text if '  (' in result:								result = result.split('  (', 1)[0] if i + 1 < numsubpods and numsubpods > 1 and '\n' in text: print if len(bs.find_all('pod', dict(scanner='Formula'))): print print '\033[91mThis appears to be an interactive formula.' print 'Results may be nonsensical.\033[0m' else: print '\033[91mQuery failed\033[0m' for tip in bs.find_all('tip'): print '\033[93m-', tip['text'], '\033[0m' print
if __name__=='__main__':	main()
Ejemplo n.º 17
0
def init_output():
    import colorama
    win_unicode_console.enable()
    colorama.init()
Ejemplo n.º 18
0
def main():
    if os.name == 'nt':
        import win_unicode_console
        win_unicode_console.enable()
    argv = sys.argv[1:]
    print("Executing gydroparser version {}".format(__version__))
    try:
        opts, args = getopt.getopt(argv,"vhtgcr:b",["version","help","temperature","generate-conf","create-conf","ratio=","build-charts"])
        #print (opts)
    except getopt.GetoptError:
        print (__doc__)
        disableWUC()
    xlsx = None
    pathToFiles = None
    jsonFile = None
    g = False
    c = False
    ratio = False
    t = False
    b = False
    for opt, arg in opts:
        if opt in ('-h','--help'):
            print (__doc__)
            disableWUC()
        if opt in ('-v', '--version'):
            print ("gydroparser version is {}".format(__version__))
            disableWUC()
        elif opt in ("-g", "--generate-conf"):
            g = True  
        elif opt in ("-c", "--create-conf"):
            c = True
        elif opt in ("-r", "--ratio"):
            try:
                ratio = float(arg)
            except ValueError:
                print ("Argument of (-r,--ratio) must be a number!")
                disableWUC()
        elif opt in ("-t", "--temperature"):
            t = True
        elif opt in ("-b", "--build-charts"):
            b = True
    if g:
        xlsx = choose_file()
        if xlsx:
            jsonFile = xlsx[:-5] + "_configure.json"
            generate_file(jsonFile,xlsx)
        else:
            print("File has not been chosen! Exit.")
            disableWUC()
    if c:
        if not jsonFile:
            opts = {'filetypes' : [('JSON files','.json')], 'title' : 'Select JSON configuration file you wish to work with'}
            jsonFile = choose_file(opts)
        try:
            jsonData = load_json_conf(jsonFile)
        except TypeError:
            print ("JSON file has not been chosen. Exit.")
            disableWUC()
        pathToFiles = choose_path()
        if pathToFiles:
            indexList = [jsonData[x][0] for x in jsonData]
            createObj = createConf()
            createObj.add_table_number_pattern('таблиц[ая] ?1.12')
            createObj.add_table_name_pattern('температура вод[иы]')
            if ratio:
                write_nonindex_names_to_conf(jsonData, jsonFile, pathToFiles, createObj, indexList, ratio)
            else:
                write_nonindex_names_to_conf(jsonData, jsonFile, pathToFiles, createObj, indexList)
        else:
            print ("You should chose a path to data base for this option. Exit.")
    if t:
        if not jsonFile:
            opts = {'filetypes' : [('JSON files','.json')], 'title' : 'Select JSON configuration file you wish to work with'}
            jsonFile = choose_file(opts)
        try:
            jsonData = load_json_conf(jsonFile)
        except TypeError:
            print ("JSON file has not been chosen. Exit.")
            disableWUC()
        if not xlsx:
            xlsx = choose_file()
            if not xlsx:
                print ("XLSX file has not been chosen.Exit.")
                disableWUC()
        if not pathToFiles:
            pathToFiles = choose_path()
        if pathToFiles:
            temperatureObject = ParseOneDoc(jsonData)
            temperatureObject.add_data_marker('[СCсc]е?редн.')
            temperatureObject.add_table_number_pattern('таблиц[ая] ?1.12')
            temperatureObject.add_table_name_pattern('температура вод[иы]')
            updateXLS(walkingDead(pathToFiles, temperatureObject),xlsx)
        else:
            print ("Path to files has not been choosen.Exit.")
    if b:
        if not xlsx:
            xlsx = choose_file()
            if not xlsx:
                print ("XLSX file has not been chosen.Exit.")
                disableWUC()
        build_charts(xlsx)
        print ("Charts have been build successfully! Exit.")
    disableWUC()
Ejemplo n.º 19
0
def main(argv=None):
    """Command line app main function.

    :param list | None argv: Overrides command options (for libuse or testing)
    """
    parser = create_parser()

    args = parser.parse_args() if argv is None else parser.parse_args(argv)

    schemas = ('xsd',) if not args.schemas else tuple(args.schemas)

    if args.debug:
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s - %(levelname)s - %(name)s - %(message)s'
        )
        print('DEBUG logging enabled.')

    try:
        import win_unicode_console
        win_unicode_console.enable()
        log.debug('Running with win-unicode-console patch')
    except Exception:
        pass

    log.debug('TYPE of path: %s' % type(args.path))
    # validate current working dir
    if not args.infile and not args.path:
        args.path = os.getcwdu()
        log.debug('NEW TYPE of path: %s' % type(args.path))

    all_valid = True

    if args.infile:
        log.debug('TYPE of infile.name: %s' % type(args.infile.name))
        print('Validating: %s' % args.infile.name)
        messages = validate(args.infile, schemas)
        is_valid = messages == []
        if is_valid:
            print('VALID - No errors found')
        else:
            print('INVALID - errors found:', file=sys.stderr)
            all_valid = False
            for msg in messages:
                if args.debug:
                    print(msg.__str__(), file=sys.stderr)
                else:
                    print(msg.short, file=sys.stderr)

    if args.path:
        tree_or_dir = 'tree' if args.recursive else 'dir'
        print()
        print('Validating all files in %s %s' % (tree_or_dir, args.path))

        for onix_file_path in iter_files(args.path, args.ext, args.recursive):
            print()
            print('Validating: %s' % onix_file_path)
            with open(onix_file_path, 'rb') as onix_file:
                messages = validate(onix_file, schemas)
                is_valid = messages == []

            if is_valid:
                print('VALID - No errors found')
            else:
                print('INVALID - errors found:', file=sys.stderr)
                all_valid = False
                for msg in messages:
                    if args.debug:
                        print(msg.__str__(), file=sys.stderr)
                    else:
                        print(msg.short, file=sys.stderr)
    if all_valid:
        return 0
    else:
        return 1
Ejemplo n.º 20
0
NOTE: This module requires the additional dependency `pyaudio`. To install
using pip:
    pip install pyaudio
Example usage:
    python transcribe_streaming_mic.py
"""

# [START speech_transcribe_streaming_mic]
from __future__ import division

import re
import sys
import requests
from google.cloud import speech
from win_unicode_console import enable
enable()

import pyaudio
from six.moves import queue

# Audio recording parameters
RATE = 16000
CHUNK = int(RATE / 10)  # 100ms


class MicrophoneStream(object):
    """Opens a recording stream as a generator yielding the audio chunks."""
    def __init__(self, rate, chunk):
        self._rate = rate
        self._chunk = chunk
Ejemplo n.º 21
0
def main():

    # Fix console for windows users
    if platform.system() == 'Windows':
        import win_unicode_console
        win_unicode_console.enable()

    args = docopt(__doc__, version=('lyrico ' + __version__))

    Config.load_config()

    if args['--settings']:
        # show current settings
        Config.show_settings()
        return

    if args['set']:
        # setting 'lyrics_dir' or 'source_dir'

        # This general try catch block is intended for os.makedirs call if
        # it raises OSError which is not due to directory already existing or
        # some other error than OSError
        try:
            Config.set_dir(args['<dir_type>'], args['<full_path_to_dir>'])
            Config.save()
        except Exception as e:
            print(e)
        return

    if args['enable'] or args['disable']:
        # setting 'save_to_file', 'save_to_tag' or 'overwrite'.
        # detect wether user wants to enable or disable a lyrico action
        update_type = 'enable' if args['enable'] else 'disable'
        Config.update_lyrico_actions(args['<lyrico_action>'], update_type)
        Config.save()
        return

    # User wants to download lyrics.

    if args['<source_dir>']:
        # if lyrico <source_dir> invocation is used:
        # update user's "source_dir" in config
        # update Config class' 'source_dir' class variable

        # This general try catch block is intended for os.makedirs call if
        # it raises OSError which is not due to directory already existing or
        # some other error than OSError
        try:
            set_dir_success = Config.set_dir('source_dir',
                                             args['<source_dir>'])
        except Exception as e:
            print(e)
            # Don't go ahead with excution since user gave bad path or might have
            # correct system settings?
            return

        # For this usage if user provides non existing dir, return by using boolean
        # return value of Config.set_dir
        if not set_dir_success:
            return

    #settings changes are done, we need a valid config now
    if not Config.check():
        return

    song_list = [
        Song(song_path) for song_path in get_song_list(Config.source_dir)
    ]
    print(len(song_list), 'songs detected.')
    print('Metadata extracted for',
          (str(Song.valid_metadata_count) + '/' + str(len(song_list))),
          'songs.')
    for song in song_list:
        # Only download lyrics if 'title' and 'artist' is present
        # Error str is already present in song.error
        if song.artist and song.title:
            song.download_lyrics()

        # Show immidiate log in console
        else:
            # If title was present, use that
            if song.title:
                print(song.title, 'was ignored.', song.error)
            # else use audio file path
            else:
                print(song.path, 'was ignored.', song.error)

    print('\nBuilding log...')
    Song.log_results(song_list)
    print(
        '{songs} songs, {tagged} tagged, {files} lyric files, {existing} existing, {errors} errors'
        .format(songs=len(song_list),
                tagged=Song.lyrics_saved_to_tag_count,
                files=Song.lyrics_saved_to_file_count,
                existing=Song.lyrics_existing_count,
                errors=Song.lyrics_errors_count))
    print('FINISHED')

    # Disable windows unicode console anyways
    if platform.system() == 'Windows':
        win_unicode_console.disable()
Ejemplo n.º 22
0
'''
    A very basic script to connect to my Outlook server and 
    iterate over my emails
'''

import win32com.client
import win_unicode_console
import cli

win_unicode_console.enable(
)  # NOTE: There's a bug related to stdout streams that errors out the program

outlook = win32com.client.Dispatch("Outlook.Application")
mapi = outlook.GetNamespace("MAPI")


class Oli():
    '''
        Helper class to iterate over Outlook objects
    '''
    def __init__(self, outlook_object):
        self._obj = outlook_object

    def items(self):
        array_size = self._obj.Count
        for item_index in range(array_size):
            yield (item_index, self._obj[item_index])

    def prop(self):
        return sorted(self._obj._prop_map_get_.keys())
Ejemplo n.º 23
0
 def _enable_win_unicode_console():
     """Enable the Windows CLI console colours for Py3."""
     win_unicode_console.enable(use_readline_hook=False)
Ejemplo n.º 24
0
from argparse import ArgumentParser
from warnings import warn
from pprint import pformat
import sys
import win_unicode_console
win_unicode_console.enable() #https://github.com/tartley/colorama/issues/32
import colorama
from . import logs, types, shells
from .conf import settings
from .corrector import get_corrected_commands
from .exceptions import EmptyCommand
from .utils import get_installation_info
from .ui import select_command


def fix_command():
    """Fixes previous command. Used when `thefuck` called without arguments."""
    colorama.init()
    settings.init()
    with logs.debug_time('Total'):
        logs.debug(u'Run with settings: {}'.format(pformat(settings)))

        try:
            command = types.Command.from_raw_script(sys.argv[1:])
        except EmptyCommand:
            logs.debug('Empty command, nothing to do')
            return

        corrected_commands = get_corrected_commands(command)
        selected_command = select_command(corrected_commands)
Ejemplo n.º 25
0
# -*- coding:utf8 -*-

import codecs
import collections
import random
import time
import numpy as np
import math
import win_unicode_console as fuck_windows
import copy
import matplotlib
import matplotlib.pyplot as plt
fuck_windows.enable()

qaz = '-' * 10
rate = 0.01
poetry_list = []

look_up_table = {}  # word -> num
reverse_look_up_table = {}  # num -> word

word_vector = []
context_matrix = []  # N x embedding_size
embedding_size = 2
one_hot_list = []


def init_vector():
    global word_vector
    for i in range(look_up_table.__len__()):
        word_vector.append(2 * np.random.random([1, embedding_size]) -
Ejemplo n.º 26
0
def main():
    """
    The primary CLI function for the Topic Explorer.
    """
    if platform.system() == 'Windows':
        win_unicode_console.enable()

    # Create the master argparse object.
    parser = ThrowingArgumentParser()

    # Adding the benchmarks flags.
    benchmark_group = parser.add_mutually_exclusive_group()
    benchmark_group.add_argument('-t', '--time', help="Print execution time",
                                 action='store_true')
    benchmark_group.add_argument('-p', '--profile', help="""Profile the command.
    Optional filename saves results for use with snakeviz, pstats, or
    cprofilev. Automatically launches snakeviz, if installed.""",
                                 nargs='?', metavar='STATS_FILE')

    # Using add_subparsers(metavar) until argparse.SUPPRESS support is fixed.
    # See issue http://bugs.python.org/issue22848
    parsers = parser.add_subparsers(help="select a command",
                                    parser_class=ArgumentParser,
                                    metavar='{version,demo,update,init,prep,train,launch,notebook,metadata}')
    version_parser = parsers.add_parser('version', help="Print the version and exit")
    version_parser.set_defaults(func='version')

    # Init Parser
    parser_init = parsers.add_parser('init', help="Initialize the topic explorer")
    init.populate_parser(parser_init)
    parser_init.set_defaults(func="init")

    # Prep Parser
    parser_prep = parsers.add_parser('prep', help="Prep the corpus",
                                     formatter_class=argparse.RawDescriptionHelpFormatter)
    prep.populate_parser(parser_prep)
    parser_prep.set_defaults(func="prep")

    # Train Parser
    parser_train = parsers.add_parser('train', help="Train the LDA models")
    train.populate_parser(parser_train)
    parser_train.set_defaults(func="train")

    # Launch Parser
    parser_launch = parsers.add_parser('launch', help="Serve the trained LDA models")
    server.populate_parser(parser_launch)
    parser_launch.set_defaults(func="launch")

    # Serve Parser
    parser_serve = parsers.add_parser('serve', 
        help="Serve a single LDA model, helper for `topicexplorer launch`," +
             "rarely called directly")
    server.populate_parser(parser_serve)
    parser_serve.set_defaults(func="serve")

    # Notebook Parser
    parser_nb = parsers.add_parser('notebook',
                                   help="Create a set of IPython Notebooks")
    notebook.populate_parser(parser_nb)
    parser_nb.set_defaults(func="notebook")

    # Demo Parser
    parser_demo = parsers.add_parser('demo',
                                     help="Download and run the AP demo")
    parser_demo.set_defaults(func="demo")

    # Update Parser
    parser_update = parsers.add_parser('update',
                                       help="Update the Topic Explorer")
    parser_update.set_defaults(func="update")
    
    # Metadata Parser
    parser_metadata = parsers.add_parser('metadata', 
        help="Add spaces before unicode chars")
    metadata.populate_parser(parser_metadata)
    parser_metadata.set_defaults(func="metadata")
    
    # Export Parser
    parser_export = parsers.add_parser('export', help="Export a tez archive")
    export.populate_parser(parser_export)
    parser_export.set_defaults(func="export")
    
    # Export HTML Parser
    parser_export_html = parsers.add_parser('export-html', help="Export the topic cluster visualization")
    export_html.populate_parser(parser_export_html)
    parser_export_html.set_defaults(func="export-html")

    # Import Parser
    parser_import = parsers.add_parser('import', help="Import the tez archive")
    tezimport.populate_parser(parser_import)
    parser_import.set_defaults(func="import")

    # fancy arg validation for manually injecting tempfile to profile arg 
    try:
        try:
            args = parser.parse_args()
        except ArgumentParserError as e:
            import sys
            new_args = sys.argv[1:]
            try:
                # If the error was thrown by the '-p' argument not having a
                # valid file, fix by manually injecting a nargs break
                profile = new_args.index('-p')

                if (len(new_args) > (profile + 1) and
                        new_args[profile + 1] in parsers.choices.keys()):
                    new_args.insert(profile + 1, '-')
                    args = parser.parse_args(new_args)
                else:
                    raise e
            except ValueError:
                raise e
    except ArgumentParserError as e:
        import sys
        # Check to see if error occurs with a subparser and cause the exception
        # to arise from the subparser instead
        for p in parsers.choices.keys():
            if p in sys.argv[1:]:
                subargs_idx = sys.argv.index(p) + 1
                subargs = sys.argv[subargs_idx:]
                subparser = locals()['parser_' + p]
                # this might cause an error in the subparser, in which case
                # we actually want to show that error first
                args = subparser.parse_args(subargs)

        # Use the default error mechanism for the master parser.
        # If the code gets here, it means the error was not in a subparser
        ArgumentParser.error(parser, e)

    if args.profile:
        if args.profile == '-':
            import tempfile
            temphandle, args.profile = tempfile.mkstemp(suffix='.prof', prefix='vsm.')
            print("Saving benchmark data to", args.profile)

        from profilehooks import profile

        def benchmark(fn):
            return profile(fn, immediate=True, filename=args.profile, stdout=None)

    elif args.time:
        from profilehooks import timecall

        def benchmark(fn):
            return timecall(fn, immediate=False)
    else:
        def benchmark(fn):
            return fn

    if args.func == 'version':
        from topicexplorer.version import __pretty_version__
        print(__pretty_version__, end='')

    elif args.func == 'init':
        args.config_file = benchmark(init.main)(args)

        print("\nTIP: Only initalizing corpus object and config file.")
        print("     Next prepare the corpus using:")
        print("         topicexplorer prep", args.config_file)
        print("     Or skip directly to training LDA models using:")
        print("         topicexplorer train", args.config_file)

    elif args.func == 'prep':
        benchmark(prep.main)(args)

        print("\nTIP: Train the LDA models with:")
        print("         topicexplorer train", args.config_file)

    elif args.func == 'train':
        benchmark(train.main)(args)

        if not args.dry_run:
            print("\nTIP: launch the topic explorer with:")
            print("         topicexplorer launch", args.config_file)
            print("     or the notebook server with:")
            print("         topicexplorer notebook", args.config_file)

    elif args.func == 'launch' or args.func == 'serve':
        # Note that we are only benchmarking the creation process - obviously
        # benches of the serve process will take longer
        app = benchmark(server.create_app)(args)
        server.main(args, app)


    elif args.func == 'notebook':
        benchmark(notebook.main)(args)

    elif args.func == 'demo':
        benchmark(demo.main)(args)

    elif args.func == 'update':
        benchmark(update.main)(args)

    elif args.func == 'metadata':
        benchmark(metadata.main)(args)
    
    elif args.func == 'export':
        benchmark(export.main)(args)

    elif args.func == 'export-html':
        benchmark(export_html.main)(args)

    elif args.func == 'import':
        benchmark(tezimport.main)(args)

    if args.profile:
        try:
            import snakeviz.cli
            print("\n\n")
            snakeviz.cli.main([args.profile])
        except ImportError:
            print("""\nSnakeviz is not installed. Install with `pip install snakeviz`,
            then run `snakeviz {}`.""".format(args.profile))
    
    if platform.system() == 'Windows':
        win_unicode_console.disable()
Ejemplo n.º 27
0
def pictureocr():
    win_unicode_console.enable()
    apikey = '57byQin2TjXUeCi1iAj0GcMF'
    secretkey = '5CjTgAsRmVppfxbjkznrVPeVPE2tjcGe'
    get_token = requests.get(
        'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=%s&client_secret=%s'
        % (apikey, secretkey)).text
    token = json.loads(get_token)['access_token']
    accessUrl = 'https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=%s' % (
        token)
    user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36'
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('--ignore-certificate-errors')
    chrome_options.add_argument('log-level=3')
    chrome_options.add_argument(
        'user-agent="Mozilla/5.0 (iPod; U; CPU iPhone OS 2_1 like Mac OS X; ja-jp) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5F137 Safari/525.20"'
    )
    driver = webdriver.Chrome(
        executable_path='chromedriver.exe', options=chrome_options)
    start = open('url.ini', encoding='utf-8').readlines()
    for line in start:
        line = line.replace('\n', '')
        line = line.split(',')
        title = line[0]
        url = line[1]
        driver.maximize_window()
        driver.get(url)
        print(url)
        picture = driver.find_elements_by_class_name("BDE_Image")
        picture2 = driver.find_elements_by_tag_name("div")
        for picture in picture:
            url = picture.get_attribute('src')
            print(url)
            values = {
                'access_token': token,
                'url': '%s' % (url),
                'probability': 'true'
            }
            data = urllib.parse.urlencode(values).encode(encoding='UTF8')
            req = urllib.request.Request(accessUrl, data)
            req.add_header('Content-Type', 'application/x-www-form-urlencoded')
            response = urllib.request.urlopen(req)
            the_page = response.read()
            if (the_page):
                try:
                    amount1 = json.loads(
                        the_page.decode("utf-8"))['words_result_num']
                except KeyError:
                    break
                print("识别到文字%d处" % (amount1))
                q = 0
                while q < amount1:
                    currentResult = json.loads(
                        the_page.decode("utf-8"))['words_result'][q]["words"]
                    print(currentResult)
                    format = re.sub("\D", "", currentResult)
                    if len(format) >= 8 and len(format) <= 12:
                        if int(format[0]) == 0:
                            print('----自动修正----')
                            temp = list(format)
                            del temp[0]
                            format = "".join(temp)
                        print("识别到qq号%s" % (format))
                        qq = open('qq.ini', 'a+')
                        qq.write('%s ' % (format))
                        qq.close()
                    q = q + 1
        for picture in picture2:
            url2 = picture.get_attribute('data-url')
            if url2 is not None:
                print("发现图片资源!地址:%s" % (url2))
                print("----开始分析图片%s----" % (url2))
                values = {
                    'access_token': token,
                    'url': '%s' % (url2),
                    'probability': 'true'
                }
                data = urllib.parse.urlencode(values).encode(encoding='UTF8')
                req = urllib.request.Request(accessUrl, data)
                req.add_header('Content-Type',
                               'application/x-www-form-urlencoded')
                response = urllib.request.urlopen(req)
                the_page = response.read()
                if (the_page):
                    try:
                        amount1 = json.loads(
                            the_page.decode("utf-8"))['words_result_num']
                    except KeyError:
                        break
                    print("识别到文字%d处" % (amount1))
                    q = 0
                    while q < amount1:
                        currentResult = json.loads(the_page.decode(
                            "utf-8"))['words_result'][q]["words"]
                        print(currentResult)
                        format = re.sub("\D", "", currentResult)
                        if len(format) >= 8 and len(format) <= 12:
                            print(currentResult)
                            if int(format[0]) == 0:
                                print('----自动修正----')
                                temp = list(format)
                                del temp[0]
                                format = "".join(temp)
                            print("识别到qq号%s" % (format))
                            qq = open('qq.ini', 'a+')
                            qq.write('%s ' % (format))
                            qq.close()
                        q = q + 1
Ejemplo n.º 28
0
Archivo: np.py Proyecto: FrankLeeC/nlp
# -*- coding:utf-8 -*-

import numpy as np
import win_unicode_console as fuckkkkkkkkkkkkkyou_windows
fuckkkkkkkkkkkkkyou_windows.enable()

a = np.random.rand(3, 1)
b = np.random.rand(5, 1)
print(a)
print(b)
print(a.shape, b.shape)
# c = [a, b]
# print(c)
# print(c.shape)

d = np.row_stack((a, b))
print(d)
print(d.shape)
print('-----------')

c = np.random.rand(3, 1)
print(c)
print(np.max(c))
print(np.argmax(c))

print('----------------------')
a = np.random.randint(0, 10, (5, 5))
print(a)
# a.itemset((0, 2), (1,2), (3, 4), 12)
# print(a)
print('----------------')
Ejemplo n.º 29
0
from __future__ import unicode_literals
import os
import requests
import re
from bs4 import BeautifulSoup
from tabulate import tabulate
import re
import sys
import urllib
import urllib2
import subprocess

import win_unicode_console as wp
wp.enable()

download_url = 'https://ukpirateproxy.xyz'


def ask_user():
    movie_name = raw_input("What do you want to search?\n")
    movie_name = movie_name.replace(" ", "+")
    url = 'https://ukpirateproxy.xyz/s/?q='
    url = url + movie_name + '&page=0&orderby=99'
    return url


def start_download(torrent_no):

    final_url = download_url + torrent_no

    try:
Ejemplo n.º 30
0
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
# pylint: disable=redefined-variable-type

try:
    import win_unicode_console
    win_unicode_console.enable(use_unicode_argv=True)
except ImportError:
    pass

import logging
import sys
import time

from contextlib import ExitStack, suppress

from path import Path
from volapi import Room, listen_many

from .constants import ADMINFAG, PARROTFAG
from ._version import __fulltitle__, __version__
from .arb import ARBITRATOR
Ejemplo n.º 31
0
def main():

	# Fix console for windows users
	if platform.system() == 'Windows':
		import win_unicode_console
		win_unicode_console.enable()

	args = docopt(__doc__, version = ('lyrico ' + __version__))

	# The check_config flag instructs the "Config.load_config" to skip the 'BadConfigError's.
	# So only when user is running downloads, the config must be valid.
	# When user is running cmds to update config, it will be always loaded
	# regardless of values of the settings.
	check_config = not(args['--settings'] or args['disable'] or args['enable'] or args['set'])

	Config.load_config(check_config)
	if not Config.is_loaded:
		# Config not loaded due to exceptions. Error logged by exception handlers.
		return
	
	if args['--settings']:
		# show current settings
		Config.show_settings()
		return

	if args['disable'] or args['enable'] or args['set']:
		# User is updating config

		if args['set']:
			# setting 'lyrics_dir' or 'source_dir'

			# This general try catch block is intended for os.makedirs call if
			# it raises OSError which is not due to directory already existing or
			# some other error than OSError
			try:
				Config.set_dir(args['<dir_type>'], args['<full_path_to_dir>'])
			except Exception as e:
				print(e)

		if args['enable'] or args['disable']:
			# setting 'save_to_file', 'save_to_tag' or 'overwrite'.

			# detect wether user wants to enable or disable a lyrico action
			update_type = 'enable' if args['enable'] else 'disable'
			Config.update_lyrico_actions(args['<lyrico_action>'], update_type)
	else:
		# User wants to download lyrics.

		if args['<source_dir>']:
			# if lyrico <source_dir> invocation is used:
			# update user's "source_dir" in config
			# update Config class' 'source_dir' class variable

			# This general try catch block is intended for os.makedirs call if
			# it raises OSError which is not due to directory already existing or
			# some other error than OSError
			try:
				set_dir_success = Config.set_dir('source_dir', args['<source_dir>'])
			except Exception as e:
				print(e)
				# Don't go ahead with excution since user gave bad path or might have
				# correct system settings?
				return

			# For this usage if user provides non existing dir, return by using boolean
			# return value of Config.set_dir
			if not set_dir_success:
				return

			# update class variable so that new setting is reflected across modules.
			Config.source_dir = args['<source_dir>']
				
		song_list = [Song(song_path) for song_path in get_song_list(Config.source_dir)]
		print(len(song_list), 'songs detected.')
		print('Metadata extracted for', (str(Song.valid_metadata_count) + '/' + str(len(song_list))), 'songs.')
		for song in song_list:
			# Only download lyrics if 'title' and 'artist' is present
			# Error str is already present in song.error
			if song.artist and song.title:
				song.download_lyrics()

			# Show immidiate log in console
			else:
				# If title was present, use that
				if song.title:
					print(song.title, 'was ignored.', song.error)
				# else use audio file path
				else:
					print(song.path, 'was ignored.', song.error)


		print('\nBuilding log...')
		Song.log_results(song_list)
		print('FINISHED')
		
		# Disable windows unicode console anyways
		if platform.system() == 'Windows':
			win_unicode_console.disable()
Ejemplo n.º 32
0
def index_files_ondisk(cur, versdir):
    logger = logging.getLogger(__name__)
    last_root='_'
    last_file_nodate='_'

    if os.name == 'nt':
        # import module that fixes unicode problems
        import win_unicode_console
        win_unicode_console.enable()
        logger.debug('Detected windows based OS, fixing console UTF-8 support')
        versdir = unicode(versdir)

    for root, subdirs, files in os.walk(versdir):
        subdirs.sort()
        files.sort()

        # get path without versioning dir in it
        orig_src_path = rtdbtools.remove_versioning_dir_from_path(root)
        logger.debug('Removed .stversions %s to %s', root, orig_src_path)

        for file in files:
            logger.debug('Processing %s %s', root, file)
            # strip date and time from filename
            file_nodate = rtdbtools.strip_file_date_time(file)
            # get date time from filename
            f_date, f_time = rtdbtools.get_file_date_time(root, file)

            # get epoch values
            try:
                f_epoch = rttools.get_epoch(f_date, f_time)
            except Exception, err:
                #sys.stderr.write('ERROR: %s' % str(err))
                #return 1
                logger.error('Failed to create epoch - %s' % str(err))
                sys.exit(1)

            # test for conflict string
            conflicted_flag=0
            if rtdbtools.check_file_conflict(file_nodate):
                conflicted_flag=1
                logger.debug('Detected syncthing conflict file')

            # confirm if original file exists
            deleted_flag=0

            # join original source path and file
            relative_file = os.path.join(orig_src_path, file_nodate)

            # if file will be considered deleted or renamed if return true
            if not rtdbtools.check_file_exists(relative_file):
                deleted_flag=1

            # if root dir is the same as last dir
            if root == last_root:
                id_root = last_id_root
                id_fo = last_id_fo
                id_fo_test = ''
                # current file_out is not the same as last file_out, test if already exists file_out to DB
                if file_nodate != last_file_nodate:
                    # before testing using sql filter use list of lists to confirm if exists, this is an attempt to optimise
                    for row in outfile_lol:
                        if row[2] in file_nodate:
                            id_fo_test = row[0]
                            break
                    if not id_fo_test:
                        id_fo = rtdbtools.insert_table_file_out(cur, id_root, file_nodate, conflicted_flag, deleted_flag)
                        # add current outfile to list of lists due to not existing yet
                        outfile_lol.append([id_fo, id_root, file_nodate])
                    else:
                        id_fo = id_fo_test
                # insert file_in into DB
                rtdbtools.insert_table_file_in(cur, id_fo, file, f_date, f_time, f_epoch)

            else:
                logger.debug('Indexing new sub directory')
                # clear outfile list of lists due to change of dir
                outfile_lol=[]
                # check if root dir exists in db, even thou not the same as last file tested above
                try:
                    cur.execute('''SELECT id_dir FROM tb_dir_in WHERE dir=?''', (root,))
                    id_root = cur.fetchone()[0]
                except:
                    id_root = rtdbtools.insert_table_dir_in(cur, root, orig_src_path)
                    id_fo = rtdbtools.insert_table_file_out(cur, id_root, file_nodate, conflicted_flag, deleted_flag)
                    rtdbtools.insert_table_file_in(cur, id_fo, file, f_date, f_time, f_epoch)
                    # update last variables for next loop
                    last_id_root, last_id_fo, last_root, last_file_nodate = rtdbtools.update_last_variables(id_root, id_fo, root, file_nodate)
                    # add current outfile to list of lists, due to not existing yet
                    outfile_lol.append([id_fo, id_root, file_nodate])
                    # goto next file in loop
                    continue
                # get row_id if fields match DIR ID and filename from file_out table
                # if no match add DIR to dir_in table, then grab last ID
                try:
                    cur.execute('''SELECT * FROM tb_file_out WHERE id_dir=? AND filename_out=?''', (id_root, file_nodate))
                    id_fo = cur.fetchone()[0]
                except:
                    id_fo = rtdbtools.insert_table_file_out(cur, id_root, file_nodate, conflicted_flag, deleted_flag)
                    # add current outfile to list of lists, due to not existing yet
                    outfile_lol.append([id_fo, id_root, file_nodate])
                # add file to DB
                rtdbtools.insert_table_file_in(cur, id_fo, file, f_date, f_time, f_epoch)
            # update last variables for next loop
            last_id_root, last_id_fo, last_root, last_file_nodate = rtdbtools.update_last_variables(id_root, id_fo, root, file_nodate)
Ejemplo n.º 33
0
#JDPA
import csv
import time
import re
import sys
import os
import win_unicode_console
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from pathlib import Path

win_unicode_console.enable()  #Enable tilde and non ASCII characters


def diditexist(oseedpath):
    oseedpath = os.path.expanduser(oseedpath)
    if not os.path.exists(oseedpath):
        os.makedirs(oseedpath)
        return False
    else:
        return True


def screenshooter(WorkingIndex, browser, imagefolder):
    WorkingIndex = str(WorkingIndex)
    pather = imagefolder + "/#" + WorkingIndex + ".png"
    browser.maximize_window()
    browser.find_element_by_class_name(
        "widget-pane-toggle-button-container").click()
    time.sleep(3)
Ejemplo n.º 34
0
import keras
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from keras.datasets import mnist
from sklearn.decomposition import PCA
from keras.models import Sequential
from keras.layers import Dense, Dropout, Conv2D, MaxPooling2D, Flatten
from keras.layers.advanced_activations import LeakyReLU
from keras.optimizers import Nadam

import win_unicode_console
win_unicode_console.enable()

(x_train, y_train), (x_test, y_test) = mnist.load_data()

#print(type(x_train))


def showimg(img):  #img=x_train[0]
    print(img.shape)
    if (img.shape[0] == 200):
        img = img.reshape(10, 20)
        print(img.shape)
    plt.imshow(img, cmap=plt.cm.gray)
    plt.show()


#x_train=x_train.reshape(60000,28*28).astype("float32")/255 #normalization
#x_test=x_test.reshape(10000,28*28).astype("float32")/255
Ejemplo n.º 35
0
def patch_win_unicode():
    if os.name == 'nt':
        import win_unicode_console
        win_unicode_console.enable()
Ejemplo n.º 36
0
def load_win_unicode_console():
    if sys.platform == 'win32':
        import win_unicode_console
        win_unicode_console.enable()
Ejemplo n.º 37
0
def init_output():
    import colorama
    win_unicode_console.enable()
    colorama.init()
Ejemplo n.º 38
0
def main(argv=None):
    """Command line app main function.

    :param list | None argv: Overrides command options (for libuse or testing)
    """
    parser = create_parser()

    args = parser.parse_args() if argv is None else parser.parse_args(argv)

    schemas = ('xsd',) if not args.schemas else tuple(args.schemas)

    if args.debug:
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s - %(levelname)s - %(name)s - %(message)s'
        )
        print('DEBUG logging enabled.')

    try:
        import win_unicode_console
        win_unicode_console.enable()
        log.debug('Running with win-unicode-console patch')
    except Exception:
        pass

    log.debug('TYPE of path: %s' % type(args.path))
    # validate current working dir
    if not args.infile and not args.path:
        args.path = getcwd()
        log.debug('NEW TYPE of path: %s' % type(args.path))

    all_valid = True

    if args.infile:
        log.debug('TYPE of infile.name: %s' % type(args.infile.name))
        print('Validating: %s' % args.infile.name)
        messages = validate(args.infile, schemas)
        is_valid = messages == []
        if is_valid:
            print('VALID - No errors found')
        else:
            print('INVALID - errors found:', file=sys.stderr)
            all_valid = False
            for msg in messages:
                if args.debug:
                    print(msg.__str__(), file=sys.stderr)
                else:
                    print(msg.short, file=sys.stderr)

    if args.path:
        tree_or_dir = 'tree' if args.recursive else 'dir'
        print()
        print('Validating all files in %s %s' % (tree_or_dir, args.path))

        for onix_file_path in iter_files(args.path, args.ext, args.recursive):
            print()
            print('Validating: %s' % onix_file_path)
            with open(onix_file_path, 'rb') as onix_file:
                messages = validate(onix_file, schemas)
                is_valid = messages == []

            if is_valid:
                print('VALID - No errors found')
            else:
                print('INVALID - errors found:', file=sys.stderr)
                all_valid = False
                for msg in messages:
                    if args.debug:
                        print(msg.__str__(), file=sys.stderr)
                    else:
                        print(msg.short, file=sys.stderr)
    if all_valid:
        return 0
    else:
        return 1
Ejemplo n.º 39
0
from argparse import ArgumentParser
from warnings import warn
from pprint import pformat
import sys
import win_unicode_console
win_unicode_console.enable()  #https://github.com/tartley/colorama/issues/32
import colorama
from . import logs, types, shells
from .conf import settings
from .corrector import get_corrected_commands
from .exceptions import EmptyCommand
from .utils import get_installation_info
from .ui import select_command


def fix_command():
    """Fixes previous command. Used when `thefuck` called without arguments."""
    colorama.init()
    settings.init()
    with logs.debug_time('Total'):
        logs.debug(u'Run with settings: {}'.format(pformat(settings)))

        try:
            command = types.Command.from_raw_script(sys.argv[1:])
        except EmptyCommand:
            logs.debug('Empty command, nothing to do')
            return

        corrected_commands = get_corrected_commands(command)
        selected_command = select_command(corrected_commands)
Ejemplo n.º 40
0
def formatBattleType(battleType):
    if battleType == 'Defence': return 'Defense type'
    if battleType == 'Attack' or battleType == 'Support' or battleType == 'Defense': return battleType + ' type'
    if battleType == 'Area': return battleType + '-attack'
    return battleType

def formatHeroNameForUrl(heroName):
    return ''


def parseSkills(skillUrl):
    return 'fasdfasd'

http = urllib3.PoolManager()
win_unicode_console.enable() #Resolves windows unicode conflict


i = 0
with open(csvPath) as csvFile:
    rowDict = csv.DictReader(csvFile)
    for row in rowDict:
        # print(str(row))

        heroInfoDict = {}
        statInfoDict = {}
        skillInfoDict = {}
        coopInfoDict = {}

        if debug == True: print('Character url: ' + characterUrlTemplate.format(row['Hero']))
        if debug == True:  print('Skill url: ' + skillUrlTemplate.format(row['Hero']))
Ejemplo n.º 41
0
    print()
    print('      ☛ Done, should be normal text. ☚  ')
    print()


if __name__ == '__main__':

    import sys, os
    import logging

    log = logging.getLogger(__name__)
    if os.name == 'nt':
        import env
        try:  # wuc must come before colorama.init() for detection to work.
            import win_unicode_console as wuc
            wuc.enable()
        except ImportError:
            pass
        try:
            if not env.ANSICON:
                import colorama
                colorama.init()
        except ImportError:
            pass

    # What needs to be done to get demos to run:
    _DEBUG = '-d' in sys.argv
    _SHORT = '-s' in sys.argv
    if _DEBUG:
        from . import set_debug_mode
        set_debug_mode(_DEBUG)
Ejemplo n.º 42
0
    pass

# Check if we are running this on windows platform
is_windows = sys.platform.startswith('win')

# Console Colors
if is_windows:
    # Windows deserves coloring too :D
    G = '\033[92m'  # green
    Y = '\033[93m'  # yellow
    B = '\033[94m'  # blue
    R = '\033[91m'  # red
    W = '\033[0m'   # white
    try:
        import win_unicode_console , colorama
        win_unicode_console.enable()
        colorama.init()
        #Now the unicode will work ^_^
    except:
        print("[!] Error: Coloring libraries not installed, no coloring will be used [Check the readme]")
        G = Y = B = R = W = G = Y = B = R = W = ''


else:
    G = '\033[92m'  # green
    Y = '\033[93m'  # yellow
    B = '\033[94m'  # blue
    R = '\033[91m'  # red
    W = '\033[0m'   # white

Ejemplo n.º 43
0
def main():

    # Fix console for windows users
    if platform.system() == 'Windows':
        import win_unicode_console
        win_unicode_console.enable()

    args = docopt(__doc__, version=('lyrico ' + __version__))

    # The check_config flag instructs the "Config.load_config" to skip the 'BadConfigError's.
    # So only when user is running downloads, the config must be valid.
    # When user is running cmds to update config, it will be always loaded
    # regardless of values of the settings.
    check_config = not (args['--settings'] or args['disable'] or args['enable']
                        or args['set'])

    Config.load_config(check_config)
    if not Config.is_loaded:
        # Config not loaded due to exceptions. Error logged by exception handlers.
        return

    if args['--settings']:
        # show current settings
        Config.show_settings()
        return

    if args['disable'] or args['enable'] or args['set']:
        # User is updating config

        if args['set']:
            # setting 'lyrics_dir' or 'source_dir'

            # This general try catch block is intended for os.makedirs call if
            # it raises OSError which is not due to directory already existing or
            # some other error than OSError
            try:
                Config.set_dir(args['<dir_type>'], args['<full_path_to_dir>'])
            except Exception as e:
                print(e)

        if args['enable'] or args['disable']:
            # setting 'save_to_file', 'save_to_tag' or 'overwrite'.

            # detect wether user wants to enable or disable a lyrico action
            update_type = 'enable' if args['enable'] else 'disable'
            Config.update_lyrico_actions(args['<lyrico_action>'], update_type)
    else:
        # User wants to download lyrics.

        if args['<source_dir>']:
            # if lyrico <source_dir> invocation is used:
            # update user's "source_dir" in config
            # update Config class' 'source_dir' class variable

            # This general try catch block is intended for os.makedirs call if
            # it raises OSError which is not due to directory already existing or
            # some other error than OSError
            try:
                set_dir_success = Config.set_dir('source_dir',
                                                 args['<source_dir>'])
            except Exception as e:
                print(e)
                # Don't go ahead with excution since user gave bad path or might have
                # correct system settings?
                return

            # For this usage if user provides non existing dir, return by using boolean
            # return value of Config.set_dir
            if not set_dir_success:
                return

            # update class variable so that new setting is reflected across modules.
            Config.source_dir = args['<source_dir>']

        song_list = [
            Song(song_path) for song_path in get_song_list(Config.source_dir)
        ]
        print(len(song_list), 'songs detected.')
        print('Metadata extracted for',
              (str(Song.valid_metadata_count) + '/' + str(len(song_list))),
              'songs.')
        for song in song_list:
            # Only download lyrics if 'title' and 'artist' is present
            # Error str is already present in song.error
            if song.artist and song.title:
                song.download_lyrics()

            # Show immidiate log in console
            else:
                # If title was present, use that
                if song.title:
                    print(song.title, 'was ignored.', song.error)
                # else use audio file path
                else:
                    print(song.path, 'was ignored.', song.error)

        print('\nBuilding log...')
        Song.log_results(song_list)
        print('FINISHED')

        # Disable windows unicode console anyways
        if platform.system() == 'Windows':
            win_unicode_console.disable()
Ejemplo n.º 44
0
from datetime import datetime
#from functools import reduce
from telegram import Bot
from configs.config import CrawlerConfig as CrConf, S3Config
from configs.crawl_list import CrawlList as map_list
from util.crawler_algo import ancestorOf

import requests
import urllib3
import asyncio
import aiohttp
import sqlite3

try:
    import win_unicode_console  # pip安装
    win_unicode_console.enable()  # 解决VSCode on Windows的输出异常问题
except:
    pass  # 不装这个包,只要不在VScode下运行也不一定有问题


class wannengError(Exception):  # 练习写个异常?
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)

'''
class threadsafe_generator():  # 解决多个线程同时抢占一个生成器导致的错误,乖乖排队去吧您们
    def __init__(self, gen):
        self.gen = gen
Ejemplo n.º 45
0
def enable_win_unicode_console():
    if sys.version_info >= (3, 6):
        return
    import win_unicode_console
    win_unicode_console.enable()