Exemple #1
0
def get_sigml_neg(word, pos, neg, WH, context, matches, sigml):
    #Fetches SiGML of word
    currentSign = sign.Sign(word, pos, neg, WH, context, matches)
    currentSigml = currentSign.get_full_sigml()
    sigml += currentSigml + '\n'
    #Fetches negation state
    neg = currentSign.neg
    return sigml, neg
Exemple #2
0
def game_init():
    # Generate keys
    signature_verify = sign.Sign()

    uid = str(uuid.uuid4())  # generate a unique ID to identify ourselves

    # Start a local server for receiving messages from other players
    if len(sys.argv) > 1 and type(sys.argv[1]) == str:
        server_at = sys.argv[1]
    else:
        server_at = raw_input("Starting local server...hostname:port? ")
    hostname, port = server_at.split(':')
    port = int(port)
    if port < 1000 or port > 65535:
        print "Port must be 1000-65535"
        return
    gp = gameplay.Gameplay(uid)
    server.run_server(hostname, port, gp)

    # And connect to other players' servers to send messages.  This two-way
    # network structure should simplify trying to figure out who we're already
    # connected to, etc.  Each player should just make a connection to each other,
    # so in the end there should be 2*N connections.
    print "Welcome to crypto-settlers!  To begin, enter [ip:port] of each user who will be playing the game."
    player_ips = []
    player_clients = []
    while True:
        ip = raw_input("Player ip:port [or enter to finish]: ")
        if ip == "": break
        player_ips.append(ip)
    print "Connecting..."
    for addr in player_ips:
        ip, port = addr.split(':')
        port = int(port)
        new_client = client.SettlersNetworkClient(ip, port, signature_verify,
                                                  uid)
        success = new_client.connect()
        # Loop around and try to connect until all players are online
        while not success:
            print "Couldn't connect to ", addr, ", trying again in 2s..."
            time.sleep(2)
            success = new_client.connect()
        # Send public key
        new_client.send_key()
        # Add connection to a list
        player_clients.append(new_client)
    print "All connected!"

    gp.setup_client_connections(player_clients)
    gp.run()

    print "Game is finished! Disconnecting clients..."
    for c in player_clients:
        c.disconnect()

    print "Shutting down local server..."
    server.shutdown_server()
    sys.exit(0)
Exemple #3
0
    def handle(self):
        global gp
        signer = sign.Sign()
        public_key = ""  # for this particular client
        client_uid = ""
        while True:
            try:
                data = self.rfile.readline().strip()
                if data != "":
                    json_data = json.loads(data)
                    if public_key == "":
                        try:
                            split = json.loads(json_data['message'])
                            client_uid = split['uid']
                            if type(split) == dict and 'public_key' in split:
                                public_key = split['public_key']
                                # Respond with our UID
                                self.wfile.write(
                                    json.dumps({
                                        "success": True,
                                        "uid": gp.uid
                                    }) + '\n')
                            else:
                                print "Error: client first needs to send public key"
                                self.wfile.write(
                                    json.dumps({"success": False}) + '\n')
                                return
                        except Exception, e:
                            print "Error: client failed in sending public key", e
                            self.wfile.write(
                                json.dumps({"success": False}) + '\n')
                            return
                    # We have a public key for this client - verify that it matches
                    # Also verify that this client is not trying to spoof their UID
                    verified = signer.verify(public_key,
                                             json_data['signature'],
                                             json_data['message'])

                    if not verified:
                        self.wfile.write(json.dumps({"success": False}) + '\n')
                        return

                    # This expected client is who they say they are..
                    verified_message_data = json.loads(json_data['message'])
                    if verified_message_data['uid'] != client_uid:
                        print "UID is not verified"
                        self.wfile.write(json.dumps({"success": False}) + '\n')
                        return
                    # Handle the request
                    if gp is not None:
                        gp.handle_message(verified_message_data)
                else:
                    return
Exemple #4
0
def shareImage(request):
    try:
        openId = ""
        if 'openId' in request.GET and request.GET['openId']:
            openId = request.GET['openId']
        token_info = certificate.certificate()
        appId = token_info.appId
        sigurate = sign.Sign(
            token_info.jsapi_ticket,
            "http://" + request.get_host() + request.get_full_path())
        sigurate_ret = sigurate.sign()
        data = "{'timestamp':'%s','nonceStr':'%s','signature':'%s'}" % (
            sigurate_ret['timestamp'], sigurate_ret['nonceStr'],
            sigurate_ret['signature'])
        return render_to_response(
            'upload_image.html', {
                'sigurate_inf': json.dumps(data),
                'appId': json.dumps(appId),
                'openId': json.dumps(openId)
            })
    except Exception, Argument:
        traceback.print_exc()
Exemple #5
0
    else:
        userInput = lines[0].strip("\n").split(" ")

    #Explains sign
    if userInput[0] == 'explain':
        #User did not specify sign to be explained
        if len(userInput) == 1:
            print("Please specify a sign to be explained")
        #Sign is specified by user
        else:
            #Sign is not in the database
            if not userInput[1].upper() in infoSigns:
                print("Please specify a sign that is in the database ()")
            #Sign is in the database
            else:
                fa.explainSign(sign.Sign(str(userInput[1])).get_gloss())

    #Fingerspells input
    elif userInput[0] == 'spell':
        #User did not specify input to be fingerspelled
        if len(userInput) == 1:
            print("Please specify input to be fingerspelled")
        #Input is specified by user
        else:
            main(userInput[1], str(userInput[0]))

    #Adds a sign to dictionary
    elif userInput[0] == 'add':
        #User did not specify all values
        if len(userInput) < 5:
            print(
import bluetooth
import sign

hostMACAddress = 'mac_address_here'  # The MAC address of a Bluetooth adapter on the server. The server might have multiple Bluetooth adapters.
port = 3
backlog = 1
size = 1024
server = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
server.bind((hostMACAddress, port))
server.listen(backlog)
s_display = sign.Sign()

display_activated = False

try:
    client, clientInfo = server.accept()
    while 1:
        data = client.recv(size)
        if data:
            print(data)
            if display_activated:
                s_display.stop()
            s_display.scrollPut(data + "     ")
            s_display.scroll()
            client.send(data)  # Echo back to client
            display_activated = True
except:
    print("Client disconnected?")
    client.close()
    server.close()
TWITTER_ACCESS_TOKEN_SECRET = keys["token_secret"]

APP_ID = keys["app_id"]

twitter = OAuth1Session(
    TWITTER_APP_KEY,
    client_secret=TWITTER_APP_KEY_SECRET,
    resource_owner_key=TWITTER_ACCESS_TOKEN,
    resource_owner_secret=TWITTER_ACCESS_TOKEN_SECRET
)

api = flask.Flask(__name__)

skill = pyalexa.Skill(app_id=APP_ID)

SIGN = sign.Sign("sign", 8800)

def get_points():
    points = {}
    try:
        with open('.points') as p:
            points = json.load(p)
    except FileNotFoundError:
        with open('.points', 'w') as p:
            json.dump({}, p)
    return points

def add_point(person):
    points = get_points()
    person = person.lower()
    if person in points:
Exemple #8
0
    if len(sys.argv) == 1:
        print("Please specify a glossed sentence to be signed")

    #Explains sign
    elif sys.argv[1] == 'explain':
        #User did not specify sign to be explained
        if len(sys.argv) == 2:
            print("Please specify a sign to be explained")
        #Sign is specified by user
        else:
            #Sign is not in the database
            if not sys.argv[2] in infoSigns:
                print("Please specify a sign that is in the database ()")
            #Sign is in the database
            else:
                fm.explainSign(sign.Sign(str(sys.argv[2])).get_gloss())

    #Fingerspells input
    elif sys.argv[1] == 'spell':
        #User did not specify input to be fingerspelled
        if len(sys.argv) == 2:
            print("Please specify input to be fingerspelled")
        #Input is specified by user
        else:
            main(sys.argv[2], str(sys.argv[1]))

    #Adds a sign to dictionary
    elif sys.argv[1] == 'add':
        #User did not specify all values
        if len(sys.argv) < 5:
            print(
Exemple #9
0
def processSentence(context, flag):
    abc = [
        'A', 'AA', 'B', 'BB', 'C', 'CC', 'D', 'DD', 'E', 'EE', 'F', 'FF', 'G',
        'GG', 'H', 'I', 'II', 'J', 'K', 'KK', 'L', 'LL', 'M', 'MM', 'N', 'NN',
        'O', 'OO', 'P', 'PP', 'Q', 'QQ', 'R', 'RR', 'S', 'SS', 'T', 'TT', 'U',
        'UU', 'V', 'W', 'WW', 'X', 'Y', 'YY', 'Z', 'ZZ'
    ]

    infoSigns = pickle.load(open("dictFile.p", "rb"))

    #Detects WH-questions
    wh = whDetect(context)
    #Detects alternative questions
    alt = altDetect(context)

    sigml = ''
    neg = None
    left = False
    end = len(context)
    #Generates markup for the signs in the sentence
    for i, item in enumerate(context):
        word = item[0]
        pos = item[1]
        word = word.upper()
        partly = False

        #Automatically spells single letters
        if word in abc:
            word += '_VINGERSPELLEN'

        #Handles questionmark
        if word == '?':
            #Adds palm up movement when handling WHquestions
            if wh:
                word = 'PALM_OMHOOG'
            #And nothing needs to happen after yes/no questions, so skip the question mark for these
            else:
                continue

        # or alternative questiones
        if word == ',':
            word = 'Q_PART_ALT'

        #Starts negation
        if word == 'N(':
            neg = True
            continue

        #Starts affirmation
        if word == 'A(':
            neg = False
            continue

        #Stops negation and affirmation
        if word == ')N' or word == ')A':
            neg = None
            continue

        #Stores the index
        if "3B" in word:
            left = True

        if word.isnumeric():
            sigml, neg = sign_number(word, neg, wh, sigml, context, infoSigns)
        else:
            #Adds word to matches if partly in dict
            partly, matches = find_matches(word, context, infoSigns)

        #Fingerspell word if not in dict at all, it is not a number, or spell-flag is encountered
        if (not partly and not word.isnumeric()) or flag == 'spell':
            sigml, neg = fingerspell(word, neg, wh, sigml)
        #Finds the sign if a word is partly in the dict
        elif partly:
            currentSign = sign.Sign(word, pos, neg, wh, context, matches)
            #Alternative questions: turn body right
            if alt == True:
                checkL, altNew = leftsideOr(alt, i, word, pos, context)
                #Rotate body left
                if checkL:
                    currentSign.nonmanual.append('<hnm_body tag = "RL"/>')
                #Updates alternative question status
                else:
                    alt = altNew
            #Alternative questions: turn body left
            elif alt == False:
                checkR, altNew = rightsideOr(alt, i, word, pos, context)
                #Rotate body right
                if checkR:
                    currentSign.nonmanual.append('<hnm_body tag = "RR"/>')
                #Updates alternative question status
                else:
                    alt = altNew

            #Performs the sign on the left side with the left hand if the index is 3B
            elif left and (pos == "NOUN" or pos == "ADJ"):
                currentSign = currentSign.mirror()
                left = False
            elif pos == "VERB" and len(item) > 2:
                currentSign.directional(item[2:])
            #Turns the body and head towards INDEX_3A and INDEX_3B
            elif pos != "ADJ":
                if (pos == "NOUN" and i + 1 != end) and (i != 0 and end != 1):
                    if context[i + 1][0] == "INDEX_3A":
                        currentSign.nonmanual.append('<hnm_body tag = "RR"/>')
                        #the head turn is repeated this often to make it look more natural
                        currentSign.nonmanual.append('<hnm_head tag="SR"/>')
                        currentSign.nonmanual.append('<hnm_head tag="SR"/>')
                        currentSign.nonmanual.append('<hnm_head tag="SR"/>')
                        currentSign.nonmanual.append('<hnm_head tag="SR"/>')
                    elif context[i + 1][0] == "INDEX_3B":
                        currentSign.nonmanual.append('<hnm_body tag = "RL"/>')
                        #the head turn is repeated this often to make it look more natural
                        currentSign.nonmanual.append('<hnm_head tag="SL"/>')
                        currentSign.nonmanual.append('<hnm_head tag="SL"/>')
                        currentSign.nonmanual.append('<hnm_head tag="SL"/>')
                        currentSign.nonmanual.append('<hnm_head tag="SL"/>')
                elif word == "INDEX_3A":
                    currentSign.nonmanual.append('<hnm_body tag = "RR"/>')
                    #the head turn is repeated this often to make it look more natural
                    currentSign.nonmanual.append('<hnm_head tag="SR"/>')
                    currentSign.nonmanual.append('<hnm_head tag="SR"/>')
                    currentSign.nonmanual.append('<hnm_head tag="SR"/>')
                    currentSign.nonmanual.append('<hnm_head tag="SR"/>')
                elif word == "INDEX_3B":
                    currentSign.nonmanual.append('<hnm_body tag = "RL"/>')
                    #the head turn is repeated this often to make it look more natural
                    currentSign.nonmanual.append('<hnm_head tag="SL"/>')
                    currentSign.nonmanual.append('<hnm_head tag="SL"/>')
                    currentSign.nonmanual.append('<hnm_head tag="SL"/>')
                    currentSign.nonmanual.append('<hnm_head tag="SL"/>')

            currentSigml = currentSign.get_full_sigml()
            sigml += currentSigml + '\n'

    return sigml