#!/usr/bin/env python3

# syllabifyARPA:
# Syllabify ARPABET transcriptions using General American English syllabification rules
# as found in https://en.wikipedia.org/wiki/English_phonology#Syllable_structure
# TODO:DOC caveat with morphological and word boundaries (e.g., mistreat, sesame street)

# October 3rd, 2017

import re
import sys

from syllabifier.constants import VOICELESS
from syllabifier.constants import VOICED
from syllabifier.constants import STOPS
from syllabifier.constants import FRICATIVES
from syllabifier.constants import AFFRICATES
from syllabifier.constants import NASALS
from syllabifier.constants import APPROXIMANTS
from syllabifier.constants import CONSONANTS
from syllabifier.constants import S_EXTENDED_CODAS
from syllabifier.constants import Z_EXTENDED_CODAS
from syllabifier.constants import T_EXTENDED_CODAS
from syllabifier.constants import D_EXTENDED_CODAS
from syllabifier.constants import PHONESET
from syllabifier.constants import VOWELS_REGEX

def syllabifyARPA(arpa_arr, silence_warnings=False):
    """
    Syllabifies ARPABET transcriptions according to General American English
    syllabification rules.

    Args:
        arpa_arr: A string or array of ARPABET phones with optional stress markers
        on the vowels.
        silence_warnings: Boolean (default False) to suppress ValueErrors

    Returns:
        List of strings with syllables in each row.
        In case the input is unsyllabifiable, an empty list is returned.

    Raises:
        ValueError if input contains non-ARPABET phonemes, no vowels or if it
        cannot be syllabified according to English syllabification rules.
    """

    def handleError(string):
        if not silence_warnings:
            raise ValueError(string)

    ret = []

    try:
        arpa_arr = arpa_arr.split() # Allows for phoneme array and string input
    except:
        pass

    for i in range(len(arpa_arr)):
        arpa_arr[i] = arpa_arr[i].upper()

    word = ' '.join(arpa_arr)

    if not (testInPhoneset(arpa_arr)):
        handleError('Input %s contains non-ARPABET phones' % word)
        return ret

    final_arr = []
    temp_arr = []

    # Append till and including vowels
    for i in range(len(arpa_arr)):
        temp_arr.append(arpa_arr[i])
        if re.match(VOWELS_REGEX, arpa_arr[i]):
            final_arr.append(temp_arr)
            temp_arr = []

    # Handle potential remaining coda consonants
    for i in range(len(temp_arr)):
        if len(final_arr) < 1:
            handleError('Input error - no vowel in %s' % word)
            return ret
        final_arr[-1].append(temp_arr[i])

    # All onsets are maximized, some are illegal - fixing that
    for i in range(len(final_arr)):
        while testLegalOnset(final_arr[i]):
            if i == 0:
                handleError('Bad onset cluster in %s' % word)
                return ret
            c = testLegalOnset(final_arr[i])
            final_arr[i].remove(c)
            final_arr[i-1].append(c)

    for i in range(len(final_arr)):
        if not testLegalCoda(final_arr[i]):
            handleError('Bad coda cluster in %s' % word)
            return ret

    ret = [' '.join(syllable) for syllable in final_arr]

    return ret

def testInPhoneset(arr):
    """
    Tests if input consists of 2-letter ARPABET phonemes. Does not require stress
    markers on the vowels.

    Args:
        arr: An array of strings

    Returns:
        True if input array consists of 2-letter ARPABET phones with optional
        stress markers.
    """
    for i in range(len(arr)):
        if not (arr[i] in PHONESET or re.match(VOWELS_REGEX, arr[i])):
            return False
    return True

def testLegalOnset(syllable):
    """
    Function to test for legal onset clusters.

    Args:
        syllable: An array of phones in a transcription containing a vowel

    Returns:
        None if the input's onset is legal. Otherwise, returns the first
        phone of the onset for removal and subsequent appendage to the previous
        syllable's coda.
    """

    cluster = []

    for i in range(len(syllable)):
        if re.match(VOWELS_REGEX, syllable[i]):
            break
        else:
            cluster.append(syllable[i])

    length = len(cluster)

    if length > 3:
        return cluster[0]

    elif length == 3:
        # Only s-clusters can be length 3
        if not (cluster[0] == 'S'):
            return cluster[0]
        # Clusters beginning with s can only be of the forms
        # s-voiceless_stop-approximant or s-voiceless_fricative-r
        elif not (
        (cluster[1] in VOICELESS.intersection(STOPS) and cluster[2] in APPROXIMANTS)
            or
        (cluster[1] in VOICELESS.intersection(FRICATIVES) and cluster[2] == 'R')):
            return cluster[0]

    elif length == 2:
        if not (
        # Valid length-2 consonant clusters are consonant-Y, stop-approximant
        # and voiceless_fricative_or_V-approximant
        (cluster[0] in CONSONANTS and cluster[1] == 'Y')
            or
        (cluster[0] in STOPS and cluster[1] in APPROXIMANTS)
            or
        (cluster[0] in VOICELESS.intersection(FRICATIVES).union(['V']) and
        cluster[1] in APPROXIMANTS)
            or
        # Only s-voiceless_stop, s-voiceless_fricative and s-non_NG_nasals
        # are valid length-2 s-clusters
        (cluster[0] == 'S' and cluster[1] in VOICELESS.difference(AFFRICATES))
            or
        (cluster[0] == 'S' and cluster[1] in NASALS.difference(['NG']))
            or
        # Other clusters normalized through loanwords, e.g. SH-N, S-V, NW, MR
        (cluster[0] == 'SH' and cluster[1] in NASALS and cluster != 'NG')
            or
        (cluster[0] == 'S' and cluster[1] == 'V')
            or
        (cluster[0] == 'M' and cluster[1] in APPROXIMANTS)
            or
        (cluster[0] == 'N' and cluster[1] == 'W')):
            return cluster[0]

    elif length == 1 and cluster[0] == 'NG':
        # Single-consonant-onsets are valid except for NG
        return cluster[0]

    return None

def testLegalCoda(syllable):
    """
    Function to test for legal coda clusters.

    Args:
        syllable: An array of phones in a transcription containing a vowel

    Returns:
        True if the coda cluster (phones after the vowel in the syllable) is
        legal according to English syllabification rules.
    """

    cluster = []

    postvowel = False
    for i in range(len(syllable)):
        if postvowel:
            cluster.append(syllable[i])
        if re.match(VOWELS_REGEX, syllable[i]):
            postvowel = True

    length = len(cluster)

    if length == 0:
        return True

    # English disallows 5+ length coda clusters
    elif length > 4:
        return False

    elif length == 4:
        # 4-phoneme codas must have /s/, /z/, /t/ or /d/ at the end
        if ((cluster[3] == 'S' and cluster[2] in S_EXTENDED_CODAS)
            or
        (cluster[3] == 'Z' and cluster[2] in Z_EXTENDED_CODAS)
            or
        (cluster[3] == 'T' and cluster[2] in T_EXTENDED_CODAS)
            or
        (cluster[3] == 'D' and cluster[2] in D_EXTENDED_CODAS)):
            length -= 1
        else:
            return False

    # if instead of elif to check s-, z-, t-, d-appended clusters

    if length == 3:
        if ((cluster[2] == 'S' and cluster[1] in S_EXTENDED_CODAS)
            or
        (cluster[2] == 'Z' and cluster[1] in Z_EXTENDED_CODAS)
            or
        (cluster[2] == 'T' and cluster[1] in T_EXTENDED_CODAS)
            or
        (cluster[2] == 'D' and cluster[1] in D_EXTENDED_CODAS)):
            length -= 1

        # 3-phone clusters beginning with L, e.g., Alps, milked
        elif cluster[0] == 'L' and (
        (cluster[1] == 'P' and cluster[2] == 'T')
            or
        (cluster[1] == 'P' and cluster[2] == 'S')
            or
        (cluster[1] == 'F' and cluster[2] == 'TH')
            or
        (cluster[1] == 'T' and cluster[2] == 'S')
            or
        (cluster[1] == 'K' and cluster[2] == 'T')
            or
        (cluster[1] == 'K' and cluster[2] == 'S')
            or
        (cluster[1] == 'S' and cluster[2] == 'T')):
            return True

        # 3-phone clusters beginning with R, e.g., carts, worst
        elif cluster[0] == 'R' and (
        (cluster[1] == 'P' and cluster[2] == 'T')
            or
        (cluster[1] == 'P' and cluster[2] == 'S')
            or
        (cluster[1] == 'M' and cluster[2] == 'TH')
            or
        (cluster[1] == 'T' and cluster[2] == 'S')
            or
        (cluster[1] == 'K' and cluster[2] == 'T')
            or
        (cluster[1] == 'S' and cluster[2] == 'T')):
            return True

        # 3-phone clusters beginning with M, e.g., mumps
        elif cluster[0] == 'M' and (
        (cluster[1] == 'P' and cluster[2] == 'T')
            or
        (cluster[1] == 'P' and cluster[2] == 'S')):
            return True

        # 3-phone clusters beginning with N, e.g., thousandth
        elif cluster[0] == 'N' and (
        (cluster[1] == 'D' and cluster[2] == 'TH')):
            return True

        # 3-phone clusters beginning with NG, e.g., angst
        elif cluster[0] == 'NG' and (
        (cluster[1] == 'K' and cluster[2] == 'T')
            or
        (cluster[1] == 'K' and cluster[2] == 'S')
            or
        (cluster[1] == 'K' and cluster[2] == 'TH')
            or
        (cluster[1] == 'S' and cluster[2] == 'T')):
            return True

        # 3-phone clusters beginning with K, e.g., sixth
        elif (
        (cluster[0] == 'K' and cluster[1] == 'S' and cluster[2] == 'TH')
            or
        (cluster[0] == 'K' and cluster[1] == 'S' and cluster[2] == 'T')):
            return True

    if length == 2:
        if ((cluster[1] == 'S' and cluster[0] in S_EXTENDED_CODAS)
            or
        (cluster[1] == 'Z' and cluster[0] in Z_EXTENDED_CODAS)
            or
        (cluster[1] == 'T' and cluster[0] in T_EXTENDED_CODAS)
            or
        (cluster[1] == 'D' and cluster[0] in D_EXTENDED_CODAS)):
            length -= 1

        # 2-phone clusters beginning with L, e.g., elk, health
        if cluster[0] == 'L' and (
        cluster[1] in STOPS.difference(['G'])
            or
        cluster[1] in AFFRICATES
            or
        cluster[1] in set(['F', 'S', 'SH', 'TH', 'V'])
            or
        cluster[1] in NASALS.difference(['NG'])):
            return True

        # 2-phone clusters beginning with R, e.g., arc, yarn
        elif cluster[0] == 'R' and (
        cluster[1] in STOPS
            or
        cluster[1] in AFFRICATES
            or
        cluster[1] in set(['F', 'S', 'SH', 'TH', 'V', 'Z'])
            or
        cluster[1] in NASALS.difference(['NG'])
            or
        cluster[1] == 'L'):
            return True

        # 2-phone clusters beginning with nasals, e.g., bent, ink
        elif cluster[0] == 'M' and cluster[1] in set(['P', 'F', 'TH', 'B']):
            return True
        elif cluster[0] == 'N' and cluster[1] in set(['T', 'D', 'CH', 'JH', 'TH', 'S', 'Z', 'F']):
            return True
        elif cluster[0] == 'NG' and cluster[1] in set(['K', 'TH', 'G']):
            return True

        # 2-phone clusters beginning with stops, e.g., pact, width
        elif (
        (cluster[0] == 'F' and cluster[1] in set(['T', 'TH']))
            or
        (cluster[0] == 'S' and cluster[1] in set(['P', 'T', 'K']))
            or
        (cluster[0] == 'P' and cluster[1] in set(['T', 'TH', 'S', 'F']))
            or
        (cluster[0] == 'K' and cluster[1] in set(['T', 'S', 'SH']))
            or
        (cluster[0] == 'T' and cluster[1] in set(['S', 'TH']))
            or
        (cluster[0] == 'D' and cluster[1] == 'TH')):
            return True

    if length == 1:
        # These phonemes cannot exist as codas by themselves
        if cluster[0] not in set(['HH', 'W', 'Y']):
            return True

    return False


import os
import numpy as np
from scipy import io
from scipy import misc

import lmdb

def load_mnist_image(path):
    image_list = []
    with open(path, 'rb') as ff:
        ff.seek(0)
        header = np.fromfile(ff, dtype=np.int32, count=4)
        header = header.byteswap()
        #num_img = header[1]
        row = header[2]
        col = header[3]
        while ff:
            img = np.fromfile(ff, dtype=np.uint8, count=row*col)
            if img.shape[0] == 0:
                break

            img = img.byteswap().reshape(row, col)
            img = misc.resize(img, (32, 32))
            image_list.append(img)
    return image_list

def load_mnist_label(path):
    label_list = []
    with open(path, 'rb') as ff:
        ff.seek(0)
        header = np.fromfile(ff, dtype=np.int32, count=2)
        header = header.byteswap()

        while ff:
            label = np.fromfile(ff, dtype=np.uint8, count=1)
            if label.shape[0] == 0:
                break

            label = label.byteswap()
            label_list.append(label)
    return label_list

def get_mnist(path):
    train_path = os.path.join(path, 'train-images.idx3-ubyte')
    train_label_path = os.path.join(path, 'train-labels.idx1-ubyte')
    test_path = os.path.join(path, 't10k-images.idx3-ubyte')
    test_label_path = os.path.join(path, 't10k-labels.idx1-ubyte')

    train_img = load_mnist_image(train_path)
    test_img = load_mnist_image(test_path)
    train_label = load_mnist_label(train_label_path)
    test_label = load_mnist_label(test_label_path)

    train_img = np.array(train_img)
    train_img = np.expand_dims(train_img, -1)
    train_img = np.concatenate([train_img, train_img, train_img], -1)

    test_img = np.array(test_img)
    test_img = np.expand_dims(test_img, -1)
    test_img = np.concatenate([test_img, test_img, test_img], -1)

    train_label = np.array(train_label)
    test_label = np.array(test_label)

    return train_img, train_label, test_img, test_label

def get_svhn(path):
    train_path = os.path.join(path, 'train_32x32.mat')
    test_path = os.path.join(path, 'test_32x32.mat')
    train = io.loadmat(train_path)
    train_img = np.transpose(train['X'], (3, 0, 1, 2))
    train_label = train['y']
    train_label[train_label == 10] = 0

    test = io.loadmat(test_path)
    test_img = np.transpose(test['X'], (3, 0, 1, 2))
    test_label = test['y']
    test_label[test_label == 10] = 0

    return train_img, train_label, test_img, test_label

def create_lmdb(mode='train'):
    env = lmdb.open('D:/workspace/dataset/digits/MNIST/lmdb', max_dbs=6, map_size=int(1e9))
    data = env.open_db(("data").encode())
    label = env.open_db(("label").encode())
    vdata = env.open_db(("vdata").encode())
    vlabel = env.open_db(("vlabel").encode())
    tdata = env.open_db(("tdata").encode())
    tlabel = env.open_db(("tlabel").encode())

    dd, ll, tt, ttl = get_mnist()
    #dd, ll, tt, ttl = get_svhn()
    dd = dd.copy(order='C')
    ll = ll.copy(order='C')
    tt = tt.copy(order='C')
    ttl = ttl.copy(order='C')

    # random select 1000 sample as validation
    np.random.seed(1)
    num_val = 1000
    rand_idx = np.random.permutation(len(dd))
    vv, vvl = dd[rand_idx[:num_val]], ll[rand_idx[:num_val]]
    dd, ll = dd[rand_idx[num_val:]], ll[rand_idx[num_val:]]

    print(dd[0].shape)
    print(dd[0].dtype)
    #return
    with env.begin(write=True) as txn:
        for idx in range(dd.shape[0]):
            txn.put((str(idx)).encode(), dd[idx], db=data)
            txn.put((str(idx)).encode(), ll[idx], db=label)
        for idx in range(vv.shape[0]):
            txn.put((str(idx)).encode(), vv[idx], db=vdata)
            txn.put((str(idx)).encode(), vvl[idx], db=vlabel)
        for idx in range(tt.shape[0]):
            txn.put((str(idx)).encode(), tt[idx], db=tdata)
            txn.put((str(idx)).encode(), ttl[idx], db=tlabel)

if __name__=='__main__':
    create_lmdb('train')


import model_old as model

from flask import Flask, jsonify

app = Flask(__name__)

@app.route("/")
def root(): return

@app.route("/api")
def hello():
    items = [
        'tomato',
        'maize',
        'plaintain',
        'potatoes',
        'rice',
        'mustard',
        'soybeans',
        'sweet potatoes',
        'wheat',
        'onion'
    ]

    temp, rainfall = [x.split("=")[-1][:-1] for x in open('VARS').readlines()]
    # print (temp, rainfall)
    # print(dict(zip(items, model.calc_for_everything(temp, rainfall, items))))
    return jsonify(dict(zip(items, model.calc_for_everything(temp, rainfall, items))))

if __name__ == '__main__':
    app.run(port=3636)


# Source
#https://www.w3schools.com/python/python_regex.asp
#https://www.tutorialspoint.com/python/python_reg_expressions.htm
#https://www.datacamp.com/community/tutorials/python-regular-expression-tutorial
#https://www.rexegg.com/regex-lookarounds.html

word = 'geeks for geeks'
result = word.find('for')

### WARM UP PART
import re

# 'search' - search in string (match)
x = re.search('in', 'The rain in Spain')
x.group()
# or simply
re.search('in', 'The rain in Spain').group() # show result
# you can define the string in an string object
str = 'The rain in Spain'
x = re.search('in', str)

re.search('in', 'The rain in Spain').start() # first index of match
re.search('in', 'The rain in Spain').end()   # last index of match
re.search('in', 'The rain in Spain').span()  # show indices

# 'findall' - print occurrences as a list
x=re.findall('a', 'The rain in Spain')

# 'sub' - replace in string
re.sub('n', 's', 'The rain in Spain')
re.sub('n', 's', 'The rain in Spain', 1) # only the first

# split - split string into pieces
re.split('i', 'The rain in Spain')

### Main part

# Metacharacters
#[] + * {} ? ! ^ $ | () .
# Special Sequences
# \ \A \b \B \d \D \s \S \w \W \Z
# Option Flags
#re.I re.M

# [] is a set. Search for any one of the characters in []
re.search('[0-9]', info).group()    # 0-9 <=> 0 1 2 3 4 5 6 7 8 9. Finding matching number from the string
# + means 1 or more match
re.search('[0-9]+', info).group()   # matches (first) up to a character which is not in the set
re.search('[a-z]+', info).group()   # matches (first) up to a character which is not in the set. from a to z
re.search('[a-zA-Z]+', info).group()   # matches (first) up to a character which is not in the set. from a to z and A to Z
re.findall('[0-9]+', info)          # all matches
re.search('[0-9-]+', info).group()  # including the dash '-'
# * means 0 or more match
re.search('[0-9-]+##*', info).group()  # Second "#" is not neccessary
re.search('[0-9-]+##+', info).group()  # Second "#" is not neccessary

# {} - how many times
re.search('[0-9]{3}', info).group()    # 3 times numbers between 0-9
re.search('[0-9]{3,5}', info).group()  # from 3 to 5 times numbers between 0-9
re.search('[0-9]{3,}', info).group()   # at least or more numbers between 0-9
# ? - character on the left at most one or no occurrence
re.search('[0-9]a?', info).span()
re.findall('[0-9-]+a?', info)

# ? - also can be used for lookbehind/lookahead
# lookbehind or look to the immediately preceding characters
re.search('(?<=-)[0-9]+', info).group()  # numbers which follow after '-'.
re.search('(?<!-)[0-9]+', info).group()  # numbers which don't follow '-'
re.split('(?<!-)[0-9]+', info)           # split at the numbers which don't follow '-'
# lookahead or look to the immediately following characters
re.search('[0-9]+(?=-)', info).group()  # numbers which followed by '-'.
re.search('[0-9]+(?!-)', info).group()  # numbers which are not followed by '-'
re.split('[0-9]+(?!-)', info)           # split at the numbers which are not followed by '-'
# ^ - in the beginning of string
re.search('^[0-9]+', info).group()      # numbers in the beginning of string
re.search('^[A-Za-z]+', info).group()      # numbers in the beginning of string

# ^ - also negates when inside []
re.search('[^0-9]+', info).group()      # not number

# $ -in the end of string
re.search('[^0-9]+$', info).group()      # not number in the end of string

info = '2004-959-559# This is Phone Number, my email is py4econ@gmail.com'
# | - or (one of many)
re.findall('i[s|l]', info)                # "i" followed by s or l
re.findall('m[b|y|a]', info)                # "m" followed by b, y or a
re.findall('m[^b|y]', info)                # "m" not followed by b or y

# () - group
x=re.search('([0-9]+)-([0-9-]+)', info)      # two number groups connected by "-"
print(x.group(1))
print(x.group(2))

x=re.search('([0-9a-zA-Z]+)@([0-9a-zA-Z.]+)', info2)      # not number in the end of string
print(x.group(1))
print(x.group(2))

# . -
info2 = '2004-959-559# This is Phone Number, my email is py4econ@gmail.com'
x=re.search(r'([0-9a-zA-Z]+)@([0-9a-zA-Z.]+)', info2)      # not number in the end of string
print(x.group(1))
print(x.group(2))


from selenium import webdriver

from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

from selenium.webdriver.common.by import By

driver = webdriver.Chrome(service=ChromeService(
    ChromeDriverManager().install()))
driver.implicitly_wait(5)

driver.get("http://uitestingplayground.com/textinput")
driver.find_element(By.CSS_SELECTOR, '#newButtonName').send_keys('SkyPro')
button = driver.find_element(By.CSS_SELECTOR, "#updatingButton")
button.click()
text_content = button.text
driver.quit()

print(text_content)


import os
import argparse
from glob import glob
import boto3

sqs = boto3.resource('sqs')
a = argparse.ArgumentParser()
a.add_argument("--queue_name")
a.add_argument("--requests_dir")
args = a.parse_args()

queue = sqs.get_queue_by_name(QueueName=args.queue_name)
for req in glob(os.path.join(args.requests_dir, "*")):
    with open(req) as rf:
        resp = queue.send_message(MessageBody=rf.read().strip())
        print(resp)


import pymel.core as pm
import json
from functools import partial
import traceback
import os.path

import mgear.maya.utils as mutils
import mgear.string as string

import mgear.maya.shifter.gameToolsUI as gtUI

from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
import mgear.maya.pyqt as gqt
from mgear.vendor.Qt import QtCore, QtWidgets

@mutils.one_undo
def disconnect(cnxDict):
    for i, jnt in enumerate(cnxDict["joints"]):
        # we don't need to disconnect blended joint since the connection is
        # from other joints
        if not jnt.startswith("blend_"):
            oJnt = pm.PyNode(jnt)

            for e, plug in enumerate([oJnt.translate, oJnt.rotate, oJnt.scale,
                                      oJnt.scale.scaleX, oJnt.scale.scaleY,
                                      oJnt.scale.scaleZ, oJnt.shear]):
                if cnxDict["attrs"][i][e]:
                    pm.disconnectAttr(cnxDict["attrs"][i][e], plug)
            if cnxDict["attrs"][i][7]:
                pm.disconnectAttr(
                    oJnt.parentInverseMatrix[0], cnxDict["attrs"][i][7])

def connect(cnxDict, nsRig=None, nsSkin=None):
    for i, jnt in enumerate(cnxDict["joints"]):
        try:
            if nsSkin:
                oJnt = pm.PyNode(nsSkin + ":" + jnt)
            else:
                oJnt = pm.PyNode(jnt)
            for e, plug in enumerate([oJnt.translate, oJnt.rotate, oJnt.scale,
                                      oJnt.scale.scaleX, oJnt.scale.scaleY,
                                      oJnt.scale.scaleZ, oJnt.shear]):
                if cnxDict["attrs"][i][e]:
                    if nsRig:
                        pm.connectAttr(
                            nsRig + ":" + cnxDict["attrs"][i][e], plug, f=True)
                    else:
                        pm.connectAttr(cnxDict["attrs"][i][e], plug, f=True)

            if cnxDict["attrs"][i][7]:
                if nsRig:
                    pm.connectAttr(
                        oJnt.parentInverseMatrix[0], nsRig + ":" +
                        cnxDict["attrs"][i][7], f=True)
                else:
                    pm.connectAttr(
                        oJnt.parentInverseMatrix[0],
                        cnxDict["attrs"][i][7],
                        f=True)

        except Exception:
            pm.displayError("{} is not found in the scene".format(jnt))

def connectCns(cnxDict, nsRig=None, nsSkin=None):
    for i, jnt in enumerate(cnxDict["joints"]):
        if nsSkin:
            oJnt = pm.PyNode(nsSkin + ":" + jnt)
        else:
            oJnt = pm.PyNode(jnt)

        if cnxDict["attrs"][i][0]:
            if nsRig:
                oAttr = pm.PyNode(nsRig + ":" + cnxDict["attrs"][i][0])
            else:
                oAttr = pm.PyNode(cnxDict["attrs"][i][0])

            oNode = oAttr.node()
            oTrans = pm.listConnections(
                pm.listConnections(oNode.inputMatrix)[0].matrixIn[0])
            pm.parentConstraint(oTrans, oJnt, mo=True)
            pm.scaleConstraint(oTrans, oJnt, mo=True)

def exportConnections(source=None, filePath=None, disc=False):
    connections = {}
    connections["joints"] = []
    connections["attrs"] = []
    if not source:
        source = pm.selected()
    for x in source:
        if not x.name().startswith("blend_"):
            connections["joints"].append(x.name())
            trans_attr = pm.listConnections(
                x.translate, p=True, type="decomposeMatrix")
            rot_attr = pm.listConnections(
                x.rotate, p=True, type="decomposeMatrix")
            scl_attr = pm.listConnections(
                x.scale, p=True, type="decomposeMatrix")
            sclX_attr = pm.listConnections(
                x.scale.scaleX, p=True, type="decomposeMatrix")
            sclY_attr = pm.listConnections(
                x.scale.scaleY, p=True, type="decomposeMatrix")
            sclZ_attr = pm.listConnections(
                x.scale.scaleZ, p=True, type="decomposeMatrix")
            shear_attr = pm.listConnections(
                x.shear, p=True, type="decomposeMatrix")
            parentInv_attr = pm.listConnections(
                x.parentInverseMatrix[0], d=True, p=True)

            attrs_list = [trans_attr, rot_attr, scl_attr, sclX_attr,
                          sclY_attr, sclZ_attr, shear_attr, parentInv_attr]
            attrs_list_checked = []
            for at in attrs_list:
                if at:
                    attrs_list_checked.append(at[0].name())
                else:
                    attrs_list_checked.append(None)

            connections["attrs"].append(attrs_list_checked)

    data_string = json.dumps(connections, indent=4, sort_keys=True)
    if not filePath:
        filePath = pm.fileDialog2(dialogStyle=2, fileMode=0,
                                  fileFilter=' Shifter joint cnx maya matrix'
                                  '  .jmm (*%s)' % ".jmm")
        if not filePath:
            return
        if not isinstance(filePath, basestring):
            filePath = filePath[0]

    if os.path.isfile(filePath) and connections["joints"]:
        with open(filePath, 'w') as f:
            f.write(data_string)

        if disc:
            disconnect(connections)

def importConnections(filePath=None, nsRig=None, nsSkin=None, useMtx=True):
    if not filePath:
        startDir = pm.workspace(q=True, rootDirectory=True)
        filePath = pm.fileDialog2(dialogStyle=2, fileMode=1,
                                  startingDirectory=startDir,
                                  fileFilter=' Shifter joint cnx maya matrix '
                                  ' .jmm (*%s)' % ".jmm")
    if not filePath:
        return
    if not isinstance(filePath, basestring):
        filePath = filePath[0]
    with open(filePath) as fp:
        configDict = json.load(fp)

    if useMtx:
        connect(configDict, nsRig=nsRig, nsSkin=nsSkin)
    else:
        connectCns(configDict, nsRig=nsRig, nsSkin=nsSkin)

def getRigTopNode(node=None):
    if not node and pm.selected():
        node = pm.selected()[0]
        if not node.hasAttr("is_rig"):
            pm.displayWarning(
                "Please select a valid rig top node!. '{}' "
                "is not a rig top node".format(node.name()))
            return False
        return node.name()
    else:
        pm.displayWarning("Please select a rig top node!")
        return False

def runScript(path=None):
    if path:
        execfile(path)

@mutils.one_undo
def exportAssetAssembly(name, rigTopNode, meshTopNode, path, postScript=None):
    if pm.ls(rigTopNode):
        rigTopNode = pm.PyNode(rigTopNode)
    else:
        pm.displayError(
            "{} doesn't exist or duplicated. Please check your "
            "scene".format(rigTopNode))
        return

    if pm.ls(meshTopNode):
        meshTopNode = pm.PyNode(meshTopNode)
    else:
        pm.displayError(
            "{} doesn't exist or duplicated. Please check "
            "your scene".format(meshTopNode))
        return
    # check the folder and script
    # if the target name exist abort and request another name

    deformer_jnts = rigTopNode.rigGroups[3].connections()[0].members()
    if not deformer_jnts:
        pm.displayError(
            "{} is empty. The tool can't find any joint".format(meshTopNode))

    # export connections and cut joint connections

    # cut al possible remaining connection and adjust hierarchy

    # pot script
    if postScript:
        try:
            execfile(postScript)
        except Exception as ex:
            template = "An exception of type {0} occured. Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            pm.displayError(message)
            cont = pm.confirmBox("FAIL: Script Fail",
                                 "Do you want to export anyway?" + "\n\n" +
                                 message + "\n\n" + traceback.format_exc(),
                                 "Continue", "Cancel")
            if not cont:
                pm.undo()
                return

    # export rig model

    # export mesh and joints

def _importAssetAssembly(paht=None, reference=False):
    return

def importAssetAssembly(path=None):
    return

def referenceAssetAssembly(path=None):
    return

####################################
# Soft tweaks Manager dialog
####################################

class gameToolsUI(QtWidgets.QDialog, gtUI.Ui_gameTools):

    def __init__(self, parent=None):
        super(gameToolsUI, self).__init__(parent)
        self.setupUi(self)

class gameTools(MayaQWidgetDockableMixin, QtWidgets.QDialog):

    def __init__(self, parent=None):
        self.toolName = "shifterGameTools"
        super(self.__class__, self).__init__(parent=parent)
        self.gtUIInst = gameToolsUI()

        self.startDir = pm.workspace(q=True, rootDirectory=True)

        self.gameTools_window()
        self.gameTools_layout()
        self.createConnections()

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)

    def gameTools_window(self):

        self.setObjectName(self.toolName)
        self.setWindowFlags(QtCore.Qt.Window)
        self.setWindowTitle("Shifter Game Tools")
        self.resize(300, 330)

    def gameTools_layout(self):

        self.gt_layout = QtWidgets.QVBoxLayout()
        self.gt_layout.addWidget(self.gtUIInst)

        self.setLayout(self.gt_layout)

    # Slots
    @staticmethod
    def _validCharacters(lEdit):
        name = string.removeInvalidCharacter(lEdit.text())
        lEdit.setText(name)

    def populateRigTopNode(self):
        topNode = getRigTopNode()
        if topNode:
            self.gtUIInst.rigNode_lineEdit.setText(topNode)

    def populateMeshTopNode(self):
        if pm.selected():
            node = pm.selected()[0]
            self.gtUIInst.meshNode_lineEdit.setText(node.name())
        else:
            pm.displayWarning("Please select a Mesh top node!")
            return False

    def populateOutputFolder(self):
        filePath = pm.fileDialog2(dialogStyle=2, fileMode=2,
                                  startingDirectory=self.startDir,
                                  fileFilter=' Shifter Game Assembly folder')
        if not filePath:
            return
        if not isinstance(filePath, basestring):
            filePath = filePath[0]
        self.gtUIInst.path_lineEdit.setText(filePath)

    def populateScript(self):
        filePath = pm.fileDialog2(dialogStyle=2, fileMode=1,
                                  startingDirectory=self.startDir,
                                  fileFilter=' Post Script  .py (*%s)' % ".py")
        if not filePath:
            return
        if not isinstance(filePath, basestring):
            filePath = filePath[0]
        self.gtUIInst.script_lineEdit.setText(filePath)

    def disconnectExport(self):
        name = self.gtUIInst.assetName_lineEdit.text()
        rigTopNode = self.gtUIInst.rigNode_lineEdit.text()
        meshTopNode = self.gtUIInst.meshNode_lineEdit.text()
        path = self.gtUIInst.path_lineEdit.text()
        postScript = self.gtUIInst.script_lineEdit.text()

        if name and rigTopNode and meshTopNode and path:
            exportAssetAssembly(
                name, rigTopNode, meshTopNode, path, postScript)
        else:
            pm.displayWarning(
                "Name, Rig Top Node, Mesh Top Node and path "
                "are mandatory fields. Please check it.")

    # Connect slots
    def createConnections(self):
        self.gtUIInst.assetName_lineEdit.editingFinished.connect(
            partial(gameTools._validCharacters,
                    self.gtUIInst.assetName_lineEdit))
        self.gtUIInst.rigNode_pushButton.clicked.connect(
            self.populateRigTopNode)
        self.gtUIInst.meshNode_pushButton.clicked.connect(
            self.populateMeshTopNode)
        self.gtUIInst.path_pushButton.clicked.connect(
            self.populateOutputFolder)
        self.gtUIInst.script_pushButton.clicked.connect(self.populateScript)
        self.gtUIInst.disconnectExport_pushButton.clicked.connect(
            self.disconnectExport)

if __name__ == "__main__":

    gqt.showDialog(gameTools)


import json
import sys
sys.path.append("..")
from api.bybit_api import Bybit_Api
import controller.comms as comms
from model.calc import Calc as calc
import time
import asyncio

class Orders:

    def __init__(self, api_key, api_secret, symbol, symbol_pair, key_input, input_quantity, leverage, limit_price_difference):
        self.atr = None
        self.total_profit_loss = 0
        self.limit_price_difference = limit_price_difference
        self.api = Bybit_Api(api_key, api_secret, symbol, symbol_pair, key_input, input_quantity, leverage)

    def log_closing_details(self, trade_record_id, symbol_pair, stop_loss, percent_gain, side, time):

        global total_profit_loss

        # trade_kv_dict = db().get_trade_values()

        # symbol_pair = trade_kv_dict['symbol_pair']
        entry_price = self.api.get_entry_price()
        exit_price = self.api.get_exit_price()
        # stop_loss = trade_kv_dict['stop_loss']
        # percent_gain = trade_kv_dict['percent_gain']
        # side =  trade_kv_dict['side']
        total_gain = self.api.calc_total_gain()
        total_coin = self.api.get_total_coin()
        time = str(comms.time_stamp())
        trade_record_id = trade_record_id + 1

        # db().set_trade_record_id(total_number_trades)
        self.total_profit_loss += total_gain

        kv_dict = {'trade_record_id': trade_record_id, 'symbol_pair': symbol_pair, 'entry_price': entry_price, 'exit_price': exit_price, 'stop_loss': stop_loss, 'percent_gain': percent_gain, 'side': side, 'total_gain': total_gain, 'total_coin': total_coin, 'time': time}

        # for x in range(len(row_list)):
        #     kv_pair = [(column_name_list[x][0], row_list[x])]
        #     kv_dict.update(kv_pair)

        # conn.create_trade_record(trade_id_input, symbol_pair, entry_price, exit_price, stop_loss, percent_gain, total_gain, total_coin, self.total_profit_loss, time)

        return kv_dict

    def active_order_check(self):
        order = self.api.get_order()
        return 0 if (order == []) else 1

    def active_position_check(self):
        try:
            position_value = self.api.get_position_value()
            return 1 if (position_value != '0') else 0
        except Exception as e:
            print("Active Position Check Exception Occured...")
            print("Trying again...")
            time.sleep(2)
            self.active_position_check()

    def input_atr(self):
        global atr
        flag = False
        print("")
        while(flag == False):
            atr = input("Input ATR: ")
            if(atr.isnumeric()):
                print("ATR input accepted for SL: " + str(atr))
                flag = True
            else:
                print("Invalid Input, try again...")

    def force_limit_order(self, side):
        flag = False
        current_price = api.last_price()
        price = calc().calc_limit_price_difference(side, self.api.last_price(), self.limit_price_difference)

        while(flag == False):
            if (self.active_order_check() == 1):
                if (self.api.last_price() != current_price) and (self.api.last_price() != price):
                    print("last_price: " + str(self.api.last_price()))
                    print("current_price: " + str(current_price))
                    print("price: " + str(price))
                    current_price = self.api.last_price()
                    price = calc().calc_limit_price_difference(side, self.api.last_price(), self.limit_price_difference)
                    self.api.change_order_price(price)
                    print("Order Price Updated: " + str(price))
                    print("")
                time.sleep(2)

            else:
                flag = True

    def create_order(self, side_input, order_type, input_quantity):
        global level
        global percent_level
        global percent_gained_lock

        percent_gained_lock = 0.0
        percent_level = 0.0
        flag = False

        if (self.active_order_check() == 1):
            print("Current Active Order...")
            print("Create Order Cancelled")
        elif (self.active_position_check() == 1):
            print("Current Active Position...")
            print("Create Order Cancelled")
        else:
            one_percent = calc().calc_one_percent(self.leverage, self.api.last_price())
            initial_stop_loss = (api.last_price() - (2*one_percent)) if (side_input == 'Buy') \
                else (self.api.last_price() + (2*one_percent))

            while(flag == False):
                if ((self.active_order_check() == 0) and (self.active_position_check() == 0)):
                    print("Attempting to place order...")
                    entry_price = calc().calc_limit_price_difference(side_input, self.api.last_price(), self.limit_price_difference)
                    self.api.place_order(price=entry_price, order_type=order_type, side=side_input, input_quantity=db().get_input_quantity(), stop_loss=initial_stop_loss, reduce_only=False)

                    if(order_type == 'Limit'):
                        print("")
                        print("Retrieving Order ID...")
                        print("Order ID: " + str(self.api.get_order_id()))
                        self.force_limit_order(side=side_input)
                else:
                    print("")
                    print("Confirming Order...")

                    if((self.active_order_check() == 0) and (self.active_position_check() == 0)):
                        print("Order Failed")
                    else:
                        entry_price = float(self.api.get_active_position_entry_price())
                        print("")
                        print("Order Successful")
                        print("Entry Price: " + str(entry_price))
                        print("Initial Stop Loss: " + str(initial_stop_loss))
                        print("")
                        flag = True

    # def close_position_sl(self):
    #     flag = True
    #     stop_loss_input_price = self.api.last_price()
    #     print("Forcing Close")
    #     self.api.change_stop_loss(self.api.last_price() - float(2))
    #     time.sleep(5)

    #     while(flag == True):
    #         if(self.active_position_check() == 1):
    #             if (self.api.last_price() > stop_loss_input_price):
    #                 stop_loss_input_price = self.api.last_price()
    #                 print("")
    #                 print("Forcing Close")
    #                 comms.time_stamp()
    #                 self.api.change_stop_loss(self.api.last_price() - float(2))
    #                 time.sleep(5)
    #         else:
    #             print("Position Closed")
    #             flag = False

    def close_position_market(self):
        position_size = self.api.get_position_size()
        flag = True

        if(self.api.get_position_side() == "Sell"):
            self.api.place_order(self.api.last_price(), 'Market', 'Buy', position_size, 0, True)
        else:
            self.api.place_order(self.api.last_price(), 'Market', 'Sell', position_size, 0, True)

        while(flag == True):
            if (self.active_position_check() == 1):
                print("Error Closing Position")
                self.close_position_market()
            else:
                print("Position Closed at: " + str(self.api.last_price()))
                flag = False

    def force_limit_close(self):
        flag = False
        current_price = self.api.last_price()
        input_quantity = self.api.get_position_size()
        side = self.api.get_position_side()
        print("current_price: " + str(current_price))

        side = 'Sell' if (side == 'Buy') else 'Buy'

        while(flag == False):
            if(self.active_position_check() == 1) and (self.active_order_check() == 0):
                print("Print Order Check")
                price = calc().calc_limit_price_difference(side, self.api.last_price(), self.limit_price_difference)
                self.api.place_order(price=price, order_type='Limit', side=side, input_quantity=input_quantity, stop_loss=0, reduce_only=True)
                time.sleep(2)
            elif (self.active_position_check() == 1) and (self.active_position_check() == 1):
                if (self.api.last_price() != current_price) and (self.api.last_price() != price):
                    print("last_price: " + str(self.api.last_price()))
                    print("current_price: " + str(current_price))
                    print("price: " + str(price))
                    current_price = self.api.last_price()
                    price = calc().calc_limit_price_difference(side, self.api.last_price(), self.limit_price_difference)
                    print("Price change: " + str(price))
                    self.api.change_order_price(price)
                    print("Order Price Updated: " + str(price))
                    print("")
                time.sleep(2)
            elif(self.active_position_check() == 0) and (self.active_order_check() == 0):
                flag = True
            else:
                print("Something's fucking wrong.")
                sleep(2)


"""
Module for managing a DTP 7001 remote value.

DPT 7.001.
"""
from __future__ import annotations

from typing import TYPE_CHECKING

from xknx.dpt import DPT2ByteUnsigned, DPTArray, DPTBinary
from xknx.exceptions import CouldNotParseTelegram

from .remote_value import AsyncCallbackType, GroupAddressesType, RemoteValue

if TYPE_CHECKING:
    from xknx.xknx import XKNX

class RemoteValueDpt2ByteUnsigned(RemoteValue[DPTArray, int]):
    """Abstraction for remote value of KNX DPT 7.001."""

    def __init__(
        self,
        xknx: XKNX,
        group_address: GroupAddressesType | None = None,
        group_address_state: GroupAddressesType | None = None,
        sync_state: bool | int | float | str = True,
        device_name: str | None = None,
        feature_name: str = "Value",
        after_update_cb: AsyncCallbackType | None = None,
    ):
        """Initialize remote value of KNX DPT 7.001."""
        super().__init__(
            xknx,
            group_address,
            group_address_state,
            sync_state=sync_state,
            device_name=device_name,
            feature_name=feature_name,
            after_update_cb=after_update_cb,
        )

    def payload_valid(self, payload: DPTArray | DPTBinary | None) -> DPTArray:
        """Test if telegram payload may be parsed."""
        if isinstance(payload, DPTArray) and len(payload.value) == 2:
            return payload
        raise CouldNotParseTelegram("Payload invalid", payload=str(payload))

    def to_knx(self, value: int) -> DPTArray:
        """Convert value to payload."""
        return DPTArray(DPT2ByteUnsigned.to_knx(value))

    def from_knx(self, payload: DPTArray) -> int:
        """Convert current payload to value."""
        return DPT2ByteUnsigned.from_knx(payload.value)


import boto3
from botocore.exceptions import ClientError
from Utility import dbController
from datetime import timedelta
from datetime import datetime
import time
import json

def org_lookup():
    """
    Check if any organizations whose data needs to be updated
    Check for timestamps > 6 months from today's date
    :return:
    """
    threshold = 180
    database = dbController.connect()["org"]
    current_time = datetime.now().date()
    for i in database.find():
        prev_time = datetime.strptime(i["last_updated"], "%Y-%m-%d").date()
        if int((current_time-prev_time).days) > threshold:
            push(i["org_key"])

def push(org_key):
    """
    Send notification to organization via AWS SES
    :param org_key:
    :return:
    """
    RECIPIENT = org_key
    SUBJECT = "[URGENT] Update organization info"
    print(RECIPIENT)

    with open("Utility/auth.json", "r") as file:
        creds = json.load(file)

    client = boto3.client('ses', region_name=creds["aws_region"], aws_access_key_id=creds["key_id"], aws_secret_access_key=creds["access_key"])

    BODY_HTML = """

Gentle reminder

It's been 6 months since your organization has updated the information we have on record. In order to ensure integrity of your information
        we need to perform verification.

In case if you no longer require our service, please contact us.

This email was sent on behalf of IJF (Illinois Joining Forces) via Bitlords.

        """

    CHARSET = "UTF-8"

    try:
        response = client.send_email(
            Destination={
                'ToAddresses': [
                    RECIPIENT,
                ],
            },
            Message={
                'Body': {
                    'Html': {
                        'Charset': CHARSET,
                        'Data': BODY_HTML,
                    },
                    'Text': {
                        'Charset': CHARSET,
                        'Data': "Update Reminder",
                    },
                },
                'Subject': {
                    'Charset': CHARSET,
                    'Data': SUBJECT,
                },
            },
            Source=creds["sender"],
        )
    # Display an error if something goes wrong.
    except ClientError as e:
        print(e.response['Error']['Message'])
    else:
        print("Email sent! Message ID:"),
        print(response['MessageId'])

if __name__ == "__main__":
    org_lookup()


from django.core.urlresolvers import reverse
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect, get_object_or_404
from .models import Reward

@login_required
def index(request):
    rewards = Reward.objects.all()
    template = 'rewards/index.html'

    if not request.user.is_authenticated:
        template = 'rewards/public.html'

    return render(request, template, {
        'rewards': rewards,
    })

@login_required
def redeem(request, reward_id):
    reward = get_object_or_404(Reward, pk=reward_id)
    profile = request.user.get_profile()

    try:
        reward.redeem(profile)
    except Exception as e:
        raise e
        messages.error(request, u'Insufficient points to redeem.')
    else:
        messages.success(request, u'Redeemed! You should receive an email shortly with the discount code.')

    return redirect(reverse('rewards:index'))


from guillotina.tests.utils import create_content
from guillotina.content import Resource
from guillotina_cms.interfaces import IBlocks
from guillotina_cms.behaviors.editors import Blocks
import asyncio
import pytest
import json

pytestmark = pytest.mark.asyncio

async def test_default_blocks_layout(cms_requester):
    async with cms_requester as requester:
        # now test it...
        response, status = await requester("GET", "/db/guillotina/")
        assert (
            len(
                response["guillotina_cms.interfaces.blocks.IBlocks"]["blocks_layout"][
                    "items"
                ]
            )
            == 2
        )
        assert "tile1" in response["guillotina_cms.interfaces.blocks.IBlocks"]["blocks"]

async def test_blocks_endpoint_gives_us_registered_blocks(cms_requester):
    async with cms_requester as requester:
        # now test it...
        response, status = await requester("GET", "/db/guillotina/@blocks")
        assert status == 200
        assert len(response) >= 1
        assert "@blocks/" in response[0]["@id"]

        response, status = await requester("GET", "/db/guillotina/@blocks/title")
        assert status == 200
        assert response["type"] == "object"

async def test_conversation_behavior_returns_instance(dummy_request):
    ob = create_content(Resource)
    behavior = IBlocks(ob)
    assert isinstance(behavior, Blocks)

async def test_storing_blocks_behavior_data(cms_requester):
    async with cms_requester as requester:
        resp, status = await requester(
            "POST",
            "/db/guillotina/",
            data=json.dumps(
                {
                    "@type": "Folder",
                    "title": "foobar",
                    "id": "foobar",
                    "@behaviors": ["guillotina_cms.interfaces.blocks.IBlocks"],
                    "guillotina_cms.interfaces.blocks.IBlocks": {
                        "blocks_layout": {"cols": ["#title-1", "#description-1"]},
                        "blocks": {"#title-1": {"@type": "title"}},
                    },
                }
            ),
        )
        assert status == 201

        resp, status = await requester("GET", "/db/guillotina/foobar")
        assert status == 200
        assert "guillotina_cms.interfaces.blocks.IBlocks" in resp
        assert "blocks_layout" in resp["guillotina_cms.interfaces.blocks.IBlocks"]


##class temp():
##    def __init__(self, name , age):
##        self.name = name
##        self.age = age
##    name = "Manisk"
##    age = 17
##    def ok(self,fx):
##        def modify(self):
##            print("Thank you for creating an object!")
##            fx()
##            print("Good Bye")
##            return modify
##    @ok
##    def show(self):
##        print(f'{self.name} is a {self.age} years old!')
##obj = temp("Manisk", 345)
##obj1=  temp("Goat", 8732)
##
##obj1.show()
##obj.show()

num = int(input("Number = "))
for i in range(2,num):
        if num % 1 == 0:
                print("No")
                break
else:
    print('Yes')


import os
import tempfile
import typing as t

from airflow.models import BaseOperator
from airflow.providers.apache.spark.hooks.spark_submit import SparkSubmitHook
from airflow.utils.context import Context

import sqlmesh
from sqlmesh.engines import commands
from sqlmesh.schedulers.airflow.operators.targets import (
    BaseTarget,
    SnapshotEvaluationTarget,
)

class SQLMeshSparkSubmitOperator(BaseOperator):
    """The operator which evaluates a SQLMesh model snapshot using a dedicated Spark job instance.

    It requires the "spark-submit" binary to be available in the PATH or the spark_home
    attribute to be set in the connection extras.

    Args:
        target: The target that will be executed by this operator instance.
        application_name: The name of the submitted application (default sqlmesh-spark).
        spark_conf: Spark configuration properties.
        connection_id: The Airflow connection ID as described in
            https://airflow.apache.org/docs/apache-airflow-providers-apache-spark/stable/connections/spark.html
            (default spark_default).
        total_executor_cores: (Srandalone & Mesos only) The total number of cores for all executors.
        executor_cores: (Standalone, YARN and Kubernetes only) The number of cores per executor.
        executor_memory: The amount of memory allocated to each executor (e.g. 1024M, 2G).
        driver_memory: The amount of memory allocated to the driver (e.g. 1024M, 2G).
        keytab: The full path to the file that contains the keytab.
        principal: The name of the Kerberos principal used for the keytab.
        proxy_user: The name of a user which should be impersonated when submitting the application.
        num_executors: The number of executors that will be allocateed to the application.
    """

    def __init__(
        self,
        *,
        target: BaseTarget,
        application_name: str = "sqlmesh-spark",
        spark_conf: t.Optional[t.Dict[str, t.Any]] = None,
        connection_id: str = "spark_default",
        total_executor_cores: t.Optional[int] = None,
        executor_cores: t.Optional[int] = None,
        executor_memory: t.Optional[str] = None,
        driver_memory: t.Optional[str] = None,
        keytab: t.Optional[str] = None,
        principal: t.Optional[str] = None,
        proxy_user: t.Optional[str] = None,
        num_executors: t.Optional[int] = None,
        **kwargs: t.Any,
    ) -> None:
        super().__init__(**kwargs)
        self._target = target
        self._application_name = application_name
        self._spark_conf = spark_conf or {}
        self._total_executor_cores = total_executor_cores
        self._executor_cores = executor_cores
        self._executor_memory = executor_memory
        self._driver_memory = driver_memory
        self._keytab = keytab
        self._principal = principal
        self._proxy_user = proxy_user
        self._num_executors = num_executors
        self._connection_id = connection_id
        self._application = os.path.join(
            os.path.dirname(os.path.abspath(sqlmesh.__file__)), "engines/spark/app.py"
        )
        self._hook: t.Optional[SparkSubmitHook] = None

    def execute(self, context: Context) -> None:
        command_payload = self._target.serialized_command_payload(context)
        with tempfile.TemporaryDirectory() as tmp:
            payload_file_path = os.path.join(tmp, commands.COMMAND_PAYLOAD_FILE_NAME)
            with open(payload_file_path, "w") as payload_fd:
                payload_fd.write(command_payload)

            if self._hook is None:
                if (
                    isinstance(self._target, SnapshotEvaluationTarget)
                    and self._target.snapshot.is_model
                ):
                    session_properties = self._target.snapshot.model.session_properties
                    executor_cores: t.Optional[int] = session_properties.pop(  # type: ignore
                        "spark.executor.cores", self._executor_cores
                    )
                    executor_memory: t.Optional[str] = session_properties.pop(  # type: ignore
                        "spark.executor.memory", self._executor_memory
                    )
                    driver_memory: t.Optional[str] = session_properties.pop(  # type: ignore
                        "spark.driver.memory", self._driver_memory
                    )
                    num_executors: t.Optional[int] = session_properties.pop(  # type: ignore
                        "spark.executor.instances", self._num_executors
                    )
                    spark_conf: t.Dict[str, t.Any] = {**self._spark_conf, **session_properties}
                else:
                    executor_cores = self._executor_cores
                    executor_memory = self._executor_memory
                    driver_memory = self._driver_memory
                    num_executors = self._num_executors
                    spark_conf = self._spark_conf

                self._hook = self._get_hook(
                    self._target.command_type,
                    payload_file_path,
                    self._target.ddl_concurrent_tasks,
                    spark_conf,
                    executor_cores,
                    executor_memory,
                    driver_memory,
                    num_executors,
                )
            self._hook.submit(self._application)
        self._target.post_hook(context)

    def on_kill(self) -> None:
        if self._hook is None:
            self._hook = self._get_hook(None, None, None, None, None, None, None, None)
        self._hook.on_kill()

    def _get_hook(
        self,
        command_type: t.Optional[commands.CommandType],
        command_payload_file_path: t.Optional[str],
        ddl_concurrent_tasks: t.Optional[int],
        spark_conf: t.Optional[t.Dict[str, t.Any]],
        executor_cores: t.Optional[int],
        executor_memory: t.Optional[str],
        driver_memory: t.Optional[str],
        num_executors: t.Optional[int],
    ) -> SparkSubmitHook:
        application_args = {
            "dialect": "spark",
            "command_type": command_type.value if command_type else None,
            "ddl_concurrent_tasks": ddl_concurrent_tasks,
            "payload_path": command_payload_file_path.split("/")[-1]
            if command_payload_file_path
            else None,
        }
        return SparkSubmitHook(
            conf=spark_conf,
            conn_id=self._connection_id,
            total_executor_cores=self._total_executor_cores,
            executor_cores=executor_cores,
            executor_memory=executor_memory,
            driver_memory=driver_memory,
            keytab=self._keytab,
            principal=self._principal,
            proxy_user=self._proxy_user,
            name=self._application_name,
            num_executors=num_executors,
            application_args=[f"--{k}={v}" for k, v in application_args.items() if v is not None],
            files=command_payload_file_path,
        )


#! python3
# customInvite.py - create customized invite documents using names stored in a txt file
# author: Falak Jain

import docx
from docx.shared import Pt

doc = docx.Document()
with open('guests.txt') as guests:
    for guest_name in guests.readlines():
        p = doc.add_paragraph()
        p.add_run('It would be a pleasure to have the company of').italic = True
        p.alignment = 1
        p.style.font.size = Pt(16)
        p = doc.add_paragraph()
        p.add_run(guest_name.rstrip('\n')).italic = True
        p.alignment = 1
        p = doc.add_paragraph()
        p.add_run('at 11010 Memory Lane on the Evening of').italic = True
        p.alignment = 1
        p = doc.add_paragraph()
        p.add_run('April 1st').italic = True
        p.alignment = 1
        p = doc.add_paragraph()
        p.add_run("at 7 o'clock").italic = True
        p.alignment = 1
        doc.add_page_break()
doc.save('invite.docx')

Working with PDF and Word Documents/customInvite.py


import json
from pathlib import Path
from web3 import Web3

# Connect to a local Ethereum node
w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8545'))

def get_contract_abi():
    certification_json_path = Path('../build/contracts/Certification.json')

    try:
        with open(certification_json_path, 'r') as json_file:
            certification_data = json.load(json_file)
            return certification_data.get('abi', [])
    except FileNotFoundError:
        print(f"Error: {certification_json_path} not found.")
        return []

contract_abi = get_contract_abi()
deployment_config_fpath = Path("../deployment_config.json")
with open(deployment_config_fpath, 'r') as json_file:
    address_data = json.load(json_file)
contract_address = address_data.get('Certification')

# Interact with the smart contract
contract = w3.eth.contract(address=contract_address, abi=contract_abi)


'''Faça um programa que pergunte o preço de três produtos e informe qual
produto você deve comprar, sabendo que a decisão é sempre pelo mais barato.'''

produto1 = float(input('Digite o valor do arroz: '))
produto2 = float(input('Digite o valor do feijão: '))
produto3 = float(input('Digite o valor do açúcar: '))

produtoMaisBarato = min(produto1, produto2, produto3)

if produtoMaisBarato == produto1:
    print ('O produto mais barato é o arroz')

elif produtoMaisBarato == produto2:
    print('O produto mais barato é o feijão')

else:
    print('O produto mais barato é o açúcar')


import sys,os
sys.path.append("../src/")
import env,requests

if len(sys.argv) < 2:
    print("Please enter USER_IP")
    exit()

userpoint = "http://" + sys.argv[1] + ":" + str(env.getenv('USER_PORT'))
auth_key = env.getenv('AUTH_KEY')

def post_to_user(url = '/', data={}):
    return requests.post(userpoint+url,data=data).json()

cons = os.listdir('/var/lib/lxc')
for con in cons:
    print("Update %s..."%(con))
    namesplit = con.split('-')
    user = namesplit[0]
    res = post_to_user('/user/uid/',{'username':user,'auth_key':auth_key})
    try:
        configfile = open('/var/lib/lxc/'+con+'/config','r')
    except:
        continue
    context = configfile.read()
    configfile.close()
    #print(context)
    #print(res['uid'])
    context = context.replace("docklet-br","docklet-br-"+str(res['uid']))
    newfile = open('/var/lib/lxc/'+con+'/config','w')
    newfile.write(context)
    newfile.close()


import os
import random
import shutil
import argparse

train_dir = r'train/'
test_dir = r'test/'

if __name__ == "__main__":
    parser = argparse.ArgumentParser( # usage='shuffle --train_dir=DIR_TRAIN --test_dir=DIR_TEST --ratio=TEST/TOTAL',
                                     prefix_chars='-', conflict_handler='error', add_help=True,
                                     description='small util to move samples in train_dir into a test_dir')
    parser.add_argument('--train_dir',type=str, help='where dataset store', required=True)
    parser.add_argument('--test_dir', type=str, help='where test set store', required=True)
    parser.add_argument('-r', '--ratio', type=float, default=0.3, help='test set size / dataset size')
    parser.add_argument('--path_prefix', type=str, default='./', help='the prefix of all the path')
    args = parser.parse_args()
    print(args)

    train_dir = os.path.join(args.path_prefix, args.train_dir)
    test_dir = os.path.join(args.path_prefix, args.test_dir)

    all_samples = []
    test_samples = []
    for base, dirs, filenames in os.walk(train_dir):
        for filename in filenames:
            all_samples.append(filename)
    print(all_samples)
    print(len(all_samples))
    indexes = random.sample(range(len(all_samples)), int(len(all_samples) * args.ratio))
    if not os.path.exists(test_dir):
        os.mkdir(test_dir)
    for i in indexes:
        shutil.move(train_dir + all_samples[i], test_dir + all_samples[i])


import json
import socket
import logging
from io import StringIO

FORMAT='{message} (at {filename}:{lineno})'
DEFAULT_ADDRESS=('127.0.0.1', 3003)

class CostumHandler(logging.StreamHandler):
  def __init__(self, server_address=DEFAULT_ADDRESS):
    super(CostumHandler, self).__init__()
    self.server = server_address
    self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

  def emit(self, record):
    msg = {
      'text': self.format(record),
      'levelno': record.levelno
    }
    print(msg)
    self.socket.sendto(json.dumps(msg).encode('utf-8'), self.server)

def getLogger():
  logger = logging.getLogger('service')
  handler = CostumHandler()
  formatter = logging.Formatter(FORMAT, style='{')
  handler.setFormatter(formatter)
  logger.addHandler(handler)
  logger.setLevel(logging.DEBUG)
  return logger


import os

class Configuration:
    def __init__(self, **entries):
        self.__dict__.update(entries)

def parse_version(args):
    """
    Parse the arguments and extract the version as a dictionary
    """
    versions = {}

    if args.get("--app-version"):
        versions['app'] = args.get("--app-version")
    if args.get("--env-version"):
        versions['env'] = args.get("--env-version")
    if args.get("--service-version"):
        versions['service'] = args.get("--service-version")
    if args.get("--static-version"):
        versions['static_files'] = args.get("--static-version")

    return versions

def parse_project(args):
    """
    Parse the arguments and return a Configuration object for the project.
    """
    dico = {}

    dico['config_file'] = os.path.abspath(os.path.expanduser(args['<config_file>']))
    dico['full_path'] = os.path.dirname(dico['config_file'])

    return Configuration(**dico)

def parse_prepare(args):
    """
    Parse the arguments and return a Configuration object for the preparation (before packaging).
    """
    dico = {}

    # path for building the packages. will be defaulted to temp folder if none.
    dico['build_path'] = args.get("--build")
    dico['architecture'] = args.get("--arch")
    dico['pip_options'] = args.get("--pip-options")
    dico['extra_description'] = args.get("--extra-description")

    return Configuration(**dico)

def parse_package(args):
    """
    """
    dico = {}

    dico['web_callback_url'] = args.get("--web-callback")
    dico['debs_path'] = args.get("--output") if args.get("--output") else os.getcwd()

    return Configuration(**dico)


"""
Файл для размещения общих настоек для работы сервисов и приложения.
"""
import os

# Стандартное количество дней за которое необходимо выдать информацию.
DEFAULT_DELTA_DAYS = int(os.getenv('DEFAULT_DELTA_DAYS'))

# Максимальное количество дней за которое сервис может выдать информацию.
MAX_DELTA_DAYS = int(os.getenv('MAX_DELTA_DAYS'))

# Режим в котором приложение работает
APP_MODE = os.getenv('APP_MODE')


from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals

import os
import sys
import warnings

# TODO: gsutil-beta: Distribute a pylint rc file.

ver = sys.version_info
if (ver.major == 2 and ver.minor < 7) or (ver.major == 3 and ver.minor < 5):
  sys.exit('gsutil requires python 2.7 or 3.5+.')

# setup a string to load the correct httplib2
if sys.version_info.major == 2:
  submodule_pyvers = 'python2'
else:
  submodule_pyvers = 'python3'

def OutputAndExit(message):
  sys.stderr.write('%s\n' % message)
  sys.exit(1)

def _fix_google_module():
  """Reloads the google module to prefer our third_party copy.

  When Python is not invoked with the -S option, it may preload the google module via .pth file.
  This leads to the "site_packages" version being preferred over gsutil "third_party" version.
  To force the "third_party" version, insert the path at the start of sys.path and reload the google module.

  This is a hacky. Reloading is required for the rare case that users have
  google-auth already installed in their Python environment.
  Note that this reload may cause an issue for Python 3.5.3 and lower
  because of the weakref issue, fixed in Python 3.5.4:
  https://github.com/python/cpython/commit/9cd7e17640a49635d1c1f8c2989578a8fc2c1de6.
  """
  if 'google' not in sys.modules:
    return
  import importlib  # pylint: disable=g-import-not-at-top
  importlib.reload(sys.modules['google'])

GSUTIL_DIR = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
if not GSUTIL_DIR:
  OutputAndExit('Unable to determine where gsutil is installed. Sorry, '
                'cannot run correctly without this.\n')

# The wrapper script adds all third_party libraries to the Python path, since
# we don't assume any third party libraries are installed system-wide.
THIRD_PARTY_DIR = os.path.join(GSUTIL_DIR, 'third_party')
VENDORED_DIR = os.path.join(THIRD_PARTY_DIR, 'vendored')

# Flag for whether or not an import wrapper is used to measure time taken for
# individual imports.
MEASURING_TIME_ACTIVE = False

# Filter out "module was already imported" warnings that get printed after we
# add our bundled version of modules to the Python path.
warnings.filterwarnings('ignore',
                        category=UserWarning,
                        message=r'.* httplib2 was already imported from')
warnings.filterwarnings('ignore',
                        category=UserWarning,
                        message=r'.* oauth2client was already imported from')

# List of third-party libraries. The first element of the tuple is the name of
# the directory under third_party and the second element is the subdirectory
# that needs to be added to sys.path.
THIRD_PARTY_LIBS = [
    ('argcomplete', ''),  # For tab-completion (gcloud installs only).
    ('mock', ''),
    ('funcsigs', ''),  # mock dependency
    ('google-reauth-python', ''),  # Package name: google_reauth
    ('pyu2f', ''),  # google_reauth dependency
    ('pyasn1', ''),  # oauth2client dependency
    ('pyasn1-modules', ''),  # oauth2client dependency
    ('rsa', ''),  # oauth2client dependency
    ('apitools', ''),
    ('gcs-oauth2-boto-plugin', ''),
    ('fasteners', ''),  # oauth2client and apitools dependency
    ('monotonic', ''),  # fasteners dependency
    ('pyparsing', ''),  # httplib2 dependency
    ('httplib2', submodule_pyvers),
    ('retry-decorator', ''),
    ('six', ''),  # Python 2 / 3 compatibility dependency
    ('cachetools', 'src'),  # google auth dependency
    ('urllib3', 'src'),  # requests dependency
    ('charset_normalizer', ''),  # requests dependency
    ('chardet', ''),  # requests dependency
    ('certifi', ''),  # requests dependency
    ('idna', ''),  # requests dependency
    ('requests', ''),  # google auth dependency
    ('google-auth-library-python', ''),
]

# The wrapper script adds all third_party libraries to the Python path, since
# we don't assume any third party libraries are installed system-wide.
#
# Note that vendored libraries (e.g. Boto) are added to the Python path in
# gslib/__init__.py, as they will always be present even when bypassing this
# script and invoking gslib.__main__.py's main() method directly.
THIRD_PARTY_DIR = os.path.join(GSUTIL_DIR, 'third_party')
for libdir, subdir in THIRD_PARTY_LIBS:
  if not os.path.isdir(os.path.join(THIRD_PARTY_DIR, libdir)):
    OutputAndExit(
        'There is no %s library under the gsutil third-party directory (%s).\n'
        'The gsutil command cannot work properly when installed this way.\n'
        'Please re-install gsutil per the installation instructions.' %
        (libdir, THIRD_PARTY_DIR))
  sys.path.insert(0, os.path.join(THIRD_PARTY_DIR, libdir, subdir))

CRCMOD_PATH = os.path.join(THIRD_PARTY_DIR, 'crcmod', submodule_pyvers)
CRCMOD_OSX_PATH = os.path.join(THIRD_PARTY_DIR, 'crcmod_osx')
try:
  # pylint: disable=g-import-not-at-top
  import crcmod
except ImportError:
  # Note: the bundled crcmod module under THIRD_PARTY_DIR does not include its
  # compiled C extension, but we still add it to sys.path because other parts of
  # gsutil assume that at least the core crcmod module will be available.
  local_crcmod_path = (CRCMOD_OSX_PATH if 'darwin' in str(sys.platform).lower()
                       else CRCMOD_PATH)
  sys.path.insert(0, local_crcmod_path)

def RunMain():
  _fix_google_module()
  # pylint: disable=g-import-not-at-top
  import gslib.__main__
  sys.exit(gslib.__main__.main())

if __name__ == '__main__':
  RunMain()


import textwrap
from typing import Optional, Callable
from urllib.parse import urlparse

import pytest
from tests.fixtures.language_container_fixture import export_slc, flavor_path
from tests.fixtures.database_connection_fixture import pyexasol_connection
from _pytest.fixtures import FixtureRequest
from click.testing import CliRunner
from exasol_script_languages_container_tool.lib.tasks.export.export_info import ExportInfo
from pyexasol import ExaConnection, ExaConnectionFailedError
from pytest_itde import config

from exasol_transformers_extension import deploy
from tests.utils.parameters import bucketfs_params
from tests.utils.revert_language_settings import revert_language_settings

def assert_udf_running(language_alias: str,
                       schema: str,
                       connection_factory: Callable[[config.Exasol], ExaConnection],
                       exasol_config: config.Exasol):
    # We need a new connection to get the new system value for the SCRIPT_LANGUAGES parameter
    with connection_factory(exasol_config) as pyexasol_connection:
        pyexasol_connection.execute(f"OPEN SCHEMA {schema}")
        pyexasol_connection.execute(textwrap.dedent(f"""
        CREATE OR REPLACE {language_alias} SCALAR SCRIPT "TEST_UDF"()
        RETURNS BOOLEAN AS

        def run(ctx):
            return True

        /
        """))
        result = pyexasol_connection.execute('SELECT "TEST_UDF"()').fetchall()
        assert result[0][0] == True

def call_language_definition_deployer_cli(dsn: str,
                                          container_path: Optional[str],
                                          language_alias: str,
                                          version: Optional[str],
                                          exasol_config: config.Exasol,
                                          bucketfs_config: config.BucketFs,
                                          use_ssl_cert_validation: bool = False):
    parsed_url = urlparse(bucketfs_config.url)
    args_list = [
        "language-container",
        "--bucketfs-name", bucketfs_params.name,
        "--bucketfs-host", parsed_url.hostname,
        "--bucketfs-port", parsed_url.port,
        "--bucketfs-use-https", False,
        "--bucketfs-user", bucketfs_config.username,
        "--bucketfs-password", bucketfs_config.password,
        "--bucket", bucketfs_params.bucket,
        "--path-in-bucket", bucketfs_params.path_in_bucket,
        "--dsn", dsn,
        "--db-user", exasol_config.username,
        "--db-pass", exasol_config.password,
        "--language-alias", language_alias
    ]
    if use_ssl_cert_validation:
        args_list += [
            "--use-ssl-cert-validation"
        ]
    else:
        args_list += [
            "--no-use-ssl-cert-validation"
        ]
    if version is not None:
        args_list += [
            "--version", version,
        ]
    if container_path is not None:
        args_list += [
            "--container-file", container_path,
        ]
    runner = CliRunner()
    result = runner.invoke(deploy.main, args_list)
    return result

def create_schema(pyexasol_connection: ExaConnection, schema: str):
    pyexasol_connection.execute(f"DROP SCHEMA IF EXISTS {schema} CASCADE;")
    pyexasol_connection.execute(f"CREATE SCHEMA {schema};")

def test_language_container_deployer_cli_with_container_file(
        request: FixtureRequest,
        export_slc: ExportInfo,
        pyexasol_connection: ExaConnection,
        connection_factory: Callable[[config.Exasol], ExaConnection],
        exasol_config: config.Exasol,
        bucketfs_config: config.BucketFs
):
    test_name: str = request.node.name
    schema = test_name
    language_alias = f"PYTHON3_TE_{test_name.upper()}"
    container_path = export_slc.cache_file
    version = None
    create_schema(pyexasol_connection, schema)
    dsn = f"{exasol_config.host}:{exasol_config.port}"
    with revert_language_settings(pyexasol_connection):
        result = call_language_definition_deployer_cli(dsn=dsn,
                                                       container_path=container_path,
                                                       language_alias=language_alias,
                                                       version=version,
                                                       exasol_config=exasol_config,
                                                       bucketfs_config=bucketfs_config)
        assert result.exit_code == 0 and result.exception == None and result.stdout == ""
        assert_udf_running(connection_factory=connection_factory,
                           exasol_config=exasol_config,
                           language_alias=language_alias,
                           schema=schema)

def test_language_container_deployer_cli_by_downloading_container(
        request: FixtureRequest,
        pyexasol_connection: ExaConnection,
        connection_factory: Callable[[config.Exasol], ExaConnection],
        exasol_config: config.Exasol,
        bucketfs_config: config.BucketFs
):
    test_name: str = request.node.name
    schema = test_name
    language_alias = f"PYTHON3_TE_{test_name.upper()}"
    container_path = None
    version = "0.5.0"
    create_schema(pyexasol_connection, schema)
    dsn = f"{exasol_config.host}:{exasol_config.port}"
    with revert_language_settings(pyexasol_connection):
        result = call_language_definition_deployer_cli(
            dsn=dsn,
            container_path=container_path,
            language_alias=language_alias,
            version=version,
            bucketfs_config=bucketfs_config,
            exasol_config=exasol_config
        )
        assert result.exit_code == 0 and result.exception == None and result.stdout == ""
        assert_udf_running(connection_factory=connection_factory,
                           exasol_config=exasol_config,
                           language_alias=language_alias,
                           schema=schema)

def test_language_container_deployer_cli_with_missing_container_option(
        request: FixtureRequest,
        pyexasol_connection: ExaConnection,
        exasol_config: config.Exasol,
        bucketfs_config: config.BucketFs
):
    test_name: str = request.node.name
    language_alias = f"PYTHON3_TE_{test_name.upper()}"
    dsn = f"{exasol_config.host}:{exasol_config.port}"
    with revert_language_settings(pyexasol_connection):
        result = call_language_definition_deployer_cli(
            dsn=dsn,
            container_path=None,
            language_alias=language_alias,
            version=None,
            bucketfs_config=bucketfs_config,
            exasol_config=exasol_config
        )
        expected_exception_message = "You should specify either the release version to " \
                                     "download container file or the path of the already " \
                                     "downloaded container file."
        assert result.exit_code == 1 \
               and result.exception.args[0] == expected_exception_message \
               and type(result.exception) == ValueError

def test_language_container_deployer_cli_with_check_cert(
        request: FixtureRequest,
        export_slc: ExportInfo,
        pyexasol_connection: ExaConnection,
        connection_factory: Callable[[config.Exasol], ExaConnection],
        exasol_config: config.Exasol,
        bucketfs_config: config.BucketFs
):
    use_ssl_cert_validation = True
    expected_exception_message = 'Could not connect to Exasol: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify ' \
                                 'failed: self signed certificate in certificate chain (_ssl.c:1131)'
    test_name: str = request.node.name
    schema = test_name
    language_alias = f"PYTHON3_TE_{test_name.upper()}"
    container_path = export_slc.cache_file
    version = None
    create_schema(pyexasol_connection, schema)
    dsn = f"{exasol_config.host}:{exasol_config.port}"
    with revert_language_settings(pyexasol_connection):
        result = call_language_definition_deployer_cli(dsn=dsn,
                                                       container_path=container_path,
                                                       language_alias=language_alias,
                                                       version=version,
                                                       exasol_config=exasol_config,
                                                       bucketfs_config=bucketfs_config,
                                                       use_ssl_cert_validation=use_ssl_cert_validation)

        assert result.exit_code == 1 \
            and result.exception.args[0].message in expected_exception_message \
            and type(result.exception) == ExaConnectionFailedError


import tkinter
from tkinter import *
from datetime import date, timedelta
import pickle
import sys
from vw.vwgui import VWGui
import hashlib

class VWActivate(tkinter.Frame):
    def __init__(self, parent, expire_date, status):
        _style = ttk.Style()
        _style.theme_use('alt')
        _style.configure('TFrame', background='maroon')
        Frame.__init__(self, parent, background='#000000')
        self.parent = parent
        self.parent.minsize(300, 80)
        self.parent.geometry("300x80+300+300")
        self.expire_date = expire_date
        self.dead_date = expire_date + timedelta(days=30)
        self.status = status
        self.parent.grid_columnconfigure(1, weight=1)
        self.parent.grid_rowconfigure(0, weight=1)
        self.parent.title("续期请求")

        self.label = Label(self.parent, text="软件在{}到期，请在{}前完成续期，\n过期将无法使用。谢谢！".\
            format(self.expire_date, self.dead_date, padx=5))
        self.register_label = Label(self.parent, text='注册码', padx=5)
        self.register_entry = Entry()
        self.register_button = Button(text='注册', command=self.activate)
        self.skip_button = Button(text='跳过', command=self.skip)

        if status == 1:
            self.skip_button.config(state='active')
        elif status == -1:
            self.skip_button.config(state='disabled')

        self.label.grid(row=0, columnspan=4)
        self.register_label.grid(row=1, column=0)
        self.register_entry.grid(row=1, column=1, sticky='we', padx=5)
        self.register_button.grid(row=1, column=2)
        self.skip_button.grid(row=1, column=3)

    def activate(self):
        input_code = self.register_entry.get().strip()
        if len(input_code) < 10:
            tkinter.messagebox.showwarning('注册码错误', '注册码位数有误，请检查')
            return
        if input_code in hashlib.md5(str.encode('xddd{}'.format(self.expire_date.year))).hexdigest():
            new_expire_date = date(self.expire_date.year + 1, self.expire_date.month, self.expire_date.day)
            pickle.dump(new_expire_date, open('ttime', 'wb'))
            tkinter.messagebox.showinfo('注册成功', '注册成功，感谢您续期！软件使用期更新为{}！'.format(new_expire_date))
            self.destroy()
            self.parent.destroy()
            VWGui(Tk())
        else:
            tkinter.messagebox.showwarning('注册码错误', '注册码错误，请检查')

    def skip(self):
        self.destroy()
        self.parent.destroy()
        VWGui(Tk())


from loguru import logger
from flask import Flask
from flask import jsonify, request
from core.Storage import BaseStorage
from core.Indexer import Indexer
from threading import Thread

app = Flask(__name__)
base_storage = BaseStorage()

def scan_handler(domain, max_depth, workers):
    max_depth, workers = int(max_depth), int(workers)
    indexer = Indexer(base_storage, domain, max_depth=max_depth, workers=workers)
    indexer.storage.mongo_client.drop_database('crawler')

@app.route('/scan')
def scan():
    domain = request.args.get('domain')
    max_depth = request.args.get('max_depth') or '2'
    workers = request.args.get('workers') or '5'

    Thread(target=scan_handler, args=(domain, max_depth, workers)).start()
    return jsonify({
        "status": "ok"
    })

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000, debug=False)


import requests

def reverse_geocode(lat, lon):
    url = "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?f=pjson&featureTypes=&location=" + str(lon) + "," + str(lat)

    req = requests.get(url)

    query=req.json()

    location = {}

    location['city'] = query['address']['City']
    location['state'] = query['address']['Region']
    location['country']=query['address']['CountryCode']

    return location

print(reverse_geocode('33.522960010097982','-112.0232999405623'))


from django.urls import path
from .views import *
from django.contrib.auth.views import LogoutView

urlpatterns = [
    path('', landing_page, name='landing_page'),
    path('home/', home, name='home'),

    path('estacionesTransformadoras/', EstacionesTransformadorasList.as_view(), name="estacionesTransformadoras"),
    path('estacionesTransformadorasCreate/', EstacionesTransformadorasCreate.as_view(), name="estacionesTransformadorasCreate"),
    path('estacionesTransformadorasUpdate/<int:pk>', EstacionesTransformadorasUpdate.as_view(), name="estacionesTransformadorasUpdate"),
    path('estacionesTransformadorasDelete/<int:pk>', EstacionesTransformadorasDelete.as_view(), name="estacionesTransformadorasDelete"),
    path('verDetalleEETT/<nombre>/', verDetalleEETT, name='verDetalleEETT'),

    path('equiposRed/', EquipoRedList.as_view(), name="equiposRed"),
    path('equipoRedCreate/', EquipoRedCreate.as_view(), name="equipoRedCreate"),
    path('equipoRedUpdate/<int:pk>/', EquipoRedUpdate.as_view(), name="equipoRedUpdate"),
    path('equipoRedDelete/<int:pk>/', EquipoRedDelete.as_view(), name="equipoRedDelete"),

    path('equiposTelecontrol/', EquipoTelecontrolList.as_view(), name="equiposTelecontrol"),
    path('equipoTelecontrolCreate/', EquipoTelecontrolCreate.as_view(), name="equipoTelecontrolCreate"),
    path('equipoTelecontrolUpdate/<int:pk>/', EquipoTelecontrolUpdate.as_view(), name="equipoTelecontrolUpdate"),
    path('equipoTelecontrolDelete/<int:pk>/', EquipoTelecontrolDelete.as_view(), name="equipoTelecontrolDelete"),

    path('equiposProteccion/', EquipoProteccionList.as_view(), name="equiposProteccion"),
    path('equipoProteccionCreate/', EquipoProteccionCreate.as_view(), name="equipoProteccionCreate"),
    path('equipoProteccionUpdate/<int:pk>/', EquipoProteccionUpdate.as_view(), name="equipoProteccionUpdate"),
    path('equipoProteccionDelete/<int:pk>/', EquipoProteccionDelete.as_view(), name="equipoProteccionDelete"),

    path('userLogin/', userLogin, name='userLogin'),
    path('userRegister/', userRegister, name='userRegister'),
    path('userLogout/', LogoutView.as_view(template_name="mainApp/userLogout.html"), name="userLogout"),
    path('editProfile/', editProfile, name='editProfile'),
    path('editAvatar/', editAvatar, name='editAvatar'),

    path('listSearchResults/', search, name='listSearchResults'),

    path('aboutMe/', aboutMe ,name="aboutMe"),
]


"""Contains functions for running a no rebirth challenge."""
from classes.features import Features
import coordinates as coords
import usersettings as userset
import time

class Rebirth(Features):
    """Contains functions for running a no rebirth challenge."""

    final_aug = False

    def first_rebirth(self):
        """Procedure for first rebirth."""
        end = time.time() + 3 * 60
        ss_assigned = False
        diggers = [x for x in range(1, 13)]
        self.nuke()
        time.sleep(2)
        self.fight()
        self.adventure(highest=True)
        while self.check_pixel_color(*coords.COLOR_TM_LOCKED):
            if not ss_assigned:
                time.sleep(1)
                self.augments({"SS": 1}, 3e12)
                ss_assigned = True
            self.wandoos(True)
            self.nuke()
            time.sleep(2)
            self.fight()

        self.time_machine(1e9, magic=True)
        self.augments({"DS": 1}, 1e12)
        self.gold_diggers(diggers)
        self.adventure(itopod=True, itopodauto=True)

        while self.check_pixel_color(*coords.COLOR_BM_LOCKED) or self.check_pixel_color(*coords.COLOR_BM_LOCKED_ALT):
            self.wandoos(True)
            self.nuke()
            time.sleep(2)
            self.fight()
            self.gold_diggers(diggers)
        self.blood_magic(8)
        self.toggle_auto_spells(drop=False, number=False)
        while time.time() < end - 90:
            self.wandoos(True)
            self.nuke()
            time.sleep(2)
            try:
                current_boss = int(self.get_current_boss())
                if current_boss > 36:
                    self.augments({"SS": 0.67, "DS": 0.33}, self.get_idle_cap(1))
            except ValueError:
                print("couldn't get current boss")
            self.gold_diggers(diggers)

        while True:
            self.wandoos(True)
            self.nuke()
            time.sleep(1)
            try:
                current_boss = int(self.get_current_boss())
                if current_boss > 45:
                    if not self.final_aug:
                        self.reclaim_aug()
                        self.final_aug = True
                    self.augments({"SM": 0.67, "AA": 0.33}, self.get_idle_cap(1))
            except ValueError:
                print("couldn't get current boss")
            self.fight()
            self.gold_diggers(diggers)

            if time.time() > end and not self.check_challenge():
                return

    def check_challenge(self):
        """Check if a challenge is active."""
        self.rebirth()
        self.click(*coords.CHALLENGE_BUTTON)
        time.sleep(userset.LONG_SLEEP)
        return True if self.check_pixel_color(*coords.COLOR_CHALLENGE_ACTIVE) else False

    def rebirth_challenge(self):
        """Defeat target boss."""
        self.first_rebirth()
        return