Esempio n. 1
0
def get_address(filename_string):

    sample = filename_string
    sample = sample[:len(sample) - 4]

    zipcode_pp = Word(nums, min=5) + pp.Suppress('_')
    zipp = zipcode_pp.searchString(sample)
    zipcode = zipp[0][0]

    address1 = pp.OneOrMore(
        Word(pp.alphanums + '()') + pp.Suppress('_') + ~Word(zipcode, min=5))
    address2 = Word(pp.alphanums + '()') + pp.Suppress('_') + pp.Suppress(
        Word(zipcode, min=5))

    add1 = list(address1.parseString(sample))
    add2 = list(address2.searchString(sample))

    add1.append(add2[0][0])

    address = " ".join(add1)

    return address, zipcode
Esempio n. 2
0
text = ' '.join(lines)

text = text.replace("\r", "")
text = text.replace("\n", "")

Dash = Literal('—')  #тире (длинное)	—	Alt + 0151
Number = Word(nums) + Dash.suppress()
Name = Word(nums).suppress() + Dash.suppress() + Word(rus_alphanums)

#Шаблон для поиска описания
Description = Name.suppress() + Word(rus_alphanums +
                                     ' ') + Literal('/').suppress()

destinyData = {}

for num in Number.searchString(text):
    key = int(num[0])
    destinyData[key] = dict({'number': num[0]})

key = 1
for name in Name.searchString(text):
    destinyData[key].update({'name': name[0]})
    key += 1

key = 1
for description in Description.searchString(text):
    destinyData[key].update({'description': description[0]})
    key += 1

#print(json.dumps(densityData, ensure_ascii = False, sort_keys = True, indent = 4))
Esempio n. 3
0
def raw_parse(filename, row=0):
    '''
    The first function in the parsing pipeline. Takes in the raw block of data
    from the CSV file and parses the text to return two arrays:
        
        week - A string to identify the week
        prices_arr - Tuples of prices and offices names
        timeslot_arr - Big array encoding office usage over the week, hit this
                       with the unwrap function to make sense of it
        
    '''
    input_file = filename
    data = pd.read_csv(read_dir + input_file, encoding='latin-1')
    d = data.iloc[row][0]
    d = d.replace(u'\xa0', ' ')  #Encoding is messed up,
    #this character \xa0 causes problems if not removed
    d = d.replace(u'åÊ', ' ')
    d = d.replace(u'ξ', ' ')
    d = d.replace(u'ξ', ' ')

    months_30 = ['Sep', 'Apr', 'Jun', 'Nov']

    #AMtime = Word(nums+':') + pp.Or(pp.Literal('AM'),pp.Literal('PM')) on standby

    date = Word(alphas) + Word(nums) + '-' + Word(alphas) + Word(
        nums) + pp.Suppress(',') + pp.Suppress(Word(nums))
    location = Word(pp.alphanums +
                    '-()#/.') + pp.OneOrMore(~pp.LineStart() +
                                             Word(pp.alphanums + '-()#/.'))
    price_loc = pp.Suppress('$') + Word(nums + '.') + pp.Suppress('/') + Word(
        alphas + '-') + location

    week_date = date.parseString(d)
    prices_loc = price_loc.searchString(d)

    week = week_date[0] + ' ' + week_date[1] + ' ' + week_date[
        2] + ' ' + week_date[3] + ' ' + week_date[4]

    start_month = week_date[0]
    start_day = week_date[1]

    if start_month in months_30:
        selector = 30
    elif start_month == 'Feb':
        selector = 28
    else:
        selector = 31

    prices_arr = [
    ]  #One of the two arrays returned, returns tuples of price per
    # time period and the name of the office

    for s in prices_loc:
        time = s[0]
        period = s[1]
        value = " ".join(s[2:])
        prices_arr.append((time, period, value))

    timeslot_arr = []  #The second array returned, contains a big mess of data,
    #basically encodes all the usage info for each office over the week.
    #Call the unwrap function on this beast to make sense of it

    lit = pp.Literal(
        'This reservation was created in different reservation mode for workspace, please correct.'
    )
    remove = pp.Or(Word(alphas) + lit, Word(alphas) + Word(alphas) + lit)
    timeslot = pp.OneOrMore(
        Word(nums + ':') + Word(alphas) + pp.Suppress('-') + Word(nums + ':') +
        Word(alphas) + pp.Suppress(remove))
    extra = pp.Or([Word(alphas) + Word(alphas), timeslot, pp.Empty()])

    for ii in range(7):

        if (int(start_day) + ii) % selector == 0:
            day = int(start_day) + ii
        else:
            day = (int(start_day) + ii) % selector

        if day < 10:
            day = str(0) + str(day)
        else:
            day = str(day)

        start = Word(alphas) + pp.Suppress(',') + Word(alphas) + day + extra

        dd = start.searchString(d)
        timeslot_arr.append(dd)

    return week, prices_arr, timeslot_arr
Esempio n. 4
0
#!/usr/bin/env python
# coding: utf8
import string, os, time
from pyparsing import Word, nums  # "sudo apt-get install acpi python-setuptools", "sudo easy_install pyparsing"

akku_ = -1
alarm = False
parse = Word(nums)
while True:
    cmd = os.popen("acpi")
    line = cmd.readlines()
    result = parse.searchString(line[0])
    akku = str(map(int, result[1]))[1:-1]
    if akku < 15 and alarm == False:
        os.popen('echo "do something"')
        alarm = True
    if akku > 15 and alarm == True:
        alarm = False
    if akku != akku_:
        print(akku + "%")
        akku_ = akku
    time.sleep(30)