Esempio n. 1
0
 def first_available_choice(self):
     """
     :rtype: site.mangasite.MangaSite.Chapter
     """
     return _(self.choices).find(
         lambda chapter, *args: (_(chapter.pages).chain()
                                 .map(lambda page, *args: page.image)
                                 .all(lambda image, *args: image is not None).value()
         )
     )
Esempio n. 2
0
def valid_borrowers(borrowers):
    valid = _(borrowers).chain()\
        .map(lambda x, *a: x['dob'])\
        .reduce(valid_dob, True).value()

    phone_number_list = _(borrowers).chain()\
        .map(lambda x, *a: x['phone_number'])\
        .value()

    valid &= is_unique_list(phone_number_list)

    return valid
Esempio n. 3
0
def valid_borrowers(borrowers):
    valid = _(borrowers).chain()\
        .map(lambda x, *a: x['dob'])\
        .reduce(valid_dob, True).value()

    phone_number_list = _(borrowers).chain()\
        .map(lambda x, *a: x['phone_number'])\
        .value()

    valid &= is_unique_list(phone_number_list)

    return valid
Esempio n. 4
0
def update_deed(deed, deed_json, akuma_flag):
    deed.identity_checked = deed_json["identity_checked"]
    json_doc = build_json_deed_document(deed_json)

    borrowers = deed_json["borrowers"]

    if not valid_borrowers(borrowers):
        msg = "borrower data failed validation"
        LOGGER.error(msg)
        return False, msg

    update_borrower_for_token = partial(update_borrower, deed_token=deed.token)

    borrower_json = _(borrowers).chain()\
        .map(update_borrower_for_token)\
        .value() if akuma_flag == "A" else None

    json_doc['borrowers'] = borrower_json

    if not update_md_clauses(json_doc, deed_json["md_ref"], deed.organisation_name):
        msg = "mortgage document associated with supplied md_ref is not found"
        LOGGER.error(msg)
        return False, msg

    deed.deed = json_doc

    deed.save()

    return True, "OK"
Esempio n. 5
0
def update_deed(deed, deed_json, akuma_flag):
    deed.identity_checked = deed_json["identity_checked"]
    json_doc = build_json_deed_document(deed_json)

    borrowers = deed_json["borrowers"]

    if not valid_borrowers(borrowers):
        msg = "borrower data failed validation"
        LOGGER.error(msg)
        return False, msg

    update_borrower_for_token = partial(update_borrower, deed_token=deed.token)

    borrower_json = _(borrowers).chain()\
        .map(update_borrower_for_token)\
        .value() if akuma_flag == "A" else None

    json_doc['borrowers'] = borrower_json

    if not update_md_clauses(json_doc, deed_json["md_ref"],
                             deed.organisation_name):
        msg = "mortgage document associated with supplied md_ref is not found"
        LOGGER.error(msg)
        return False, msg

    deed.deed = json_doc

    deed.save()

    return True, "OK"
Esempio n. 6
0
def title_candidate(doc):
    candidates = set()
    regex = re.compile("tit", re.U | re.I)

    _([".//h1", ".//h2", ".//h3", ".//h4"]).chain().map(lambda x, *a: list(doc.iterfind(x))).flatten().filter(
        lambda elem, *a: elem.get("class") is not None
    ).filter(lambda elem, *a: regex.search(elem.get("class"))).map(
        lambda elem, *a: [elem.text, elem.text_content()]
    ).flatten().compact().each(
        lambda elem, *a: candidates.add(elem)
    )

    if len(candidates) > 2:
        # If we have more than 2 elements, then we may made a wrong guess
        return set()

    return candidates
Esempio n. 7
0
 def title(self):
     """
     :rtype: str
     """
     return (_(self.choices).chain()
             .map(lambda chapter, *args: chapter.title)
             .sortBy(lambda title, *args: len(title))
             .last().value()
     )
Esempio n. 8
0
def _testFile(original_filename):
    underscored_filename = os.path.join('examples', 'underscored',
                                        os.path.basename(original_filename))
    _(original_filename, underscored_filename, original=True)

    try:
        original_filename_output = execute(original_filename)
    except:
        raise Exception(str(dump_ast(original_filename)))

    try:
        underscored_filename_output = execute(underscored_filename)
    except:
        exc_type, value = sys.exc_info()[:2]
        raise Exception(
            str(value) + '\n\n' + str(dump_ast(original_filename)) + '\n\n' +
            open(underscored_filename).read())

    nt.assert_equal(original_filename_output, underscored_filename_output)
Esempio n. 9
0
def _testFile(original_filename):
    underscored_filename = os.path.join('examples', 'underscored',
                               os.path.basename(original_filename))
    _(original_filename, underscored_filename, original=True)

    try:
        original_filename_output = execute(original_filename)
    except:
        raise Exception(str(dump_ast(original_filename)))

    try:
        underscored_filename_output = execute(underscored_filename)
    except:
        exc_type, value = sys.exc_info()[:2]
        raise Exception(
            str(value) + '\n\n' +
            str(dump_ast(original_filename)) + '\n\n' +
            open(underscored_filename).read())

    nt.assert_equal(original_filename_output, underscored_filename_output)
    def validate_dob(self, deed_json):
        borrowers = deed_json["borrowers"]

        valid = _(borrowers).chain() \
            .map(lambda x, *a: x['dob']) \
            .reduce(valid_dob, True).value()

        if not valid:
            msg = "A date of birth must not be a date in the future."
            application.app.logger.error(msg)
            return valid, msg
        else:
            return True, ""
    def validate_phonenumbers(self, deed_json):
        borrowers = deed_json["borrowers"]

        phone_number_list = _(borrowers).chain() \
            .map(lambda x, *a: x['phone_number']) \
            .value()

        valid = is_unique_list(phone_number_list)

        if not valid:
            msg = "A mobile phone number must be unique to an individual."
            application.app.logger.error(msg)
            return valid, msg
        else:
            return True, ""
Esempio n. 12
0
def update_deed(deed, deed_json):
    deed.identity_checked = deed_json["identity_checked"]
    json_doc = build_json_deed_document(deed_json)

    borrowers = deed_json["borrowers"]
    update_borrower_for_token = partial(update_borrower, deed_token=deed.token)

    borrower_json = _(borrowers).chain()\
        .map(update_borrower_for_token).value()

    json_doc['borrowers'] = borrower_json

    reference = ""
    if "reference" in deed_json:
        reference = deed_json["reference"]

    date_of_mortgage_offer = ""
    if "date_of_mortgage_offer" in deed_json:
        date_of_mortgage_offer = deed_json["date_of_mortgage_offer"]

    deed_effector = ""
    if "deed_effector" in deed_json:
        deed_effector = deed_json["deed_effector"]

    if not update_md_clauses(json_doc, deed_json["md_ref"], reference,
                             date_of_mortgage_offer, deed_effector,
                             get_organisation_name(deed)):
        msg = "mortgage document associated with supplied md_ref is not found"
        application.app.logger.error(msg)
        return False, msg

    assign_deed(deed, json_doc)

    deed.payload_json = deed_json

    deed.save()

    delete_orphaned_borrowers(deed)

    return True, "OK"
def format_address_string(address_string):
    def remove_whitespace(x, index, list):
        return x.strip()

    def uppercase_if_postcode(x, index, list):
        return x.upper() if re.search(BASIC_POSTCODE_REGEX, x.upper()) else x

    def handle_house_number(result, x, index):
        if index == 1 and re.search(HOUSE_CODE, result[0]):
            result = [result[0] + ' ' + x]
        else:
            result.append(x)
        return result

    def make_postcode_last(context, x, index):

        matches = re.match(BASIC_POSTCODE_WITH_SURROUNDING_GROUPS_REGEX, x)
        slots = len(context)
        if index > 1 and re.search(BASIC_POSTCODE_REGEX, context[slots - 1]):
            postcode = context[slots - 1]
            context[slots - 1] = x
            context.append(postcode)
        elif matches:
            if matches.group('leading_text') and len(
                    matches.group('leading_text').strip()) > 0:
                context.append(matches.group('leading_text').strip())
            if matches.group('trailing_text') and len(
                    matches.group('trailing_text').strip()) > 0:
                context.append(matches.group('trailing_text').strip())
            context.append(matches.group('postcode').strip())
        else:
            context.append(x)
        return context

    return _(address_string.split(',')).chain()\
        .map(remove_whitespace)\
        .reduce(handle_house_number, [])\
        .reduce(make_postcode_last, [])\
        .map(uppercase_if_postcode)\
        .value()
def format_address_string(address_string):

    def remove_whitespace(x, index, list):
        return x.strip()

    def uppercase_if_postcode(x, index, list):
        return x.upper() if re.search(BASIC_POSTCODE_REGEX, x.upper()) else x

    def handle_house_number(result, x, index):
        if index == 1 and re.search(HOUSE_CODE, result[0]):
            result = [result[0] + ' ' + x]
        else:
            result.append(x)
        return result

    def make_postcode_last(context, x, index):

        matches = re.match(BASIC_POSTCODE_WITH_SURROUNDING_GROUPS_REGEX, x)
        slots = len(context)
        if index > 1 and re.search(BASIC_POSTCODE_REGEX, context[slots-1]):
            postcode = context[slots-1]
            context[slots-1] = x
            context.append(postcode)
        elif matches:
            if matches.group('leading_text') and len(matches.group('leading_text').strip()) > 0:
                context.append(matches.group('leading_text').strip())
            if matches.group('trailing_text') and len(matches.group('trailing_text').strip()) > 0:
                context.append(matches.group('trailing_text').strip())
            context.append(matches.group('postcode').strip())
        else:
            context.append(x)
        return context

    return _(address_string.split(',')).chain()\
        .map(remove_whitespace)\
        .reduce(handle_house_number, [])\
        .reduce(make_postcode_last, [])\
        .map(uppercase_if_postcode)\
        .value()
Esempio n. 15
0
        cur_state.append(building)
        craw_building(building['building_id'])
        cur_state.pop()


def crawl_parent_area(area_id):
    # crawl_area(area_id)
    print 'Crawing parent area:', area_id
    res = requests.get(
        base_url + '/area/query',
        params={'parent_id': area_id}
    )
    areas = res.json()['data']

    for area in areas:
        cur_state.append(area)
        crawl_area(area['area_id'])
        cur_state.pop()


if __name__ == '__main__':
    res = requests.get(base_url + '/api/store/list')
    data = _(res.json()['data']).chain()
    districts = data.map(lambda x, i, *a: x['districts']).flatten()
    places=districts.map(lambda x, i, *a: x['places']).flatten().value()

    for place in places:
        cur_state.append(place)
        crawl_parent_area(place['area_id'])
        cur_state.pop()
Esempio n. 16
0
 def _(self, *args):
     _(*args)
Esempio n. 17
0

def t():
    return map(lambda x: x * x, [1, 2, 3])


def s():
    data = [1, 2, 3, 4, 5, 6]
    try:
        __path = os.path.dirname(os.path.realpath(__file__))
        with open(__path + '\input.txt', 'r') as f:
            print f.readline()  # Hello from python
    except Exception, err:
        print err
    return _(data) \
        .chain() \
        .filter(lambda x, *a: x > 2) \
        .map(lambda x, *a: x * 2) \
        .sortBy() \
        .value()


def f():
    data = [1, 2, 3]
    return reduce(lambda x, y: x + y, data)


def fff(m, n):
    return m
    # return 1 if num == 0 or num == 1 else factor_fn(num - 1) * num
Esempio n. 18
0
accounts = [75,76,77,78,79,1] #You'd need to replace these account numbers

for account in accounts:
    print "getting users account "+str(account)
    incomplete = True
    page = 1
    while incomplete:
        #sleep(1)
        #r = requests.get(
        #    base_url + "/accounts/"+str(account)+"/users?page="+str(page), verify=False, **settings)
        r = getWeb(base_url + "/accounts/"+str(account)+"/users?page="+str(page), settings)
        #base_url + "/courses/" + str(course.id) +
        #"/students", **settings)
        print "  page "+str(page)
        for user in r.json():
            user_info = _(user).pick(["id", "name","sis_user_id"])
            #sis_user_id not sis_account_id?
            u = User(**user_info)
            u.sortable_name = user["sortable_name"]
            #u = User()
            #u.id = user["id"]
            #u.name = user["name"]
            #u.sis_account_id = user["sis_account_id"]
            u_string = str(u.id)
            if len(u_string) > 5:
                u_string = u_string[6:]
            #print u_string
            u.id = int(u_string)
            #print u.id
            user_ids.append(u.id)
            user_names.append(u.name)
Esempio n. 19
0
import sys
sys.path.append("/Users/wenjunyan/_py/src")
sys.path.append("/Users/wenjun.yan/tmp/_.py/src")
from underscore import _
import inspect

def p(x): print(x)

def args(x):
    s = inspect.getargspec(getattr(_, x))
    r = ", ".join(s.args[1:])
    if s.varargs:
        r = r + (r and ", ") + "*" + s.varargs
    if s.keywords:
        r = r + (r and ", ") + "**" + s.keywords
    return r

def dl(x):
    return x + "("+ args(x) + ")"

(_(dir(_))
 .filter(lambda x: getattr(_, x).__doc__ and not x.startswith('__'))
 .map(lambda x: "### "+ dl(x) + getattr(_, x).__doc__)
 .map(lambda x: inspect.cleandoc(x).replace("e.g.", "```python\n").replace("type", "\n**type**") + "\n```\n")
 .map(lambda x: x.replace("@param", "\n**@param**"))
 .map(lambda x: x.replace("@return", "\n**@return**"))
 .each(p))


Esempio n. 20
0
 def _(self, *args):
     _(*args)