예제 #1
0
def read_csv(filename, params):
    from string import ascii_lowercase, ascii_uppercase

    # find out header existance
    header_letters = set(
        ascii_lowercase.replace('e', '') + ascii_uppercase.replace('E', ''))
    with open(filename, 'r') as file:
        first_line = file.readline()
        while 'nan' in first_line:
            first_line = first_line.replace('nan', '')
        header = 0 if len(header_letters & set(first_line)) != 0 else None
    # try to read csv with pandas and fall back to numpy reader if failed
    try:
        import pandas as pd
        data = pd.read_csv(filename, header=header, dtype=params.dtype).values
    except ImportError:
        data = np.genfromtxt(filename,
                             delimiter=',',
                             dtype=params.dtype,
                             skip_header=0 if header is None else 1)

    if data.ndim == 2:
        if data.shape[1] == 1:
            data = data.reshape((data.shape[0], ))

    return data
예제 #2
0
def linear_main():
    start_time = time.time()
    last_names_list = ascii_lowercase.replace('x', '')

    for ln in last_names_list[0:2]:
        thisLogger.debug("Fetching playerlist for last names starting with  ""{playerlist_lastname}""".format(playerlist_lastname=ln))
        player_list = fetch_playerlist(playerlist_lastname=ln)[0]
        thisLogger.debug("Parsing playerlist for last names starting with  ""{playerlist_lastname}""".format(playerlist_lastname=ln))
        this_player_list = parse_playerlist(player_list)
        thisLogger.debug("Got playerlist \t""{0}"" \tContains {1}".format(ln.upper(), len(this_player_list)))
        glob_plist.extend(this_player_list)

    for pl in glob_plist[0:3]:
        thisLogger.debug("Fetching player {player}".format(player=pl))
        fetch_result = fetch_player(player=pl)
        thisLogger.debug("Parsing player {player}".format(player=pl))
        this_player = parse_player(
            soup=fetch_result[0], url=fetch_result[1])
        glob_player.append(this_player)
        thisLogger.debug("Finished parsing Player {name} for general information. His seasons are {seasons}".format(name=this_player['name'], seasons=", ".join(this_player['seasons'])))

        for season in this_player['seasons']:
            soup, fetched_url = fetch_player_season(
                this_player['page_url'], season)
            glob_player_season.extend(
                parse_player_season(player=this_player, soup=soup))
            end_time = time.time()
            gen_text = "Finished Season {0} Player {1}. Running for {2:.2f} min"
            thisLogger.debug(gen_text.format(season, this_player['name'], (end_time - start_time) / 60))

    # dump_games_to_csv(glob_player_season)

    thisLogger.debug("RUN TIME {0:.2f}".format((time.time() - start_time) / 60))
예제 #3
0
    def encode_plain(plain: str, key: str, sub=("j", "")) -> str:
        keyalpha = Utils.unformat(key) + lc.replace(sub[0], "")
        keyfiltered = ''.join(keyalpha[i] for i in range(len(keyalpha)) if i == keyalpha.index(keyalpha[i]))
        key_grid = [[keyfiltered[i*5+j] for j in range(5)] for i in range(5)]

        plain = re.sub(*sub, Utils.unformat(plain))

        q, output = list(plain), ""
        while len(q) > 0:
            if len(q) == 1: q += "x"
            if q[0] == q[1]: output += Playfair.encrypt_pair(q.pop(0), "x", key_grid)
            else: output += Playfair.encrypt_pair(q.pop(0), q.pop(0), key_grid)

        return output
예제 #4
0
    class _spce(list):
        x = "x"
        vs = ascii_lowercase.replace(x, "")

        def sub(self, val):
            idx = len(self)
            self.append(val)
            return sympy.Symbol(self.vs[idx])

        @classmethod
        def extract(cls, expr):
            ret = cls()
            return expr.replace(attrgetter("is_Number"), ret.sub), ret

        @classmethod
        def symbols(cls, num):
            return sympy.symbols(" ".join(cls.vs[:num]), seq=True)
예제 #5
0
    def _jumpled_random_square_alphabet() -> List[List[int]]:
        """ jumple alphabet from random shuffled positions of chars.

        Returns:
            list: jumpled alphabet as 5x5 matrix.
        """
        positions = [(x, y) for x in range(5) for y in range(5)]
        shuffle(positions)  # make it be random for inserte chars
        square = [[0 for _ in range(5)] for _ in range(5)]
        ascii_letters = ascii_lowercase.replace('i', '')  # i = j in square

        count = 0
        for x, y in positions:
            if count > len(ascii_lowercase):
                break
            if square[x][y] == 0:
                if ascii_letters[count] == 'j':
                    square[x][y] = ascii_letters[count] + 'i'
                else:
                    square[x][y] = ascii_letters[count]
                count += 1

        return square
예제 #6
0
def dealphabetize(text):
    return ' '.join([ascii_lowercase.replace(char, '') for char in text])
예제 #7
0
# Scrapes data from basketball reference to build our dataset for our deep model
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup
from scrape_tools import getSoup
from string import ascii_lowercase
import urllib.request
import shutil
import requests
import unidecode

base_url = 'https://www.basketball-reference.com'
letters = ascii_lowercase.replace('x', '')


def getHOFPlayerLinks(
        url='https://www.basketball-reference.com/awards/hof.html'):
    # I manually added Kobe, Duncan and Garnett as they will be in the hall of fame next year
    soup = getSoup(url)
    links = {
        '/players/b/bryanko01.html', '/players/d/duncati01.html',
        '/players/g/garneke01.html'
    }
    for a in soup.find_all('a', href=True):
        if a.text == 'Player':
            links.add(a['href'])
    return links


def getAllStarLinks(
        url='https://www.basketball-reference.com/awards/all_star_by_player.html'
예제 #8
0
def cipher(text, encrypt_mode, keyword):
    # encrypt mode is a boolean which stores whether we are encrypting or decrypting
    alphabet = ascii_lowercase.replace("j", "")
    text = "".join(
        filter(lambda x: x in ascii_lowercase,
               "".join(text.lower().replace("j", "i").split())))
    keyword = keyword.lower().replace("j", "i")

    if len(text) % 2 == 1:
        text += "x"

    blocks = [text[i:i + 2] for i in range(0, len(text), 2)]

    for index, block in enumerate(blocks):
        if block[0] == block[1]:
            blocks[index] = block[0] + "x"

    matrix = []
    letters = []

    for i in (keyword.lower() + alphabet):
        if i not in letters: letters.append(i)

    for i in range(0, 25, 5):
        matrix.append(letters[i:i + 5])

    def getPosition(x):
        for i, j in product(range(5), repeat=2):
            if matrix[i][j] == x:
                return i, j
        print("wtf: {}".format(x))

    cipherText = []

    for b1, b2 in blocks:
        x1, y1 = getPosition(b1)
        x2, y2 = getPosition(b2)
        if x1 == x2:
            if y1 == 4: y1 = -1
            if y2 == 4: y2 = -1
            cipherText.append(matrix[x1][y1 + (encrypt_mode) -
                                         (not encrypt_mode)])
            cipherText.append(matrix[x2][y2 + (encrypt_mode) -
                                         (not encrypt_mode)])
        elif y1 == y2:
            if x1 == 4: x1 = -1
            if x2 == 4: x2 = -1
            cipherText.append(matrix[x1 + (encrypt_mode) -
                                     (not encrypt_mode)][y1])
            cipherText.append(matrix[x2 + (encrypt_mode) -
                                     (not encrypt_mode)][y2])
        else:
            cipherText.append(matrix[x1][y2])
            cipherText.append(matrix[x2][y1])

    if not encrypt_mode:
        if cipherText[-1] == "x":
            cipherText.pop()
        for index, char in enumerate(cipherText):
            if char == "x":
                cipherText[index] = cipherText[index - 1]
        return ("".join(cipherText).lower())
    else:
        return "".join(cipherText).upper()

    table = {}
예제 #9
0
from string import ascii_lowercase, ascii_uppercase, ascii_letters
"""
Created on Sat Aug 31 19:47:07 2019
@author: omer Navon
"""
"""Bacon’s Code
Bacon used a naïve binary system to encode the alphabeth. This was 24 rather than 26 letters as IJ and UV were combined.
So each letter was represented by it’s ordinal from 0 to 23,
in 5-bit binary (00000 to 10111) (it was big endian like hindu-arabic numerals ←)
Instead of 0 and 1 he used ‘a’ and ‘b’ but this was only for discussing the system.
The actual encoding was done by a pair of fonts.
And than a false messege was written in them to encode the real messege (which was obviously 5 times shorter)
"""

order = ascii_lowercase.replace('j', '').replace('v', '')
"""all Packet Objects are Equivalent to a letter of the True Massage or 5-bit"""


class Letter:
    """format:1*(a-z).exclude(j,v)"""
    def __init__(self, letter: str):
        letter = letter.lower()
        if letter == 'j':
            letter = 'i'
        if letter == 'v':
            letter = 'u'
        self.val = letter

    def __str__(self):
        return self.val
def get_ascii_lowercase_exclude_current_char(char):
    return ascii_lowercase.replace(char, "")
예제 #11
0
            "ng",
            "o",
            "ō",
            "p",
            "r",
            "t",
            "u",
            "ū",
            "w",
            "wh",
        ],
    },
    # Simplified Chinese
    "zh-hans": {
        "letters":
        ["─", "╱", "V", "╲"] + list(ascii_lowercase.replace("v", "ü")),
        "description": "汉语拼音",
    },
}


def get_alphabet(language_code):
    """Return the language for the given language code.

    Args:
        language_code (str): Code of language.

    Returns:
        List of strings of alphabet.
    """
    return [SPACER] + ALPHABETS[language_code]["letters"]
예제 #12
0
from string import ascii_lowercase

# https://www.codeeval.com/public_sc/37/

def pangram(input_sentence):
    input_sentence = set(input_sentence.lower())
    missing_letters = []
    if input_sentence == set(ascii_lowercase):
        return None
    for c in ascii_lowercase:
        if c not in input_sentence:
            missing_letters.append(c)
    return missing_letters or None


assert pangram(ascii_lowercase) is None
assert pangram(ascii_lowercase.replace("z", "a")) == ["z"]
assert pangram(ascii_lowercase.replace("z", "a").replace("b", "a")) == ["b", "z"]

to_be_replaced = []
for c in ascii_lowercase:
    to_be_replaced.append(c)
    alphabet = ascii_lowercase
    for to_replace in to_be_replaced:
        alphabet.replace(to_replace, "a")
        missing_letters_for_pangram = pangram(alphabet)
        assert missing_letters_for_pangram == to_be_replaced or \
               alphabet == ascii_lowercase and missing_letters_for_pangram is None

print("done!")