Пример #1
0
def ctf():
    """
    returns a list of ctfs
    """
    try:
        page = "https://ctftime.org/event/list/upcoming/rss/"
        p = re.compile(ur'<item><title>(.*?)<.*?Date(.*?)\&.*?sh;(.*?) &.*?at: (.*?)&lt.*?b&gt;(.*?)&.*?href="(.*?)"')
        test_str = unicode(requests.get(page).content.strip(), errors='ignore').replace("\n", "")
        liste = re.findall(p, test_str)
        compteur = 0
        string = []
        while liste:
            elt = liste.pop(0)
            if "On-site" in elt[4]:
                continue
            compteur += 1
            line = "\x0304" + elt[0] + "\x03 Dates\x0302" + elt[1]
            line += "-" + elt[2] + "\x03 type: \x0302" + elt[3]
            line += "\x03 Site web: \x0303" + elt[5] + "\x03"
            string.append(line)
            if compteur == 5:
                break
        return string
    except:
        traceback.print_exc(file=sys.stdout)
        return "failure"
 def autoCase(string):
     """Capitalizes Region/City format inputs
     and makes all letters in 2/3 letter Country-Codes upper-case
     """
     if "/" in string:
         stringList = string.lower().split("/")
         string = []
         for stringTmp in stringList:
             stringTmp = stringTmp.capitalize()
             if "_" or "-" in stringTmp:
                 if "-" in stringTmp:
                     dash = "-"
                 else:
                     dash = "_"
                 string_ = stringTmp.split(dash)
                 stringU = []
                 for stringE in string_:
                     stringU.append(stringE.capitalize())
                 stringTmp = dash.join(stringU)
             string.append(stringTmp)
         if len(string[0]) == 2:
             string[0] = string[0].upper()
         string = "/".join(string)
     else:
         string = string.upper()
     return string
def read_file(file_name):
    input_file = open(file_name)
    count = 0
    gc_current = 0
    name = []  #存放DNA的名称
    string = []  #存放DNA序列
    gc_per = []
    current_string = []
    line = input_file.readline()
    while 1:
        if not line:
            break
        if line[0] == '>':
            #is a name of DNA
            name.append(line[1:len(line) - 1])
            line = input_file.readline()
            if not line:
                break
            while line and line[0] != '>':
                current_string.append(line[0:len(line) - 1])
                line = input_file.readline()
            string.append(current_string)
            current_string = []
    maxx = 0
    loc = -1
    whole_string = []
    tmp_string = []
    for i in range(len(name)):
        whole_string.append(''.join(string[i]))
    input_file.close()
    return name, whole_string
Пример #4
0
 def next(self,string):
     """ Get next sequence of characters.
     Treats characters as numbers (0-255). Function tries to increment
     character at the first position. If it fails, new character is
     added to the back of the list.
     It's basically a number with base = 256.
     :param string: A list of characters (can be empty).
     :type string: list
     :return: Next list of characters in the sequence
     :rettype: list
     """
     
     
     #print("Enter function")
     #print(string)
     if len(string) <= 0:
         string.append(self.indexToCharacter(0))
         #print("First time")
     else:
         string[0] = self.indexToCharacter((self.characterToIndex(string[0]) + 1) % self.NUMBER_OF_CHARACTERS)
         #print("not first")
         if self.characterToIndex(string[0]) is 0:
             #print("is 0 state")
             return list(string[0]) + self.next(string[1:])
             
     return string
Пример #5
0
def convertir_en_letras(numerica):

    string = []
    for i in numerica:
      string.append(chr(ord('`') + i)) #para recobrar un caracter de su ordinal ASCII, se utiliza chr, por lo que en esta linea el contador va cambiando letra a letra e introduciendolo todo en un string nuevo que es devuelto mediante el return
    
    return string
Пример #6
0
def encodeString(s):
	# print s
	if len(s) == 0:
		return '""'
	s = s.replace('\\n', '\n')
	s = s.replace('\\t', '\t')
	s = s.replace('\\r', '\r')
	s = s.replace('\\"', '"')
	choix = random.randint(0, 3)
	if choix == 0:
		string = s.encode('bz2').encode('hex')
		return '"'+string+'".decode(n.lowercase[7:1:-3]+"x").decode((n.lowercase+"a"*21+n.digits)[1::24])'
	elif choix == 1:
		string = s.encode('base64').replace('\n','')
		return '"'+string+'".decode("4z06uue69sgjanpb"[::-3])'
	elif choix == 2:
		string = '"'
		for i in s:
			hexencoded = hex(ord(i)).replace('0x','')
			string += '\\x' + ('0' + hexencoded if len(hexencoded) == 1 else hexencoded)
		return string.encode('rot13') + '"' # '\x' encode
	else :
		string = []
		for i in s:
			string.append('chr(' + str(ord(i)) + ')')
		return '+'.join(string) # chr()+chr()+...
Пример #7
0
    def run(self):
        while self.running:
            #Switch to polling mode if asked...
            if self.mode == 'hotkey' and not self.queue.empty():
                #print "Switching to polling mode..."
                bindkey, callback = self.queue.get()
                self.root.grab_keyboard(1, X.GrabModeAsync, X.GrabModeAsync,
                                        X.CurrentTime)
                self.disp.flush()
                self.mode = 'poll'

            #Don't hammer the CPU
            if self.disp.pending_events() == 0:
                time.sleep(0.1)
                continue

            e = self.disp.next_event()
            if e.type == X.KeyPress:

                keycode = e.detail
                mods = self.xkey.getModStrings(
                    e.state)  # List of modifiers down
                key = dict(self.xkey.getKeyByKeycode(keycode))  # Key details

                if self.xkey.isMod(key["keycode"]):
                    continue

                #Handle hotkey callbacks
                if self.mode == 'hotkey':
                    for k, v in self.bound.items():
                        if keycode == k.internal[
                                "keycode"] and e.state in k.internal[
                                    "mask_permutations"]:
                            v(k)

                #Otherwise process data and return
                elif self.mode == 'poll':
                    #Get an english representation
                    string = mods
                    string.append(key["string"])
                    string = " + ".join(string)

                    key["ignore_mask"] = self.xkey.getIgnoreMask()
                    key["mod_mask"] = e.state & key["ignore_mask"]
                    key["string"] = string
                    key["mask_permutations"] = self.xkey.mask_permutations(
                        key['mod_mask'], key['ignore_mask'])

                    bindkey.internal = key
                    bindkey.string = string

                    self.disp.ungrab_keyboard(X.CurrentTime)
                    self.disp.flush()

                    self.mode = 'hotkey'
                    self.queue.task_done()

                    if callback:
                        callback(bindkey)
Пример #8
0
def random_strings(n, lon, alf):
    s = {}
    while len(s) < n:
        string = []
        for i in range(lon):
            string.append(random.choice(alf))
        s["".join(string)] = "".join(string)
    return s
 def serialization(self, string, root):
     # here we use pre-order to serialize the tree
     if root:
         string.append(str(root.val) + '!')
         self.serialization(string, root.left)
         self.serialization(string, root.right)
     else:
         string.append('#!')
Пример #10
0
 def join_strings(self, cut_phenomes):
     """
     Joins the pronunciations stored as lists into strings.
     Makes it easier for suffix check.
     """
     string = []
     for i in range(len(cut_phenomes)):
         string.append(''.join(cut_phenomes[i]))
     return string
Пример #11
0
def next(string):
    if len(string) <= 0:
        string.append(indexToCharacter(0))
    else:
        string[0] = indexToCharacter(
            (characterToIndex(string[0]) + 1) % NUMBER_OF_CHARACTERS)
        if characterToIndex(string[0]) is 0:
            return list(string[0]) + next(string[1:])
    return string
Пример #12
0
def StringGenerator(string):
    if len(string) <= 0:
        string.append(string_list[0])
    else:
        # error checking needs to be done, otherwise a ValueError will raise
        string[0] = IndexErrorCheck((string_list.index(string[0]) + 1) % len(string_list))
        if string_list.index(string[0]) == 0:
            return [string[0]] + StringGenerator(string[1:])
    return string
Пример #13
0
def polymorph(value, offset):
    string = []
    # Uses the decomposition from the lookup table to load the byte into r3, by subtracting the sequence from r7
    for i, v in enumerate(byteTable[value]):
        string.append("\tsubpl r3, " + ("r7" if i == 0 else "r3") + ", #0x" +
                      v)
    # Stores the byte in r3 to r4-offset (offset is between 0x41 and 0x5B)
    string.append("\tstrbpl r3, [r4, #-" + offset + "]")
    return string
Пример #14
0
 def __str__(self):
     string = list()
     if (len(self.c) == len(self.names)):
         for i in range(len(self.c)):
             string.append("("+self.names[i] + ", " + str(self.t[i]) + ")")
         return ".".join(string)
     else:
         for i in range(len(self.c)):
             string.append("("+str(self.c[i]) + ", " + str(self.t[i]) + ")")
         return ".".join(string)
Пример #15
0
 def scrape_data():
     '''
     Return title + content of a webpage 
     '''
     page = requests.get(link)
     title = BeautifulSoup(page.text, 'html.parser').head.title.contents
     text = BeautifulSoup(page.text, 'html.parser').find_all('p')
     for p in text:
         string.append(p.get_text())
     return link, title, ' '.join(string).replace(u'\xa0', ' ').translate(translator)
Пример #16
0
def command_line_display(maze: Dict[Tuple[int, int], str]):
    x, y = zip(*maze.keys())
    xmin, xmax = min(x), max(x)
    ymin, ymax = min(y), max(y)
    for y in range(ymin, ymax + 1):
        string = [f"{y:02d}"]
        for x in range(xmin, xmax + 1):
            block = maze[(x, y)]
            string.append(block[0])
        print(''.join(string))
Пример #17
0
def nontrival(txt1, txt2, arr):
    ref = [x + y for x, y in zip(txt1, txt2)]
    string = []
    for i in range(len(ref)):
        if (i > 100):
            break
        if (ref[i] < 2):
            continue
        else:
            string.append(str("" + get_key(i, arr) + " : " + str(ref[i])))
    np.textarea2.insert(1.0, string)
Пример #18
0
def resta_strings(string1, string2):

    string = []
    for i in range (len(string1)):
        resta=int(string1[i])-int(string2[i])
        if resta < 0:
            resultado=resta+26
        else:
            resultado=resta
        string.append(resultado)
    return string
Пример #19
0
def suma_strings(string1, string2):

    string = []
    for i in range (len(string1)):
        suma=int(string1[i])+int(string2[i])
        if suma > 26:
            resultado=suma-26
        else:
            resultado=suma
        string.append(resultado)
    return string
def StringAleatorias(NumPalabras):

    string = []
    Tam = random.choice(range(1,1001))

    for i in range(NumPalabras):

        x = id_generator ( Tam ,  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" )
        string.append(x)

    return string
Пример #21
0
def search(n, string, x):
    if x == n:
        return valid(n, string, x)

    for k in extensions(n, string, x):
        string.append(k)
        if search(n, string, x + (k == '\n')):
            return True
        string.pop()

    return False
Пример #22
0
    def run(self):
        while self.running:
            # Switch to polling mode if asked...
            if self.mode == "hotkey" and not self.queue.empty():
                # print "Switching to polling mode..."
                bindkey, callback = self.queue.get()
                self.root.grab_keyboard(1, X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)
                self.disp.flush()
                self.mode = "poll"

                # Don't hammer the CPU
            if self.disp.pending_events() == 0:
                time.sleep(0.1)
                continue

            e = self.disp.next_event()
            if e.type == X.KeyPress:

                keycode = e.detail
                mods = self.xkey.getModStrings(e.state)  # List of modifiers down
                key = dict(self.xkey.getKeyByKeycode(keycode))  # Key details

                if self.xkey.isMod(key["keycode"]):
                    continue

                    # Handle hotkey callbacks
                if self.mode == "hotkey":
                    for k, v in self.bound.items():
                        if keycode == k.internal["keycode"] and e.state in k.internal["mask_permutations"]:
                            v(k)

                            # Otherwise process data and return
                elif self.mode == "poll":
                    # Get an english representation
                    string = mods
                    string.append(key["string"])
                    string = " + ".join(string)

                    key["ignore_mask"] = self.xkey.getIgnoreMask()
                    key["mod_mask"] = e.state & key["ignore_mask"]
                    key["string"] = string
                    key["mask_permutations"] = self.xkey.mask_permutations(key["mod_mask"], key["ignore_mask"])

                    bindkey.internal = key
                    bindkey.string = string

                    self.disp.ungrab_keyboard(X.CurrentTime)
                    self.disp.flush()

                    self.mode = "hotkey"
                    self.queue.task_done()

                    if callback:
                        callback(bindkey)
Пример #23
0
def LDA_fb_post_pat2(patfile, unseenpatfile, outfile):

    print ('Reading training file...')

    with open(patfile, 'r') as data:
        patt_dict = json.load(data)
        patt_dict = dict(patt_dict)

    postid = patt_dict.keys()
    postid.sort()

    texts = []
    for id_ in postid:
        texts.append(patt_dict[id_])

    dictionary = corpora.Dictionary(texts)
    dictionary.filter_extremes(no_below = 3, no_above = 0.8)
    corpus = [dictionary.doc2bow(text) for text in texts]

    lda = models.LdaModel(corpus, num_topics = 8, id2word = dictionary, update_every = 1, chunksize = 10000, passes = 100)

    print ('Reading unseen data...')
    with open(unseenpatfile, 'r') as data:
        unseen_patt = json.load(data)
        unseen_patt = dict(unseen_patt)

    postid = unseen_patt.keys()
    postid = [int(i) for i in postid]
    postid.sort()

    texts = []
    for id_ in postid:
        print (id_)
        texts.append(unseen_patt[str(id_)].keys())

    print ('The length of unseen posts patterns list: {}'.format(len(texts)))

    dictionary = corpora.Dictionary(texts)
    dictionary.filter_extremes(no_below = 3, no_above = 0.8)
    corpus = [dictionary.doc2bow(text) for text in texts]

    print ('Getting unseen data topics...')
    with open(outfile, 'w') as csvfile:
        spamwriter = csv.writer(csvfile, delimiter = ',', quotechar = '"')

        top_prob = lda.get_document_topics(corpus)
        index = 1
        for prob in top_prob:
            string = [index]
            for i in xrange(0, len(prob)):
                string.append(prob[i][1])
            spamwriter.writerow(string)
            index += 1
Пример #24
0
 def __str__(self):
     string = list()
     if (len(self.c) == len(self.names)):
         for i in range(len(self.c)):
             string.append("(" + self.names[i] + ", " + str(self.t[i]) +
                           ")")
         return ".".join(string)
     else:
         for i in range(len(self.c)):
             string.append("(" + str(self.c[i]) + ", " + str(self.t[i]) +
                           ")")
         return ".".join(string)
Пример #25
0
def readContent(link):
    '''
    Depend on the website (pdf or regular html)
    Open the file and scrape the data of 01 site
    Libraries used: 
    bs4 -> BeautifulSoup 
    requests, io, re
    '''

    string = []

    # if the link is a pdf
    if (r'.pdf' in link.split('/')[-1]):
        title = link.split('/')[-1]
        response = requests.get(link)
        raw_data = response.content
        pdf_content = io.BytesIO(raw_data)
        pdf_reader = PyPDF2.PdfFileReader(pdf_content)
        for page in range(pdf_reader.numPages):
            string.append(pdf_reader.getPage(page).extractText())
        return link, title, (' '.join(string))

    # if not
    else:

        def scrape_data():
            '''
            Return title + content of a webpage 
            '''
            page = requests.get(link)
            title = BeautifulSoup(page.text, 'html.parser').head.title.contents
            text = BeautifulSoup(page.text, 'html.parser').find_all('p')
            for p in text:
                string.append(p.get_text())
            return link, title, (' '.join(string).replace(u'\xa0',
                                                          ' ').replace(
                                                              u'\n', ' '))

        try:
            return scrape_data()

        #some links need authentication
        except:

            headers = {'User-Agent': 'Mozilla/5.0'}
            #class AppURLopener(urllib.request.FancyURLopener):
            #version = "Mozilla/5.0"
            #opener = AppURLopener()
            return scrape_data()
Пример #26
0
def getAvailableLetters(lettersGuessed):
    '''
    lettersGuessed: list, what letters have been guessed so far
    returns: string, comprised of letters that represents what letters have not
      yet been guessed.
    '''
    # FILL IN YOUR CODE HERE...
    import string
    alpha = string.ascii_lowercase
    string = []
    string2 = ' '
    for i in alpha:
        if i not in lettersGuessed:
            string.append(i)
    return string2.join(string)
Пример #27
0
def LDA_fb_post_pat(patfile, outfile):
    print ('Reading training file...')

    with open(patfile, 'r') as data:
        patt_dict = json.load(data)
        patt_dict = dict(patt_dict)

    # Delete the item with id 71, because post 71 contains nothing
    patt_dict.pop('71', None)

    postid = patt_dict.keys()
    postid.sort()

    texts = []
    for id_ in postid:
        texts.append(patt_dict[id_])

    dictionary = corpora.Dictionary(texts)
    dictionary.filter_extremes(no_below = 3, no_above = 0.7)
    corpus = [dictionary.doc2bow(text) for text in texts]

    lda = models.LdaModel(corpus, num_topics = 8, id2word = dictionary, update_every = 1, chunksize = 10000, passes = 100)

    topics = lda.show_topics(num_topics = 8, num_words = 10)

    pprint.pprint(topics)

    return

    with open(outfile, 'w') as csvfile:
        spamwriter = csv.writer(csvfile, delimiter = ',', quotechar = '"')

        top_prob = lda.get_document_topics(corpus)
        print ('The length of top_prob: {}'.format(len(top_prob)))
        print ('The lenght of postid: {}'.format(len(postid)))

        index = 0
        for prob in top_prob:
            string = [postid[index]]
            probs = []
            for i in xrange(0, len(prob)):
                probs.append(prob[i][1])

            cluster = probs.index(max(probs)) + 1
            string.append(cluster)
            string.extend(probs)
            spamwriter.writerow(string)
            index += 1
Пример #28
0
def duplicate_lines_removal():
    text = input("Enter filename:")
    string = []
    temp = []
    file = open(text, 'r')
    for line in file:
        string.append(line)
    sentences = nltk.sent_tokenize(' '.join(string))
    for line in sentences:
        if line not in temp:
            temp.append(line)
    file = open("output.txt", "w")
    for line in temp:
        file.write(line)
    print(temp)
    file.close()
Пример #29
0
def segment_characters(img):
    height, width = util.get_2dimensions(img)
    # Find the sum of pixels in each column of image
    colsum = []
    for j in range(width):
        cols = sum([img[i, j] for i in xrange(height)])
        colsum.append(cols)

    vertical_pixel_count = [
        i for i in xrange(width) if colsum[i] != util.ABOVE_THRESHOLD * height
    ]

    # Find the start and end value where the vertical_pixel_count is continuous
    # This is analogous to finding the vertical projection histogram values
    vertical_projection_range = OrderedDict()
    n = 0
    for each_pix_count in vertical_pixel_count:
        if each_pix_count - n in vertical_projection_range:
            vertical_projection_range[each_pix_count - n] = each_pix_count
            n += 1
        else:
            vertical_projection_range[each_pix_count] = each_pix_count
            n = 1

    string = []
    # Segment characters based on the vertical_projection_range
    feature_vector = []
    for start in vertical_projection_range:
        end = vertical_projection_range[start]
        img_character = img[0:height, start - 1:end + 2]
        h, w = util.get_2dimensions(img_character)
        value = 1.5
        temp_sum_rows = sum(
            [1 for j in xrange(w) if img_character[h / value, j] == 0])
        if temp_sum_rows:
            # Removes the rows and columns in the image that are completely white pixels
            img_hor_trim = util.horiz_trimmer(img_character)
            img_vert_trim = util.vert_trimmer(img_hor_trim)
            cv2.imwrite(
                "/home/archana/LPR/codes/extracted/ltr-" + str(start) + ".jpg",
                img_vert_trim)
            # Calls function to find feature array
            lp_character_feature(img_vert_trim)
            # Calls function to idenfity the character from hte feature array
            char = identify_character()
            string.append(char)
    return string
Пример #30
0
def event_handler(msg):
    msgArray = str(msg).split(':')
    msgSubArray = msgArray[2].split("'")
    msg = msgSubArray[0]
    #print('Handler', msg)
    value = redis.get(msg)
    #Find the gear value
    gearArray = value.split(':')
    gear = gearArray[2]
    gearNumberArray = gear.split(',')
    gearNumber = gearNumberArray[0]
    print(gearNumber)
    string.append(value)
    #print(string)
    if (len(string) == 200):
        #print(string)
        pass  #np.savetxt(f,gearNumber, delimiter=",", fmt="%s")
Пример #31
0
    def decrypt(self, cipher_text):
        """
        decrypts plain text using
        the formula ((y-8) *21) % 26
        y being the value of alphabet

        """
        cipher_text = cipher_text.upper()
        string = []
        for letter in cipher_text:
            if letter in self.alphabet_keys.keys():
                string.append(
                    chr(((self.alphabet_keys[letter] - 8) * 21) % 26 + 65))
            else:
                string.append(letter)

        return "".join(string)
Пример #32
0
    def __str__(self):
        string = []
        for symbol in self.symbols:
            string.append(str(symbol))

        if self.count != 1:
            if len(self.symbols) > 1:
                string = ["("] + string + [")"]
            string += [str(self.count)]

        if self.charge != 0:
            if self.charge < 0:
                string += ["(" + str(self.charge) + "-)"]
            else:
                string += ["(" + str(self.charge) + "+)"]

        return "".join(string)
Пример #33
0
    def __str__(self):
        string = []
        for symbol in self.symbols:
            string.append(str(symbol))

        if self.count != 1:
            if len(self.symbols) > 1:
                string = ["("] + string + [")"]
            string += [str(self.count)]

        if self.charge != 0:
            if self.charge < 0:
                string += ["(" + str(self.charge) + "-)"]
            else:
                string += ["(" + str(self.charge) + "+)"]

        return "".join(string)
Пример #34
0
    def encrypt(self, text):
        """
        Encrypts plain text using
        the formula (5x + 8) % 26
        x being the value of alphabet example A:0
        would result to 8 than add 65 to get its encrypted letter
        """
        text = text.upper()
        string = []
        for letter in text:
            if letter in self.alphabet_keys.keys():
                string.append(
                    chr((self.alphabet_keys[letter] * 5 + 8) % 26 + 65))
            else:
                string.append(letter)

        return "".join(string)
Пример #35
0
 def plot_freq(self, corpus, patt, n):
     wordlists = PlaintextCorpusReader(corpus, patt)
     fileids = wordlists.fileids()
     words = []
     for id in fileids:
         words = append(words, wordlists.words(id))
     fre = FreqDist(word.lower() for word in words if word.isalpha())
     fre.tabulate(n)
     return fre.plot(n)
def segment_characters(img):
    height, width = util.get_2dimensions(img)
    # Find the sum of pixels in each column of image
    colsum = []
    for j in range(width):
        cols = sum([img[i, j] for i in xrange(height)])
        colsum.append(cols)

    vertical_pixel_count = [i for i in xrange(width) if colsum[i] != util.ABOVE_THRESHOLD * height]

    # Find the start and end value where the vertical_pixel_count is continuous
    # This is analogous to finding the vertical projection histogram values
    vertical_projection_range = OrderedDict()
    n = 0
    for each_pix_count in vertical_pixel_count:
        if each_pix_count-n in vertical_projection_range:
            vertical_projection_range[each_pix_count-n] = each_pix_count
            n += 1
        else:
            vertical_projection_range[each_pix_count] = each_pix_count
            n = 1

    string = []
   # Segment characters based on the vertical_projection_range
    feature_vector = []
    for start in vertical_projection_range:
        end = vertical_projection_range[start]
        img_character = img[0 : height, start-1 : end+2]
        h, w = util.get_2dimensions(img_character)
        value = 1.5
        temp_sum_rows = sum([1 for j in xrange(w) if img_character[h/value, j] == 0])
        if temp_sum_rows :
            # Removes the rows and columns in the image that are completely white pixels
            img_hor_trim = util.horiz_trimmer(img_character)
            img_vert_trim = util.vert_trimmer(img_hor_trim)
            cv2.imwrite("/home/archana/LPR/codes/extracted/ltr-" + str(start) + ".jpg", img_vert_trim)
            # Calls function to find feature array
            lp_character_feature(img_vert_trim)
            # Calls function to idenfity the character from hte feature array
            char = identify_character()
            string.append(char)
    return string
Пример #37
0
	def __generateStatsText(self):
		"""Returns a nicely formatted string to display a given player's stats."""
		string = []
		string.append("%s: %d(%+d)/%d(%+d)" %(self.lithonian.strings.getString('Info.Stat.HP')[1], self.lithonian.player.health[0], self.lithonian.player.health[1], self.lithonian.player.maxHealth[0], self.lithonian.player.maxHealth[1])) # Health display are special cases of stat, where we want to show max value.
		stats = self.lithonian.player.stats
		
		statString = "%s: %d/%d(%+d) " %(self.lithonian.strings.getString('Info.Stat.Power')[1], self.lithonian.player.power[0], self.lithonian.player.maxPower[0], self.lithonian.player.maxPower[1]) # Note that stat string in this implementation must fit on one line.
		for stat in stats:
			statString += "%s: %d(%+d) " %(self.lithonian.strings.getString('Info.Stat.'+stat)[1], stats[stat][0], stats[stat][1])
		string.append(statString)
		string.append(self.__generateTurnText()) # Turn timer
		if self.lithonian.debugMode:
			string.append("%s" %(self.lithonian.strings.getString('Info.Debug')[1])) # Debug Mode
		return string
Пример #38
0
def db_reset_mazes():
    db = get_db()
    # generate entrance
    db["mazes"].remove({})
    db["mazes_id"].remove({})

    maze = generator.generate_maze(21, 21, {})
    print("Maze generated")

    for y in range(0, maze["y"]):
        string = []
        for x in range(0, maze["x"]):
            if x == maze["start_x"] and y == maze["start_y"]:
                string.append("@")
            elif is_passable(maze["structure"][x][y]):
                string.append(" ")
            else :
                string.append("#")
        print("".join(string))
    print("StartX: " + str(maze["start_x"]))
    print("StartY: " + str(maze["start_y"]))
    db_add_maze(maze, "entrance")
Пример #39
0
for x in range(len(node_r)):
	node_r[x] = node_r[x].split(";")
print node_r
node_dic = dict(node_r)
h.add_nodes_from(node_dic.keys())
h.remove_node("Id")
h.remove_edge("Source","Target")
h.remove_node("Source")
h.remove_node("Target")

indegree = nx.in_degree_centrality(h)
indegree_sort = sorted(indegree.iteritems(), key=itemgetter(1), reverse=True)
indegree_result = indegree_sort[:4]
string = []
for row in indegree_result:
	string.append(row[0])
print "Indegree:"
for row in string:
	print node_dic[row]

outdegree = nx.out_degree_centrality(h)
outdegree_sort = sorted(outdegree.iteritems(), key=itemgetter(1), reverse=True)
outdegree_result = outdegree_sort[:4]
string_out = []
for row in outdegree_result:
	string_out.append(row[0])
print "Outdegree:"
for row in string_out:
	print node_dic[row]

closeness = nx.closeness_centrality(h)
Пример #40
0
def url_contruct():
    string = []
    for x in range(0, 5):
        test = randpart()
        string.append(test)
    return "".join(string)
Пример #41
0
address = 0x04

def writeByte(value):
    bus.write_byte(address, value)
    # bus.write_byte_data(address, 0, value)
    return -1

def readByte():
    number = bus.read_byte(address)
    # number = bus.read_byte_data(address, 1)
    return number

while True:
    ## Receives byte by byte from Arduino, then appends this to string list
    
    byte=1
    try:
        while byte != 0:
            byte=readByte()
            string.append(chr(byte))
            #time.sleep(0.00001)
        new=''.join(string)     #elements in string concatenated
            
        print new
        string = [] #Reinitialise string
        writeByte(0) #send 0 back to signify string has been sent
        time.sleep(1)
    except IOError:
        print "error"
        subprocess.call(['i2cdetect','-y','1'])
Пример #42
0
 def __str__(self):
     string = list()
     for i in range(len(self.n)):
         string.append(str((self.n[i], self.t[i])))
     return ".".join(string).replace("), (", ").(")
# Genera palabras alegatorias


import string
import random

def id_generator ( size, chars = string.ascii_uppercase): 
   return  '' . join ( random . choice ( chars )  for _ in range ( size ))

string = []

for i in range(10):

    x = id_generator ( 3 ,  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" )
    print(x)
    string.append(x)
    print(string)
Пример #44
0
def shorte_parse_modifiers(modifiers):
    STATE_TAG = 0
    STATE_VALUE = 2
    STATE_STRING = 1
    STATE_TRIPLE_QUOTES = 3

    tag = ""
    value = ""
    string = []

    #WARNING("MODIFIERS: [%s]" % modifiers)

    tags = {}
    states = []
    states.append(STATE_TAG)

    i = 0
    while i < len(modifiers):

        state = states[-1]

        #print "STATE: %d, char: %c" % (state, modifiers[i])

        if(modifiers[i] == '\\'):
            i += 1
            continue

        if(state == STATE_TAG):

            if(modifiers[i] == "="):
                value = ""
                states.append(STATE_VALUE)
            else:
                tag += modifiers[i]
                #print "building tag: %s" % tag
        
        elif(state == STATE_TRIPLE_QUOTES):
            if((modifiers[i:i+3] == start_sequence) and modifiers[i-1] != '\\'):
                states.pop()
                i += 2
            else:
                string.append(modifiers[i])

        elif(state == STATE_STRING):
            
            if(modifiers[i] == start_sequence and modifiers[i-1] != '\\'):
                states.pop()
            else:
                string.append(modifiers[i])


        elif(state == STATE_VALUE):
           
            value += ''.join(string)
            string = []

            
            if(modifiers[i:i+3] in ("'''", '"""')):
                states.append(STATE_TRIPLE_QUOTES)
                start_sequence = modifiers[i:i+3]
                i += 2
            elif(modifiers[i] in ('"', "'")):
                states.append(STATE_STRING)
                start_sequence = modifiers[i]
            elif(modifiers[i] == " "):

                tags[tag.strip()] = value.strip()

                #print "Adding tag: %s" % tag
                tag = ""
                value = ""
                states.pop()

            else:
                value += modifiers[i]

        i += 1

    if(value != "" or len(string) != 0):
        value += ''.join(string)
        #print "tag = %s, value = %s" % (tag, value)
        tags[tag.strip()] = value.strip()
    elif(tag != ""):
        tags[tag.strip()] = ""


    #for tag in tags:
    #    print "TAG: [%s] = [%s]" % (tag, tags[tag])

    return tags
	
	for j in range(len(b)):
		concept2.append(b[j])



tuples_normalized = []
	
s = MicrosoftNgram.LookupService()

string_perm = itertools.permutations(keywords)

string = []

for i in string_perm:
	string.append(" ".join(i))


results = []

for i in range(len(string)):
	for t in s.Generate(string[i], maxgen=40): results.append(t)

answers = []

for i in range(len(results)):
	 answers.append(results[i][0])

concept2 = list(set(concept2))

list_answers =  list( (set(concept2) & set(answers) ) - set(keywords) )
Пример #46
0
def List2StringList(lista):
	string = []	
	for l in range(len(lista)):
		string.append(str(lista[l]))	
	return string