Beispiel #1
0
    def apply(self):
        print(I18n.get('# From left to right, from top to bottom,'))
        near_color = 0

        for y in xrange(self.bot.image.height):
            for x in xrange(self.bot.image.width):
                color = EnumColor.rgb(self.bot.image.pix[x, y])
                old_color = self.bot.canvas.get_color(self.bot.start_x + x,
                                                      self.bot.start_y + y)
                if color != near_color and old_color != color and not color in self.colors_ignored and old_color not in self.colors_not_overwrite:
                    self.bot.paint(self.bot.start_x + x, self.bot.start_y + y,
                                   color)
                near_color = color
            near_color = 0

        print(I18n.get('# From right to left, from top to bottom,'))

        near_color = 0

        for y in xrange(self.bot.image.height):
            for x in reversed(xrange(self.bot.image.width)):
                color = EnumColor.rgb(self.bot.image.pix[x, y])
                old_color = self.bot.canvas.get_color(self.bot.start_x + x,
                                                      self.bot.start_y + y)
                if color != near_color and old_color != color and not color in self.colors_ignored and old_color not in self.colors_not_overwrite:
                    self.bot.paint(self.bot.start_x + x, self.bot.start_y + y,
                                   color)
                near_color = color
            near_color = 0

        print(I18n.get('# From top to bottom, from left to right,'))

        near_color = 0

        for x in xrange(self.bot.image.width):
            for y in xrange(self.bot.image.height):
                color = EnumColor.rgb(self.bot.image.pix[x, y])
                old_color = self.bot.canvas.get_color(self.bot.start_x + x,
                                                      self.bot.start_y + y)
                if color != near_color and old_color != color and not color in self.colors_ignored and old_color not in self.colors_not_overwrite:
                    self.bot.paint(self.bot.start_x + x, self.bot.start_y + y,
                                   color)
                near_color = color
            near_color = 0

        print(I18n.get('# From bottom to top, from left to right,'))

        near_color = 0

        for x in xrange(self.bot.image.width):
            for y in reversed(xrange(self.bot.image.height)):
                color = EnumColor.rgb(self.bot.image.pix[x, y])
                old_color = self.bot.canvas.get_color(self.bot.start_x + x,
                                                      self.bot.start_y + y)
                if color != near_color and old_color != color and not color in self.colors_ignored and old_color not in self.colors_not_overwrite:
                    self.bot.paint(self.bot.start_x + x, self.bot.start_y + y,
                                   color)
                near_color = color
            near_color = 0
Beispiel #2
0
    def paint(self, x, y, color):        
        response = self.pixelio.send_pixel(x, y, color)
        while not response['success']:
            print(I18n.get('try_again'))
            self.wait_time(response)
            self.pixelio.send_pixel(x, y, color)

            self.canvas.update(x, y, color)
        print(I18n.get('You painted %s in the %s,%s') % (I18n.get(str(color.name)), str(x), str(y)))

        self.wait_time(response)
Beispiel #3
0
    def dump(self, language):
        d = dict([(k, v) for k, v in vars(self).items()
                  if not k.startswith('_') and not k == 'geom'])
        locale = I18n.I18n()
        lang = locale.match_language(language)
        d['id'] = 's' + d['schema'] + 'id' + str(d['errorId'])
        d['annotationCoordinate'] = [
            float(d.pop('latitude')),
            float(d.pop('longitude'))
        ]
        d['geomType'] = 'point' if d['osmType'] == 'node' else 'line'
        d['koinReward'] = d.pop('fix_koin_count')
        d['koinRewardWhenComplete'] = d.pop('vote_koin_count')

        d['question'] = locale.translate_question(lang, d['question'],
                                                  d.pop('txt1'), d.pop('txt2'),
                                                  d.pop('txt3'), d.pop('txt4'),
                                                  d.pop('txt5'))
        d['title'] = locale.translate(lang, d['title'])

        input_type = MissionTypeLoader()
        d['inputType'] = copy.deepcopy(
            input_type.get_input_type(
                lang=lang,
                type_id=d['error_type'],
                input_type_name=d.pop('view_type'),
                re_description=d.pop('constraint_re_description'),
                re=d.pop('constraint_re'),
                lower_bound=d.pop('constraint_lower_bound'),
                upper_bound=d.pop('constraint_upper_bound')))
        return d
Beispiel #4
0
    def load_image(self, file):
        tmb_full_path = os.getcwd() + '/img/.cache/' + self.checksum + '.png'

        if (os.path.isfile(tmb_full_path)):
            print(I18n.get('Load cached image'))
            return pillow.open(tmb_full_path).convert('RGB')

        print(
            I18n.get('generating converted image here : %s') %
            str(tmb_full_path))

        new_image = self.convert_pixels(pillow.open(file).convert('RGB'))
        self.save_image(new_image, tmb_full_path)

        print(I18n.get('Saved image cache file, Loading Now...'))
        return pillow.open(tmb_full_path).convert('RGB')
Beispiel #5
0
    def wait_time(self, data={'waitSeconds': None}):
        if data['waitSeconds'] is not None:
            wait = data['waitSeconds'] + random.randint(0, 5)
            print(I18n.get('Waiting %s seconds') % str(wait))

            max_length = int(wait)
            at_length = max_length
            empty = "-"
            used = "+"

            bar = empty * max_length

            for i in range(0, max_length):
                at_length -= 1

                #setting empty and full spots
                bar = used * i
                bar = bar + empty * at_length

                #\r is carriage return(sets cursor position in terminal to start of line)
                #\0 character escape

                sys.stdout.write("[{}]\0\r".format(bar))
                sys.stdout.flush()

                #do your stuff here instead of time.sleep
                time.sleep(1)

            sys.stdout.write("\n")
            sys.stdout.flush()
Beispiel #6
0
    def create_QR_image(text, scale):
        full_QR_path = os.getcwd() + '/img/QRcode.png'
        url = pyqrcode.create(text)
        url.png(full_QR_path, scale)

        print(
            I18n.get('Create QR Code succes in here: %s') % str(full_QR_path))
        print(url.text())
Beispiel #7
0
    def build(strategy, bot, colors_ignored, colors_not_overwrite):

        if strategy == 'randomize':
            return Randomize(bot, colors_ignored, colors_not_overwrite)

        if strategy == 'linear':
            return Linear(bot, colors_ignored, colors_not_overwrite)

        if strategy == 'qf':
            return QuickFill(bot, colors_ignored, colors_not_overwrite)

        if strategy == 'status':
            return Status(bot, colors_ignored, colors_not_overwrite)

        if strategy == 'sketch':
            return Sketch(bot, colors_ignored, colors_not_overwrite)

        if strategy == 'tlc':
            return TopLeftCorner(bot, colors_ignored, colors_not_overwrite)

        if strategy == 'trc':
            return TopRightCorner(bot, colors_ignored, colors_not_overwrite)

        if strategy == 'blc':
            return BottomLeftCorner(bot, colors_ignored, colors_not_overwrite)

        if strategy == 'brc':
            return BottomRightCorner(bot, colors_ignored, colors_not_overwrite)

        if strategy == 'cnb':
            return CentreNorthBoundary(bot, colors_ignored,
                                       colors_not_overwrite)

        if strategy == 'csb':
            return CentreSouthBoundary(bot, colors_ignored,
                                       colors_not_overwrite)

        if strategy == 'cwb':
            return CentreWestBoundary(bot, colors_ignored,
                                      colors_not_overwrite)

        if strategy == 'ceb':
            return CentreEastBoundary(bot, colors_ignored,
                                      colors_not_overwrite)

        if strategy == 'cpd':
            return CentrePointDomain(bot, colors_ignored, colors_not_overwrite)

        if strategy == 'detect':
            return DetectMinTime(bot, colors_ignored, colors_not_overwrite)

        print(
            I18n.get('not fonud strategy %s auto selected randomize') %
            str(strategy))

        return Randomize(bot, colors_ignored,
                         colors_not_overwrite)  # Default strategy
 def on_message(ws, message):
     if unpack_from('B', message, 0)[0] == 193:
         x = unpack_from('!h', message, 1)[0]
         y = unpack_from('!h', message, 3)[0]
         a = unpack_from('!H', message, 5)[0]
         number = (65520 & a) >> 4
         x = int(x * 64 + ((number % 64 + 64) % 64))
         y = int(y * 64 + math.floor(number / 64))
         color = EnumColor.index(15 & a)
         try:
             canvas.matrix[x][y] = color
             if (x in xrange(axis['start_x'], axis['end_x'] + 1)
                     and y in xrange(axis['start_y'],
                                     axis['end_y'])) or log_all_info:
                 print(
                     I18n.get('Somebody updated %s,%s with %s color') %
                     (str(x), str(y), I18n.get(color.name)))
         except Exception as e:
             pass
    def send_pixel(self, x, y, color):
        payload = '{"x":%s,"y":%s,"%s":%s,"color":%s,"fingerprint":"%s","token":null}' % (
            x, y, self.duck, x + y + 2, color.index, self.fingerprint)
        response = self.post(PixelCanvasIO.URL + 'api/pixel', payload)

        if response.status_code == 403:
            raise Exception(I18n.get('Oh no, you are using a proxy'))

        if response.status_code == 422:
            raise Exception(I18n.get('refresh_token'))

        if response.status_code == 429:
            raise Exception(I18n.get('Rate_limit_exceeded'))
        try:
            return response.json()
        except Exception as e:
            raise Exception(
                I18n.get('only_time') + str(response.text) + '-' +
                str(response.status_code))
Beispiel #10
0
    def rgb(rgb, silent=False, sensitive=1, brightness=0):
        for color in EnumColor.ENUM:
            if rgb == color.rgb:
                return color

        #if that colors not in standart colors list
        diff_min = [
            (255, 255, 255), 1038366
        ]  # sqrt(255*255 + 255*255 + 255*255) = 441.67295593 --> Default white

        for color in EnumColor.ENUM:
            #formula that sqrt( (x1 - x2)2 + (y1 - y2)2 + (z1 - z2)2 )

            diff_r = ((rgb[0] + brightness) - color.rgb[0]) * (
                (rgb[0] + brightness) - color.rgb[0])
            diff_g = ((rgb[1] + brightness) - color.rgb[1]) * (
                (rgb[1] + brightness) - color.rgb[1])
            diff_b = ((rgb[2] + brightness) - color.rgb[2]) * (
                (rgb[2] + brightness) - color.rgb[2])

            x = min(diff_r, diff_g, diff_b)
            z = max(diff_r, diff_g, diff_r)
            y = (diff_r + diff_g + diff_b) - (x + z)

            x = x / sensitive
            z = z * sensitive

            diffys = math.sqrt(x + y + z)

            if diffys < diff_min[1]:
                diff_min[1] = diffys
                diff_min[0] = color.rgb

        #return rounding colour

        if not silent:
            print(
                I18n.get(' %s colours rounded %s (%s) ') %
                (str(rgb), str(diff_min[0]),
                 I18n.get(str(EnumColor.rgb(diff_min[0]).name), 'true')))
        return EnumColor.rgb(diff_min[0])
Beispiel #11
0
 def apply(self):
     px_total = self.bot.image.height * self.bot.image.width
     px_ok = 0
     px_not_yet = 0
     for y in xrange(self.bot.image.height):
         for x in xrange(self.bot.image.width):
             color = EnumColor.rgb(self.bot.image.pix[x,y])
             px_ok = px_ok + 1
             if self.bot.canvas.get_color(self.bot.start_x + x, self.bot.start_y + y) != color and not color in self.colors_ignored:
                 px_not_yet = px_not_yet + 1
                 px_ok = px_ok - 1
     print(I18n.get('Total: %s painted: %s Not painted %s') % (str(px_total), str(px_ok), str(px_not_yet)))
     time.sleep(60)
Beispiel #12
0
 def dump(self, language, achieved, achievementDate):
     d = dict([(k, v) for k, v in vars(self).items()
               if not k.startswith('_')])
     locale = I18n.I18n()
     lang = locale.match_language(language)
     d['achievementDate'] = achievementDate.strftime(
         "%d/%m/%y") if achievementDate else None
     d['achievementTitle'] = locale.translate(lang, d.pop('title'))
     d['achieved'] = achieved
     d['achievementId'] = d.pop('id')
     d['achievementImageURI'] = d.pop('name')
     d['achievementDescription'] = locale.translate(lang,
                                                    d.pop('description'))
     return d
Beispiel #13
0
    def wait_time(self, data = {'waitSeconds':None}):
        def complete(i, wait):
            return ((100 * (float(i) / float(wait))) * 20) / 100

        if data['waitSeconds'] is not None:
            wait = data['waitSeconds'] + (random.randint(0, 9) / 10.0)
            print(I18n.get('Waiting %s seconds') % str(wait))

            c = i = 0
            while c < 20:
                c = complete(i, wait)
                time.sleep(wait - i if i == int(wait) else 1)
                out.write("[{}]\0\r".format('+' * int(c) + '-' * (20 - int(c))))
                out.flush()
                i += 1
            out.write("\n")
            out.flush()
Beispiel #14
0
    def rgb(rgb):
        for color in EnumColor.ENUM:
            if rgb == color.rgb:
                return color

        #if that colors not in standart colors list
        diff_min = [(255,255,255), 441.7] # sqrt(255*255 + 255*255 + 255*255) = 441.67295593 --> Default white

        for color in EnumColor.ENUM:
            #formula that sqrt( (x1 - x2)2 + (y1 - y2)2 + (z1 - z2)2 )
            diffys = math.sqrt( (rgb[0] - color.rgb[0]) * (rgb[0] - color.rgb[0]) + (rgb[1] - color.rgb[1]) * (rgb[1] - color.rgb[1]) + (rgb[2] - color.rgb[2]) * (rgb[2] - color.rgb[2]))

            if diffys < diff_min[1]:
                diff_min[1] = diffys
                diff_min[0] = color.rgb

        #return rounding colour
        print(I18n.get(' %s colours rounded %s (%s) ') % (str(rgb) , str(diff_min[0]), I18n.get(str(EnumColor.rgb(diff_min[0]).name))))
        return EnumColor.rgb(diff_min[0])
 def get_input_type(self, lang, type_id, input_type_name, re_description,
                    re, lower_bound, upper_bound):
     try:
         locale = I18n.I18n()
         input_type = {
             'constraints': {
                 'description': locale.translate(lang, re_description)
                 or '',
                 're': re or '',
                 'lowerBound': lower_bound or '',
                 'upperBound': upper_bound or ''
             },
             'options':
             locale.translate_list(
                 lang, copy.deepcopy(self.options.get(type_id, []))),
             'values':
             self.values.get(type_id, []),
             'name':
             locale.translate(lang, input_type_name)
         }
     except Exception as e:
         logger.error(traceback.format_exc())
     return input_type
Beispiel #16
0
from .wakeup import wakeup
from . import config
from .loggers import setup_client
from i18n import I18n, load as load_i18n
from .matchmaking import Matchmaking

client = commands.Bot(cmdargs.prefix, activity=discord.Game(',mahjong join'))
client.should_stop = False


@client.command()
async def tiles(ctx: commands.Context, *, arg: str):
    await ctx.send(emojis.tiles(arg))


load_i18n()
client.add_cog(I18n())
client.add_cog(Matchmaking(client))


@commands.is_owner()
@client.command()
async def stop(ctx: commands.Context):
    await emojis.add_ok(ctx)
    client.should_stop = True


setup_client(client)
client.loop.create_task(wakeup(client))
client.run(config.token)
Beispiel #17
0
 def wait_time(self, data = {'waitSeconds':None}):
     if data['waitSeconds'] is not None:
         wait = data['waitSeconds']
         print(I18n.get('Waiting %s seconds') % str(wait))
         time.sleep(wait)
Beispiel #18
0
loglevel = logging.DEBUG if DEBUG else logging.INFO

logging.basicConfig(level=loglevel,
                    format='[%(asctime)s] [%(levelname)s] %(message)s')

log = logging.getLogger('totes')
logging.getLogger('requests').setLevel(loglevel)


db = sqlite3.connect("totes.sqlite3")
cur = db.cursor()

r = praw.Reddit(USER_AGENT, domain=DOMAIN)

i18n = I18n()

PATH_REGEX = re.compile(r'^/r/([^/]+)/comments/([a-z0-9]{6,8})(/[^/]+/([a-z0-9]{6,8}))?')


def log_error(e):
    log.error("Unexpected {}:\n{}".format(e.__class__.__name__,
                                          traceback.format_exc()))


def np(url):
    """
    Transforms a reddit link into a no participation URL (which in some
    subreddits hides voting arrows, to help prevent administrator shadowbans.
    :param url: URL to transform
    :return: A no participation (NP) link
 def on_close(ws):
     print(I18n.get("### closed ###"))
     open_connection()
 def on_open(ws):
     print(I18n.get("Websocket open"))