Пример #1
0
def format_table(chunk):
    """ Takes a pipe-separated table and aligns the columns. """
    data = [[cell.strip() for cell in row.split("|")] 
                          for row in chunk.split("\n")]

    if data and not data[0][0]:
        if any(i[0] for i in data):
            data[0][0] = ""
            data[0][-1] += ""
    table = aligntable(data)
    return table
Пример #2
0
def format_matrix(chunk):
    """ Takes a matrix and formats/aligns it. """
    data = chunk.split("\n")
    prematrix, data[0] = data[0].split("(", 1)
    data[-1], postmatrix = data[-1].rsplit(")", 1)
    data = [[cell.strip() for cell in row.split("|")] for row in data]
    data = aligntable(data, "  ")
    data[0]    =  "⎛%s⎞" % data[0]
    data[1:-1] = ["⎜%s⎟" % i for i in data[1:-1]]
    data[-1]   =  "⎝%s⎠" % data[-1]
    data = [(" "*len(prematrix))+i for i in data]
    data[int(len(data)/2)] = prematrix + data[int(len(data)/2)].lstrip() + postmatrix

    return data
Пример #3
0
def get_tsv_thread(server, message, text):
    """
    - Syntax: [!@]tsv ^C03query^C
    - Description: Search /r/svexchange for a tsv
    """
    url = (
        "http://www.reddit.com/r/SVExchange/search.json?q=flair%3Ashiny+AND+title%3A"
        + text
        + "&restrict_sr=on&sort=new&t=all"
    )
    results = requests.get(url, headers={"User-Agent": "Rythm the IRC bot by /u/KnightHawk3 (melody)"}).json()
    tableresults = []

    for number, result in enumerate(results["data"]["children"]):
        line = ["\x0f" + result["data"]["title"], "http://redd.it/" + result["data"]["url"].split("/")[-3]]
        tableresults.append(line)
    table = aligntable(tableresults)

    for line in table:
        yield line