コード例 #1
0
def fetch_store_detail(s, data, isOfficial=False):
    entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                data['brandname_c'])

    entry[cm.name_e] = cm.html2plain(s['name']).strip()
    entry[cm.country_e] = data['country']
    val = cm.html2plain(s['city']).strip().upper()
    entry[cm.city_e] = cm.extract_city(
        val if val and val != '' else data['city'])[0]
    entry[cm.addr_e] = cm.html2plain(s['address']).strip()
    entry[cm.email] = s['email'].strip()
    entry[cm.tel] = s['phone'].strip()
    entry[cm.fax] = s['fax'].strip()
    entry[cm.store_class] = 'Official Retailer' if isOfficial else 'Retailer'

    try:
        entry[cm.lat] = string.atof(s['lat']) if s['lat'] != '' else ''
    except (ValueError, KeyError, TypeError) as e:
        cm.dump('Error in fetching lat: %s' % str(e), log_name)
    try:
        entry[cm.lng] = string.atof(s['lng']) if s['lng'] != '' else ''
    except (ValueError, KeyError, TypeError) as e:
        cm.dump('Error in fetching lng: %s' % str(e), log_name)

    gs.field_sense(entry)
    ret = gs.addr_sense(entry[cm.addr_e], entry[cm.country_e])
    if ret[1] is not None and entry[cm.province_e] == '':
        entry[cm.province_e] = ret[1]
    if ret[2] is not None and entry[cm.city_e] == '':
        entry[cm.city_e] = ret[2]
    gs.field_sense(entry)

    return entry
コード例 #2
0
ファイル: shanghaivive.py プロジェクト: haizi-zh/ofashion
def fetch_stores(data):
    body = data['body']
    start = body.find(u'<ul class="storelist storelist_%s' % data['code'])
    if start == -1:
        cm.dump('Error in finding stores for %s' % data['code'])
        return []
    body = cm.extract_closure(body[start:], ur'<ul\b', ur'</ul>')[0]

    store_list = []
    for m in re.findall(ur'<li class="sitem">(.+?)</li>', body, re.S):
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'], data['brandname_c'])
        m1 = re.search(ur'<h3>(.+?)</h3>', m)
        if m1 is not None:
            entry[cm.name_c] = m1.group(1).strip()
        m1 = re.search(ur'<div class="addr">(.+?)</div>', m)
        if m1 is not None:
            entry[cm.addr_e] = m1.group(1).replace(u'地址:', '').replace(u'地址:', '').strip()
        m1 = re.search(ur'<div class="tel">(.+?)</div>', m)
        if m1 is not None:
            entry[cm.tel] = m1.group(1).replace(u'电话:', '').replace(u'电话:', '').strip()
        entry[cm.city_c] = data['city']
        ret = gs.look_up(data['city'], 3)
        if ret is not None:
            entry[cm.city_e] = ret['name_e']
            entry[cm.city_c] = ret['name_c']
            if ret['province'] != '':
                entry[cm.province_e] = ret['province']['name_e']
        entry[cm.country_e] = u'CHINA'
        gs.field_sense(entry)
        cm.dump('(%s / %d) Found store: %s, %s (%s, %s)' % (data['brandname_e'], data['brand_id'],
                                                            entry[cm.name_e], entry[cm.addr_e], entry[cm.country_e],
                                                            entry[cm.continent_e]), 'canali_log.txt')
        db.insert_record(entry, 'stores')
        store_list.append(entry)
コード例 #3
0
def fetch_store_details(data):
    url = data['host'] + data['url']
    try:
        body = cm.get_data(url)
    except Exception:
        cm.dump('Error in fetching store details: %s' % url, log_name)
        return []

    entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                data['brandname_c'])
    start = body.find(ur'<h3>available in store</h3>')
    if start != -1:
        type_sub = cm.extract_closure(body[start:], ur'<ul\b', ur'</ul>')[0]
        entry[cm.store_type] = ', '.join(
            cm.html2plain(tmp).strip()
            for tmp in re.findall(ur'<li[^<>]*>(.+?)</li>', type_sub, re.S))

    start = body.find(ur"<div class='gmap_info_box'")
    if start == -1:
        cm.dump('Error in fetching store details: %s' % url, log_name)
        return []
    body = cm.extract_closure(body[start:], ur'<div\b', ur'</div>')[0]

    raw = json.loads(cm.extract_closure(body, ur'\{', ur'\}')[0])['table']
    entry[cm.name_e] = cm.html2plain(raw['name'])
    entry[cm.city_e] = data['city'].strip().upper()
    entry[cm.country_e] = data['country'].strip().upper()
    # entry[cm.store_type] = data['store_type']
    entry[cm.addr_e] = cm.reformat_addr(raw['address'])
    m = re.search(re.compile(ur'phone:(.*?)fax:(.*?)', re.I | re.S),
                  raw['phone'])
    if m is not None:
        entry[cm.tel] = m.group(1).strip()
        entry[cm.fax] = m.group(2).strip()
    else:
        m = re.search(re.compile(ur'phone:(.*?)', re.I | re.S), raw['phone'])
        if m is not None:
            entry[cm.tel] = m.group(1).strip()
        m = re.search(re.compile(ur'fax:(.*?)', re.I | re.S), raw['phone'])
        if m is not None:
            entry[cm.fax] = m.group(1).strip()
    entry[cm.hours] = raw['hours']
    if raw['lat'] is not None and raw['lat'] != '':
        entry[cm.lat] = string.atof(raw['lat'])
    if raw['lng'] is not None and raw['lng'] != '':
        entry[cm.lat] = string.atof(raw['lng'])
    gs.field_sense(entry)
    ret = gs.addr_sense(entry[cm.addr_e], entry[cm.country_e])
    if ret[1] is not None:
        entry[cm.province_e] = ret[1]
        gs.field_sense(entry)

    cm.dump(
        '(%s / %d) Found store: %s, %s (%s, %s)' %
        (data['brandname_e'], data['brand_id'], entry[cm.name_e],
         entry[cm.addr_e], entry[cm.country_e], entry[cm.continent_e]),
        log_name)
    db.insert_record(entry, 'stores')
    return [entry]
コード例 #4
0
def fetch_stores(data):
    url = data['url']
    try:
        body = cm.get_data(url)
    except Exception:
        cm.dump('Error in fetching stores: %s' % url, log_name)
        return []

    store_list = []
    for m1 in re.finditer(ur'<lignecountry\s+titre\s*=\s*"([^"]+)"', body):
        country = m1.group(1).strip().upper()
        if country == 'U.S.A.':
            country = 'US'
        sub_country = cm.extract_closure(body[m1.start():], ur'<lignecountry\b', ur'</lignecountry>')[0]
        for m2 in re.finditer(ur'<lignecity\s+titre\s*=\s*"([^"]+)"', sub_country):
            city = m2.group(1).strip().upper()
            sub_city = cm.extract_closure(sub_country[m2.start():], ur'<lignecity\b', ur'</lignecity>')[0]
            m3 = re.search(ur'<!\[CDATA\[(.+?)\]\]>', sub_city, re.S)
            if m3 is None:
                continue
            sub_city = m3.group(1)
            store_subs = re.split(ur'<\s*h2\s*>\s*LANVIN BOUTIQUE\s*<\s*/h2\s*>', sub_city)
            for s in store_subs:
                if s.strip() == '':
                    continue
                m4 = re.search(ur'<p>(.+?)</p>', s, re.S)
                if m4 is None:
                    continue
                entry = cm.init_store_entry(data['brand_id'], data['brandname_e'], data['brandname_c'])
                entry[cm.country_e] = country
                entry[cm.city_e] = city
                s = m4.group(1)
                m4 = re.search(ur'(.+?)\n\s*\n', s, re.S)
                if m4 is not None:
                    entry[cm.addr_e] = cm.reformat_addr(m4.group(1))
                m4 = re.search(ur'Phone:(.+?)\n\s*\n', s, re.S)
                if m4 is not None:
                    entry[cm.tel] = cm.reformat_addr(m4.group(1).strip())
                m4 = re.search(ur'Boutique Hours:(.+?)\n\s*\n', s, re.S)
                if m4 is not None:
                    entry[cm.hours] = cm.reformat_addr(m4.group(1).strip())
                m4 = re.search(ur'Products available:(.+?)\n\s*\n', s, re.S)
                if m4 is not None:
                    entry[cm.store_type] = m4.group(1).strip()
                m4 = re.search(ur'Email:\s*<a href="mailto:([^"]+)">', s)
                if m4 is not None:
                    entry[cm.email] = m4.group(1).strip()
                gs.field_sense(entry)
                ret = gs.addr_sense(entry[cm.addr_e], entry[cm.country_e])
                if ret[1] is not None and entry[cm.province_e] == '':
                    entry[cm.province_e] = ret[1]
                gs.field_sense(entry)
                cm.dump('(%s / %d) Found store: %s, %s (%s, %s)' % (data['brandname_e'], data['brand_id'],
                                                                    entry[cm.name_e], entry[cm.addr_e],
                                                                    entry[cm.country_e],
                                                                    entry[cm.continent_e]), log_name)
                db.insert_record(entry, 'stores')
                store_list.append(entry)
コード例 #5
0
ファイル: sergio.py プロジェクト: haizi-zh/ofashion
def fetch_stores(db, data, logger):
    """
    获得商店信息
    :param data:
    """
    url = data['post_url']
    try:
        html = cm.post_data(url, {
            'pid': data['city_id'],
            'lang': 'en',
            'action': 'popola_box_DX'
        })
        if html.strip() == u'':
            logger.error(
                unicode.format(u'Failed to fetch stores for city {0}',
                               data['city_id']))
            return []
        body = pq(html)
    except Exception as e:
        print 'Error occured in getting city list: %s' % url
        dump_data = {
            'level': 2,
            'time': cm.format_time(),
            'data': {
                'url': url
            },
            'brand_id': data['brand_id']
        }
        cm.dump(dump_data)
        return []

    store_list = []
    for item in (pq(temp) for temp in body('a[href]')):
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                    data['brandname_c'])
        entry[cm.url] = item[0].attrib['href']
        entry[cm.name_e] = item('h3.titleShop')[0].text.strip()

        # terms = cm.reformat_addr(item('div.txtBoxSingleStore p.lineHeight14')[0].text).split(',')
        terms = cm.reformat_addr(
            unicode(item('div.txtBoxSingleStore p.lineHeight14'))).split(',')
        tel = cm.extract_tel(terms[-1])
        if tel != '':
            terms = terms[:-1]
            entry[cm.tel] = tel
        entry[cm.addr_e] = u', '.join([v.strip() for v in terms])
        entry['country_e'] = data['country_e']
        entry['city_e'] = data['city_e']
        gs.field_sense(entry)

        logger.info(
            '(%s / %d) Found store: %s, %s (%s, %s)' %
            (data['brandname_e'], data['brand_id'], entry[cm.name_e],
             entry[cm.addr_e], entry[cm.country_e], entry[cm.continent_e]))
        store_list.append(entry)
        cm.insert_record(db, entry, 'spider_stores.stores')

    return store_list
コード例 #6
0
ファイル: kenzo.py プロジェクト: haizi-zh/ofashion
def fetch(level=1, data=None, user='******', passwd=''):
    db = cm.StoresDb()
    db.connect_db(user=user, passwd=passwd)
    db.execute(u'DELETE FROM %s WHERE brand_id=%d' % ('stores', brand_id))

    try:
        html = cm.get_data(url)
    except Exception:
        print 'Error occured: %s' % url
        dump_data = {
            'level': 1,
            'time': cm.format_time(),
            'data': {
                'url': url
            },
            'brand_id': brand_id
        }
        cm.dump(dump_data)
        return []

    js = json.loads(html)
    store_list = []
    for s in js['data']['list']:
        entry = cm.init_store_entry(brand_id, brandname_e, brandname_c)
        cm.update_entry(
            entry, {
                cm.lat: string.atof(s['geo']['lat']),
                cm.lng: string.atof(s['geo']['lng'])
            })
        entry[cm.name_e] = s['contact']['title']
        entry[cm.addr_e] = cm.reformat_addr(s['contact']['address'])
        entry[cm.tel] = s['contact']['phone']
        entry[cm.fax] = s['contact']['fax']
        entry[cm.hours] = cm.reformat_addr(s['contact']['hours'])
        entry[cm.store_type] = s['contact']['selling']
        entry[cm.url] = host + s['link']

        gs.update_city_map(s['city'], s['country'], s['continent'])
        cm.update_entry(
            entry, {
                cm.continent_e: s['continent'],
                cm.country_e: s['country'],
                cm.city_e: s['city']
            })
        gs.field_sense(entry)

        print '(%s / %d) Found store: %s, %s (%s, %s)' % (
            brandname_e, brand_id, entry[cm.name_e], entry[cm.addr_e],
            entry[cm.country_e], entry[cm.continent_e])
        db.insert_record(entry, 'stores')
        store_list.append(entry)

    db.disconnect_db()
    gs.commit_maps(1)
    gs.commit_maps(3)
    return store_list
コード例 #7
0
def fetch_stores(data):
    entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                data['brandname_c'])
    code = data['country_code']
    if gs.look_up(code, 1) is None:
        entry[cm.country_e] = cm.html2plain(data['country']).strip().upper()
    else:
        entry[cm.country_e] = code
    entry[cm.name_e] = data['store_name']
    entry[cm.city_e] = cm.extract_city(data['city'])[0]
    entry[cm.lat] = data['lat'] if data['lat'] is not None else ''
    entry[cm.lng] = data['lng'] if data['lng'] is not None else ''

    m = re.search(ur'data-boutique\s*=\s*"%s"' % data['store_id'],
                  data['content'])
    sub = data['content'][m.end():]

    m1 = re.search(ur'<li class="isDistributeur[^<>]+>(.+?)</li>', sub)
    if m1 is not None:
        entry[cm.store_class] = cm.reformat_addr(m1.group(1))

    m1 = re.search(ur'<li class="place-title[^<>]+>(.+?)</li>', sub, re.S)
    if m1 is not None:
        entry[cm.addr_e] = cm.reformat_addr(m1.group(1))

    m1 = re.search(ur'<li class="contacts[^<>]+>(.+?)</li>', sub, re.S)
    if m1 is not None:
        m2 = re.search(ur'<a class="popupLaunch" href="([^"]+)"', m1.group(1))
        if m2:
            entry = fetch_details(data, m2.group(1), entry)

        m2 = re.search(ur'<p>(.+?)</p>', m1.group(1), re.S)
        if m2:
            ct_list = tuple(
                tmp.strip()
                for tmp in cm.reformat_addr(m2.group(1)).split(','))
            entry[cm.tel] = cm.extract_tel(ct_list[0])
            if len(ct_list) > 1:
                entry[cm.email] = ct_list[1].strip()

    gs.field_sense(entry)
    ret = gs.addr_sense(entry[cm.addr_e], entry[cm.country_e])
    if ret[1] is not None and entry[cm.province_e] == '':
        entry[cm.province_e] = ret[1]
    if ret[2] is not None and entry[cm.city_e] == '':
        entry[cm.city_e] = ret[2]
    gs.field_sense(entry)

    cm.dump(
        '(%s / %d) Found store: %s, %s (%s, %s)' %
        (data['brandname_e'], data['brand_id'], entry[cm.name_e],
         entry[cm.addr_e], entry[cm.country_e], entry[cm.continent_e]),
        log_name)
    db.insert_record(entry, 'stores')

    return tuple(entry)
コード例 #8
0
ファイル: jimmy_choo.py プロジェクト: haizi-zh/ofashion
def fetch_uk(body, data):
    start = body.find(u'<div class="fableft">')
    if start == -1:
        print 'Error in finding %s stores' % data['name']
        return []
    body, start, end = cm.extract_closure(body[start:], ur'<div\b', ur'</div>')
    if end == 0:
        print 'Error in finding %s stores' % data['name']
        return []

    store_list = []
    for m in re.findall(ur'<div>\s*(.+?)\s*</div>', body, re.S):
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                    data['brandname_c'])
        entry[cm.country_e] = data['name']

        addr_list = re.findall(ur'<p>\s*(.+?)\s*</p>', m)
        tel = cm.extract_tel(addr_list[-1])
        if tel != '':
            entry[cm.tel] = tel
            del addr_list[-1]

        if data['name'] == 'AUSTRALIA':
            country, province, city = gs.addr_sense(', '.join(addr_list),
                                                    data['name'])
            if city is not None:
                entry[cm.city_e] = city
            if province is not None:
                entry[cm.province_e] = province
        else:
            city = addr_list[-2].strip().upper()
            entry[cm.city_e] = city
            ret = gs.look_up(city, 3)
            if ret is not None and ret['country']['name_e'] == gs.look_up(
                    'UK', 1)['name_e']:
                entry[cm.city_e] = ret['name_e']
            entry[cm.zip_code] = addr_list[-1].strip().upper()
        entry[cm.addr_e] = ', '.join(addr_list)
        entry[cm.city_e] = cm.extract_city(entry[cm.city_e])[0]

        gs.field_sense(entry)
        ret = gs.addr_sense(entry[cm.addr_e], entry[cm.country_e])
        if ret[1] is not None and entry[cm.province_e] == '':
            entry[cm.province_e] = ret[1]
        if ret[2] is not None and entry[cm.city_e] == '':
            entry[cm.city_e] = ret[2]
        gs.field_sense(entry)

        print '(%s / %d) Found store: %s, %s (%s, %s, %s)' % (
            data['brandname_e'], data['brand_id'], entry[cm.name_e],
            entry[cm.addr_e], entry[cm.city_e], entry[cm.country_e],
            entry[cm.continent_e])

        db.insert_record(entry, 'stores')
        store_list.append(entry)
コード例 #9
0
def fetch_stores(data):
    url = data['url']
    try:
        body = cm.get_data(url)
    except Exception:
        cm.dump('Error occured in fetching stores: %s' % url, 'canali_log.txt')
        dump_data = {
            'level': 0,
            'time': cm.format_time(),
            'data': {
                'url': url
            },
            'brand_id': data['brand_id']
        }
        cm.dump(dump_data)
        return []

    store_list = []
    for m in re.finditer(ur'<div class="storeInfo">', body):
        sub = cm.extract_closure(body[m.start():], ur'<div\b', ur'</div>')[0]
        m1 = re.search(ur'<span itemprop="streetAddress">(.+?)</span>', sub)
        if m1 is None:
            cm.dump('Error: failed to find the address: %s' % url,
                    'canali_log.txt')
            continue
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                    data['brandname_c'])
        entry[cm.addr_e] = cm.reformat_addr(m1.group(1))
        entry[cm.country_e] = data['country']
        entry[cm.city_e] = data['city']
        ret = gs.addr_sense(entry[cm.addr_e], entry[cm.country_e])
        if ret[1] is not None:
            entry[cm.province_e] = ret[1]

        m1 = re.search(ur'<span itemprop="telephone">(.+?)</span>', sub)
        if m1 is not None:
            entry[cm.tel] = m1.group(1).strip()

        m1 = re.search(ur'data-latitude="(.+?)"', sub)
        if m1 is not None:
            entry[cm.lat] = string.atof(m1.group(1))
        m1 = re.search(ur'data-longitude="(.+?)"', sub)
        if m1 is not None:
            entry[cm.lng] = string.atof(m1.group(1))

        gs.field_sense(entry)
        cm.dump(
            '(%s / %d) Found store: %s, %s (%s, %s)' %
            (data['brandname_e'], data['brand_id'], entry[cm.name_e],
             entry[cm.addr_e], entry[cm.country_e], entry[cm.continent_e]),
            'canali_log.txt')
        db.insert_record(entry, 'stores')
        store_list.append(entry)
コード例 #10
0
def fetch_stores(data):
    url = '%s/en/shops/%s.json' % (
        data['host'], urllib.quote(data['country_id'].encode('utf-8')))
    try:
        body = cm.get_data(url)
        raw = json.loads(body)
    except Exception:
        cm.dump('Error in fetching stores: %s' % url, 'unode50_log.txt')
        dump_data = {
            'level': 0,
            'time': cm.format_time(),
            'data': {
                'url': url
            },
            'brand_id': data['brand_id']
        }
        cm.dump(dump_data)
        return []

    store_items = []
    for s in raw['distributors']:
        s['store_class'] = 'distributor'
        store_items.append(s)
    for s in raw['shops']:
        s['store_class'] = 'shop'
        store_items.append(s)

    store_list = []
    for s in store_items:
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                    data['brandname_c'])
        entry[cm.store_class] = s['store_class']
        entry[cm.country_e] = data['country']
        entry[cm.name_e] = s['title']
        if s['lat'] is not None:
            entry[cm.lat] = string.atof(str(s['lat']))
        if s['lng'] is not None:
            entry[cm.lng] = string.atof(str(s['lng']))
        entry[cm.addr_e] = s['address']
        entry[cm.city_e] = cm.extract_city(s['city'])[0]
        entry[cm.tel] = s['phone']
        entry[cm.zip_code] = s['postal_code']
        gs.field_sense(entry)
        cm.dump(
            '(%s / %d) Found store: %s, %s (%s, %s, %s)' %
            (data['brandname_e'], data['brand_id'], entry[cm.name_e],
             entry[cm.addr_e], entry[cm.city_e], entry[cm.country_e],
             entry[cm.continent_e]), 'unode50_log.txt')
        db.insert_record(entry, 'stores')
        store_list.append(entry)

    return store_list
コード例 #11
0
def fetch_stores(data):
    url = data['host'] + data['data_url']
    if data['province_code'] != '':
        param = {
            'region': data['continent'],
            'country': data['country_code'],
            'state': data['province_code']
        }
    else:
        param = {'region': data['continent'], 'country': data['country_code']}
    try:
        body = cm.get_data(url, param)
    except Exception:
        cm.dump('Error in fetching stores: %s, %s' % (url, param), log_name)
        return []

    raw = json.loads(body)['stores']
    store_list = []
    for s in raw:
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                    data['brandname_c'])
        entry[cm.name_e] = s['name']
        entry[cm.province_e] = data['province_code'].strip().upper()
        entry[cm.country_e] = data['country_code'].strip().upper()
        entry[cm.city_e] = s['city'].strip().upper()

        addr_list = []
        for tmp in ['address%d' % idx for idx in xrange(1, 4)]:
            if tmp in s and s[tmp] is not None and s[tmp].strip() != '':
                addr_list.append(s[tmp].strip())
        entry[cm.addr_e] = ', '.join(addr_list)
        entry[cm.tel] = s['phone']
        entry[cm.zip_code] = s['postalCode']
        hours = ''
        for item in s['openingHours']:
            hours += '%s %s' % (item['days'], item['openingHours'])
        entry[cm.hours] = hours
        entry[cm.url] = s['storePageUrl']
        coords = s['coords']
        entry[cm.lat] = string.atof(coords['lat'])
        entry[cm.lng] = string.atof(coords['lng'])

        gs.field_sense(entry)
        cm.dump(
            '(%s / %d) Found store: %s, %s (%s, %s)' %
            (data['brandname_e'], data['brand_id'], entry[cm.name_e],
             entry[cm.addr_e], entry[cm.country_e], entry[cm.continent_e]),
            log_name)
        db.insert_record(entry, 'stores')
        store_list.append(entry)

    return store_list
コード例 #12
0
ファイル: marni.py プロジェクト: haizi-zh/ofashion
def fetch_stores(data):
    """
    获得商店信息
    :param data:
    """
    url = data['url']
    try:
        info = json.loads(cm.get_data(url, {'tskay': data['key_term']}))
    except Exception:
        print 'Error occured: %s' % url
        dump_data = {'level': 0, 'time': cm.format_time(), 'data': {'url': url}, 'brand_id': data['brand_id']}
        cm.dump(dump_data)
        return []

    raw_list = info['shops']
    store_list = []
    for s in raw_list:
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'], data['brandname_c'])
        entry[cm.city_e] = s['city'].strip().upper()
        entry[cm.country_e] = data['country_e'].strip().upper()
        entry[cm.name_e] = s['name'].strip()
        addr = s['address']
        entry[cm.addr_e] = addr

        terms = addr.split(',')
        if len(terms) > 1 and entry[cm.city_e] in terms[-1].strip().upper():
            country = entry['country_e']
            tmp = gs.look_up(country, 1)
            if tmp is not None:
                country = tmp['name_e']
            if country == 'JAPAN':
                # 日本邮编
                m = re.search(ur'\d{3,}[ -\.]+?\d{3,}', terms[-1])
                if m is not None:
                    entry[cm.zip_code] = m.group(0)
            else:
                m = re.search(ur'\d{4,}', terms[-1])
                if m is not None:
                    entry[cm.zip_code] = m.group(0)

        entry[cm.tel] = s['tel']
        entry[cm.fax] = s['fax']
        entry[cm.email] = s['email']
        gs.field_sense(entry)

        print '(%s / %d) Found store: %s, %s (%s, %s)' % (data['brandname_e'], data['brand_id'],
                                                          entry[cm.name_e], entry[cm.addr_e], entry[cm.country_e],
                                                          entry[cm.continent_e])
        store_list.append(entry)
        # db.insert_record(entry, 'stores')

    return store_list
コード例 #13
0
def fetch_stores(data):
    url = data['store_url']
    param = {'myid': data['key'], 'idioma': 'in'}
    try:
        body = cm.get_data(url, param)
    except Exception:
        cm.dump('Error in fetching countries: %s, %s' % (url, param), log_name)
        return []

    store_list = []
    for s in json.loads(body):
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                    data['brandname_c'])
        entry[cm.country_e] = data['country']
        entry[cm.city_e] = cm.extract_city(data['city'])[0]
        entry[cm.name_e] = cm.reformat_addr(s['title'])

        m = re.search(ur'(.+?)-\s*<', s['key'])
        addr_list = [entry[cm.name_e]]
        if m is not None:
            m1 = re.search(ur'-+', m.group(1))
            if m1 is not None:
                tmp = [m.group(1)[:m1.start()], m.group(1)[m1.end():]]
            else:
                tmp = [m.group(1)]
            if len(tmp) > 1:
                entry[cm.tel] = cm.extract_tel(tmp[1])
            m1 = re.search(ur'\d{4,}', tmp[0])
            if m1 is not None:
                entry[cm.zip_code] = m1.group()
            addr_list.append(tmp[0].strip())
        entry[cm.addr_e] = ', '.join(addr_list)

        gs.field_sense(entry)
        ret = gs.addr_sense(entry[cm.addr_e])
        if ret[0] is not None and entry[cm.country_e] == '':
            entry[cm.country_e] = ret[0]
        if ret[1] is not None and entry[cm.province_e] == '':
            entry[cm.province_e] = ret[1]
        if ret[2] is not None and entry[cm.city_e] == '':
            entry[cm.city_e] = ret[2]
        gs.field_sense(entry)
        cm.dump(
            '(%s / %d) Found store: %s, %s (%s, %s)' %
            (data['brandname_e'], data['brand_id'], entry[cm.name_e],
             entry[cm.addr_e], entry[cm.country_e], entry[cm.continent_e]),
            log_name)
        db.insert_record(entry, 'stores')
        store_list.append(entry)

    return store_list
コード例 #14
0
ファイル: levis_us.py プロジェクト: haizi-zh/ofashion
def fetch_hk(data):
    loc_list = ('Hong Kong', 'Kowloon', 'Macau', 'New Territories')
    url = 'http://levi.com.hk/hk/storelocator'
    store_list = []
    for loc in loc_list:
        param = {'loc': loc}
        try:
            body = cm.get_data(url, param)
        except Exception, e:
            cm.dump('Error in fetching stores: %s' % param, log_name)
            continue

        start = body.find(ur'<div id="addWrapper">')
        if start == -1:
            cm.dump('Error in fetching stores: %s' % param, log_name)
            continue
        sub = cm.extract_closure(body[start:], ur'<ul>', ur'</ul>')[0]
        for s in re.findall(ur'<li>(.+?)</li>', sub, re.S):
            entry = cm.init_store_entry(data['brand_id'], data['brandname_e'], data['brandname_c'])
            entry[cm.country_e] = 'MACAU' if loc == 'Macau' else 'HONG KONG'
            entry[cm.city_e] = entry[cm.country_e]

            m = re.search(ur'<div id="addStore">([^<>]+)', s)
            entry[cm.addr_e] = cm.html2plain(m.group(1)) if m else ''

            m = re.search(ur'<div id="addAddress">([^<>]+)', s)
            tmp = cm.html2plain(m.group(1))
            pat = re.compile(ur'business hours?\s*[:\.]?\s*', re.I)
            if re.search(pat, tmp):
                entry[cm.hours] = re.sub(pat, '', tmp).strip()

            m = re.search(ur'<div id="addPhone">([^<>]+)', s)
            tmp = cm.html2plain(m.group(1))
            pat = re.compile(ur'(tel|phone|telephone)?\s*[:\.]?\s*', re.I)
            if re.search(pat, tmp):
                entry[cm.tel] = re.sub(pat, '', tmp).strip()

            gs.field_sense(entry)
            ret = gs.addr_sense(entry[cm.addr_e], entry[cm.country_e])
            if ret[1] is not None and entry[cm.province_e] == '':
                entry[cm.province_e] = ret[1]
            if ret[2] is not None and entry[cm.city_e] == '':
                entry[cm.city_e] = ret[2]
            gs.field_sense(entry)

            cm.dump('(%s / %d) Found store: %s, %s (%s, %s)' % (data['brandname_e'], data['brand_id'],
                                                                entry[cm.name_e], entry[cm.addr_e], entry[cm.country_e],
                                                                entry[cm.continent_e]), log_name)
            db.insert_record(entry, 'stores')
            store_list.append(entry)
コード例 #15
0
ファイル: paulsmith.py プロジェクト: haizi-zh/ofashion
def fetch_details(data):
    url = data[cm.url]
    try:
        html = cm.get_data(url)
    except Exception:
        print 'Error occured: %s' % url
        dump_data = {'level': 0, 'time': cm.format_time(), 'data': {'url': url}, 'brand_id': data['brand_id']}
        cm.dump(dump_data)
        return []

    entry = cm.init_store_entry(data['brand_id'], data['brandname_e'], data['brandname_c'])
    entry[cm.name_e] = data[cm.name_e]
    start = html.find(ur'<div class="field-address">')
    if start == -1:
        return []
    sub, start, end = cm.extract_closure(html[start:], ur'<div\b', ur'</div>')
    if end == 0:
        return []
    m1 = re.search(ur'<div  class="locality">(.+?)</div>', sub)
    if m1 is not None:
        entry[cm.city_e] = cm.extract_city(m1.group(1))[0]
    m1 = re.search(ur'<div  class="postal-code">(.+?)</div>', sub)
    if m1 is not None:
        entry[cm.zip_code] = m1.group(1).strip()
    entry[cm.country_e] = data[cm.country_e]
    pat = re.compile(ur'<[^<>]+?>', re.S)
    entry[cm.addr_e] = cm.reformat_addr(re.sub(pat, u'\r\n', sub))

    m1 = re.search(ur'<div class="field-telephone"><a href=".+?" class="tel">(.+?)</a></div>', html)
    if m1 is not None:
        entry[cm.tel] = m1.group(1).strip()

    m1 = re.search(ur'<div class="field-opening-hours">\s*<p>(.+?)</p>\s*</div>', html, re.S)
    if m1 is not None:
        entry[cm.hours] = cm.reformat_addr(m1.group(1))

    m1 = re.search(ur'"coordinates":\[(-?\d+\.\d{4,})\s*,\s*(-?\d+\.\d{4,})\]', html)
    if m1 is not None:
        lat = string.atof(m1.group(1))
        lng = string.atof(m1.group(2))
        cm.update_entry(entry, {cm.lat: lat, cm.lng: lng})

    entry[cm.continent_e] = data[cm.continent_e]
    gs.field_sense(entry)
    print '(%s / %d) Found store: %s, %s (%s, %s)' % (data['brandname_e'], data['brand_id'],
                                                      entry[cm.name_e], entry[cm.addr_e], entry[cm.country_e],
                                                      entry[cm.continent_e])
    db.insert_record(entry, 'stores')
    return [entry]
コード例 #16
0
    def func(item):
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                    data['brandname_c'])
        entry[cm.name_e] = cm.html2plain(item('h6')[0].text).strip()
        addr_sub = unicode(pq(item('p')[0]))
        addr_list = [
            term.strip() for term in cm.reformat_addr(addr_sub).split(',')
        ]
        tel = cm.extract_tel(addr_list[-1])
        if tel != '':
            entry[cm.tel] = tel
            del addr_list[-1]
        entry[cm.addr_e] = ', '.join(addr_list)

        temp = item('a.track_map[href]')
        m = hashlib.md5()
        m.update(url)
        if len(temp) > 0:
            map_ref = temp[0].attrib['href']
            m.update(map_ref)
            m_query = re.search(r'q=([^;]+?)&', cm.html2plain(map_ref))
            if m_query:
                query_parm = m_query.group(1).replace('+', ' ')
                entry['geo_query_param'] = query_parm

        else:
            m.update(entry[cm.addr_e])
        fingerprint = m.hexdigest()
        entry[cm.native_id] = fingerprint
        if entry[cm.native_id] in data['store_list']:
            return

        entry[cm.country_e] = data['country']
        gs.field_sense(entry)
        ret = gs.addr_sense(entry[cm.addr_e])
        if ret[0] is not None and entry[cm.country_e] == '':
            entry[cm.country_e] = ret[0]
        if ret[1] is not None and entry[cm.province_e] == '':
            entry[cm.province_e] = ret[1]
        if ret[2] is not None and entry[cm.city_e] == '':
            entry[cm.city_e] = ret[2]
        gs.field_sense(entry)

        logger.info(
            ('(%s / %d) Found store: %s, %s (%s, %s)' %
             (data['brandname_e'], data['brand_id'], entry[cm.name_e],
              entry[cm.addr_e], entry[cm.country_e], entry[cm.continent_e])))
        cm.insert_record(db, entry, data['table'])
        return entry
コード例 #17
0
ファイル: samsonite.py プロジェクト: haizi-zh/ofashion
def fetch_stores(data):
    url = data['home_url']
    try:
        body = cm.post_data(url, {'lz_sf': data['province'], 'lz_sx': data['city']})
    except Exception:
        cm.dump('Error in fetching stores: %s, %s, %s' % (url, data['province'], data['city']),
                'samsonite_log.txt')
        dump_data = {'level': 0, 'time': cm.format_time(), 'data': {'url': url}, 'brand_id': data['brand_id']}
        cm.dump(dump_data)
        return []

    start = body.find(u'搜索结果')
    if start == -1:
        cm.dump('Error in fetching stores: %s, %s, %s' % (url, data['province'], data['city']),
                'samsonite_log.txt')
        return []

    body = body[start + 4:]

    store_list = []
    for m in re.findall(ur'</script>\s*(\S+)\s*</span>', body, re.S):
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'], data['brandname_c'])
        entry[cm.name_e] = m.strip()
        entry[cm.addr_e] = m.strip()
        entry[cm.city_c] = data['city']
        ret = gs.look_up(data['city'], 3)
        if ret is not None:
            entry[cm.city_e] = cm.extract_city(ret['name_e'])[0]
            if ret['province'] != '':
                entry[cm.province_e] = ret['province']['name_e']
        entry[cm.province_c] = data['province']
        ret = gs.look_up(data['province'], 2)
        if ret is not None:
            entry[cm.province_e] = ret['name_e']
        entry[cm.country_e] = u'CHINA'

        gs.field_sense(entry)
        ret = gs.addr_sense(entry[cm.addr_e], entry[cm.country_e])
        if ret[1] is not None and entry[cm.province_e] == '':
            entry[cm.province_e] = ret[1]
        if ret[2] is not None and entry[cm.city_e] == '':
            entry[cm.city_e] = ret[2]
        gs.field_sense(entry)
        cm.dump('(%s / %d) Found store: %s, %s (%s, %s)' % (data['brandname_e'], data['brand_id'],
                                                            entry[cm.name_e], entry[cm.addr_e], entry[cm.country_e],
                                                            entry[cm.continent_e]), 'benetton_log.txt', False)
        db.insert_record(entry, 'stores')
        store_list.append(entry)
コード例 #18
0
ファイル: oasis.py プロジェクト: haizi-zh/ofashion
def fetch_store_details(data):
    # http://maps.oasis-stores.com/index-v2.php?coutnryISO=GB&brand=oasis&lat=51.42014&lng=-0.20954
    url = data['store_url']
    code = data['country_code']
    city = data['city_e']

    try:
        html = cm.get_data(url, {'latitude': data['lat'], 'longitude': data['lng'], 'brand': 'oasis'})
    except Exception:
        print 'Error occured: %s' % url
        dump_data = {'level': 0, 'time': cm.format_time(), 'data': {'url': url}, 'brand_id': data['brand_id']}
        cm.dump(dump_data)
        return []

    raw = json.loads(html)
    entry = cm.init_store_entry(data['brand_id'], data['brandname_e'], data['brandname_c'])
    entry[cm.name_e] = raw['name']
    addr_list = []
    for i in xrange(1, 4):
        tmp = cm.html2plain(raw['address%d' % i]).strip()
        if tmp != '':
            addr_list.append(tmp)
    entry[cm.addr_e] = ', '.join(addr_list)
    state = raw['countryRegion']
    if state is not None and state.strip() != '':
        entry[cm.province_e] = state.strip().upper()
    state = raw['state']
    if state is not None and state.strip() != '':
        entry[cm.province_e] = state.strip().upper()
    state = raw['county']
    if state is not None and state.strip() != '':
        entry[cm.province_e] = state.strip().upper()
    entry[cm.zip_code] = raw['postcode']
    entry[cm.country_e] = data['country_e']
    entry[cm.city_e] = cm.extract_city(data['city_e'])[0]
    entry[cm.lat] = string.atof(data['lat'])
    entry[cm.lng] = string.atof(data['lng'])
    entry[cm.tel] = raw['phone']
    entry[cm.email] = raw['email']
    tmp = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
    entry[cm.hours] = ', '.join([raw[d + '_open_times'] for d in tmp])
    gs.field_sense(entry)
    print '(%s / %d) Found store: %s, %s (%s, %s)' % (data['brandname_e'], data['brand_id'],
                                                      entry[cm.name_e], entry[cm.addr_e], entry[cm.country_e],
                                                      entry[cm.continent_e])
    db.insert_record(entry, 'stores')

    return [entry]
コード例 #19
0
def fetch_stores(data):
    url = data['home_url']
    try:
        body = cm.get_data(url)
    except Exception:
        print 'Error occured: %s' % url
        dump_data = {'level': 0, 'time': cm.format_time(), 'data': {'url': url}, 'brand_id': data['brand_id']}
        cm.dump(dump_data)
        return []

    raw = json.loads(body)['results']
    store_list = []
    for key in raw:
        store = raw[key]
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'], data['brandname_c'])
        entry[cm.name_e] = store['post_title']
        entry[cm.url] = store['post_permalink'].replace(u'\\', '')
        entry[cm.country_e] = store['country'].strip().upper()
        entry[cm.city_e] = store['city'].strip().upper()

        if '_yoox_store_latlong' in store:
            m = re.findall(ur'-?\d+\.\d+', store['_yoox_store_latlong'])
            if len(m) == 2:
                entry[cm.lat] = string.atof(m[0])
                entry[cm.lng] = string.atof(m[1])

        if 'store_phone' in store:
            entry[cm.tel] = store['store_phone'].replace('P:', '').replace('T:', '') \
                .replace('P', '').replace('T', '').strip()
        if 'store_email' in store:
            entry[cm.email] = store['store_email']
        if 'store_fax' in store:
            entry[cm.fax] = store['store_fax'].replace('F:', '').replace('F', '').strip()
        if 'store_hours' in store:
            entry[cm.hours] = cm.reformat_addr(store['store_hours'])
        if 'store_address' in store:
            entry[cm.addr_e] = cm.reformat_addr(store['store_address'])
        if 'women' in store and 'men' in store:
            entry[cm.store_type] = 'Women: %s, men: %s' % (', '.join(store['women']), ', '.join(store['men']))

        gs.field_sense(entry)
        print '(%s / %d) Found store: %s, %s (%s, %s)' % (data['brandname_e'], data['brand_id'],
                                                          entry[cm.name_e], entry[cm.addr_e], entry[cm.country_e],
                                                          entry[cm.continent_e])
        db.insert_record(entry, 'stores')
        store_list.append(entry)

    return store_list
コード例 #20
0
def fetch_stores_cn(data):
    vals = ['Storenew%d.html' % idx for idx in xrange(1, 10)]
    vals.append('Store.html')
    store_list = []
    for url in ('http://www.hushpuppies.com.cn/%s' % term for term in vals):
        try:
            body = cm.get_data(url)
        except Exception, e:
            cm.dump('Error in fetching stores: %s' % url, log_name)
            return ()

        city_map = dict((m[0].strip(), m[1].strip()) for m in re.findall(
            ur'<a rel="([^"]+)" href="#"[^<>]*>([^<>]+)', body))

        start = body.find(ur'<div id="all-list-wrap" style="float:left">')
        if start == -1:
            cm.dump('Error in fetching stores: %s' % url, log_name)
            return ()
        sub = cm.extract_closure(body[start:], ur'<div\b', ur'</div>')[0]

        for m in re.findall(ur'<ul id="([^"]+)"[^<>]*>(.+?)</ul>', sub, re.S):
            city = city_map[m[0].strip()]
            for store in re.findall(ur'<li><a>([^<>]+)', m[1]):
                entry = cm.init_store_entry(data['brand_id'],
                                            data['brandname_e'],
                                            data['brandname_c'])
                entry[cm.country_e] = u'CHINA'
                entry[cm.city_e] = city
                entry[cm.addr_e] = store.strip()

                gs.field_sense(entry)
                ret = gs.addr_sense(entry[cm.addr_e], entry[cm.country_e])
                if ret[1] is not None and entry[cm.province_e] == '':
                    entry[cm.province_e] = ret[1]
                if ret[2] is not None and entry[cm.city_e] == '':
                    entry[cm.city_e] = ret[2]
                gs.field_sense(entry)

                cm.dump(
                    '(%s / %d) Found store: %s, %s (%s, %s)' %
                    (data['brandname_e'], data['brand_id'], entry[cm.name_e],
                     entry[cm.addr_e], entry[cm.country_e],
                     entry[cm.continent_e]), log_name)
                db.insert_record(entry, 'stores')
                store_list.append(entry)
コード例 #21
0
ファイル: paul_joe.py プロジェクト: haizi-zh/ofashion
def fetch_stores(db, data, logger):
    q = pq(url='http://www.paulandjoe.com/en/ozcms/stores/list/?country_id=&postcode=')

    store_list = []

    # Country
    country_a = q('#store_list>li>a')
    country_b = q('#store_list>li>ul')
    assert (len(country_a) == len(country_b))
    for i in xrange(len(country_a)):
        country = country_a[i].text.strip().upper()
        store_a = pq(country_b[i])('a.marker-store')
        store_b = pq(country_b[i])('span.store-infos')
        assert (len(store_a) == len(store_b))
        for j in xrange(len(store_a)):
            entry = cm.init_store_entry(data['brand_id'], data['brandname_e'], data['brandname_c'])

            lat = store_a[j].attrib['data-latitude']
            lat = float(lat) if lat else None
            lng = store_a[j].attrib['data-longitude']
            lng = float(lng) if lng else None
            if lat and lng:
                entry[cm.lat], entry[cm.lng] = lat, lng

            entry[cm.name_e] = store_a[j].text
            entry[cm.addr_e] = cm.reformat_addr(str(pq(store_b[j])))  # cm.reformat_addr(str(store_b[j]))
            entry[cm.country_e] = country

            gs.field_sense(entry)
            ret = gs.addr_sense(entry[cm.addr_e])
            if ret[0] is not None and entry[cm.country_e] == '':
                entry[cm.country_e] = ret[0]
            if ret[1] is not None and entry[cm.province_e] == '':
                entry[cm.province_e] = ret[1]
            if ret[2] is not None and entry[cm.city_e] == '':
                entry[cm.city_e] = ret[2]
            gs.field_sense(entry)
            logger.info('(%s/%d) Found store: %s, %s (%s, %s)' % (data['brandname_e'], data['brand_id'],
                                                                  entry[cm.name_e], entry[cm.addr_e],
                                                                  entry[cm.country_e],
                                                                  entry[cm.continent_e]))
            store_list.append(entry)
            cm.insert_record(db, entry, 'spider_stores.stores')

    return tuple(store_list)
コード例 #22
0
ファイル: juicycouture.py プロジェクト: haizi-zh/ofashion
def fetch_stores(data):
    url = data['url']
    try:
        body = cm.get_data(url, {'countryCode': data['country_code']})
    except Exception:
        print 'Error occured in fetching stores: %s, %s' % (url, data['country_code'])
        dump_data = {'level': 0, 'time': cm.format_time(), 'data': {'url': url}, 'brand_id': data['brand_id']}
        cm.dump(dump_data)
        return []

    raw = json.loads(body)['stores']
    store_list = []
    for key in raw:
        store = raw[key]
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'], data['brandname_c'])
        entry[cm.name_e] = store['name']
        addr = store['address1']
        if store['address2'] != '':
            addr += ', ' + store['address2']
        entry[cm.addr_e] = addr
        entry[cm.zip_code] = store['postalCode']
        entry[cm.city_e] = store['city'].strip().upper()
        entry[cm.province_e] = store['stateCode'].strip().upper()
        entry[cm.country_e] = data['country_code']
        entry[cm.tel] = store['phone']
        entry[cm.fax] = store['fax']
        entry[cm.email] = store['email']
        entry[cm.hours] = store['storeHours']
        if store['latitude'] != '':
            entry[cm.lat] = string.atof(store['latitude'])
        if store['longitude'] != '':
            entry[cm.lng] = string.atof(store['longitude'])

        gs.field_sense(entry)
        print '(%s / %d) Found store: %s, %s (%s, %s)' % (data['brandname_e'], data['brand_id'],
                                                          entry[cm.name_e], entry[cm.addr_e], entry[cm.country_e],
                                                          entry[cm.continent_e])
        db.insert_record(entry, 'stores')
        store_list.append(entry)

    return store_list
コード例 #23
0
def fetch_stores(data):
    url = data['store_url']
    try:
        body = cm.get_data(url, {
            'country': data['country'],
            'city': data['city']
        })
    except Exception:
        print 'Error occured: %s' % url
        dump_data = {
            'level': 0,
            'time': cm.format_time(),
            'data': {
                'url': url
            },
            'brand_id': data['brand_id']
        }
        cm.dump(dump_data)
        return []

    raw = json.loads(body)
    store_list = []

    for item in raw['items']:
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                    data['brandname_c'])
        entry[cm.country_e] = data['country'].strip().upper()
        tmp = cm.extract_city(data['city'])[0]
        if entry[cm.country_e] == 'USA':
            entry[cm.province_e] = tmp
        else:
            entry[cm.city_e] = tmp
        gs.field_sense(entry)

        addr = cm.reformat_addr(item['address'].replace(u'\\', ''))
        addr_list = [tmp.strip() for tmp in addr.split(',')]
        tel = cm.extract_tel(addr_list[-1])
        if tel != '':
            entry[cm.tel] = tel
            del addr_list[-1]
        entry[cm.addr_e] = ', '.join(addr_list)
        entry[cm.store_type] = item['shop_type']

        gs.field_sense(entry)
        ret = gs.addr_sense(entry[cm.addr_e])
        if ret[0] is not None and entry[cm.country_e] == '':
            entry[cm.country_e] = ret[0]
        if ret[1] is not None and entry[cm.province_e] == '':
            entry[cm.province_e] = ret[1]
        if ret[2] is not None and entry[cm.city_e] == '':
            entry[cm.city_e] = ret[2]
        gs.field_sense(entry)

        print '(%s / %d) Found store: %s, %s (%s, %s)' % (
            data['brandname_e'], data['brand_id'], entry[cm.name_e],
            entry[cm.addr_e], entry[cm.country_e], entry[cm.continent_e])
        db.insert_record(entry, 'stores')
        store_list.append(entry)

    return store_list
コード例 #24
0
def fetch_cn(data):
    url = 'http://www.lee.com.cn/xml/storefinder.xml'

    store_list = []
    for store in (pq(tmp) for tmp in pq(url=url)('NewDataSet Table')):
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                    data['brandname_c'])
        tmp = store('shop_name')[0]
        entry[cm.name_e] = tmp.text if tmp.text else ''
        entry[cm.country_e] = 'CHINA'
        tmp = store('city')[0]
        entry[cm.city_e] = tmp.text if tmp.text else ''
        tmp = store('province')[0]
        entry[cm.province_e] = tmp.text if tmp.text else ''
        tmp = store('district')[0]
        entry[cm.district_e] = tmp.text if tmp.text else ''
        tmp = store('address')[0]
        entry[cm.addr_e] = tmp.text if tmp.text else ''
        tmp = store('tel')[0]
        entry[cm.tel] = tmp.text if tmp.text else ''

        gs.field_sense(entry)
        ret = gs.addr_sense(entry[cm.addr_e])
        if ret[0] is not None and entry[cm.country_e] == '':
            entry[cm.country_e] = ret[0]
        if ret[1] is not None and entry[cm.province_e] == '':
            entry[cm.province_e] = ret[1]
        if ret[2] is not None and entry[cm.city_e] == '':
            entry[cm.city_e] = ret[2]
        gs.field_sense(entry)
        cm.dump(
            '(%s / %d) Found store: %s, %s (%s, %s, %s)' %
            (data['brandname_e'], data['brand_id'], entry[cm.name_e],
             entry[cm.addr_e], entry[cm.city_e], entry[cm.country_e],
             entry[cm.continent_e]), log_name)
        db.insert_record(entry, 'stores')
        store_list.append(entry)

    return tuple(store_list)
コード例 #25
0
def fetch_stores(data):
    url = data['host'] + '/en/jil_store_stores.json'
    try:
        body = cm.get_data(url, {'city': data['city']})
    except Exception:
        print 'Error occured: %s' % url
        dump_data = {'level': 0, 'time': cm.format_time(), 'data': {'url': url}, 'brand_id': data['brand_id']}
        cm.dump(dump_data)
        return []

    raw = json.loads(body)

    store_list = []
    for store in raw:
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'], data['brandname_c'])
        entry[cm.name_e] = store['title']
        entry[cm.country_e] = store['country'].strip().upper()
        entry[cm.city_e] = store['city'].strip().upper()
        entry[cm.lat] = string.atof(store['lat'])
        entry[cm.lng] = string.atof(store['lng'])
        entry[cm.tel] = store['telephone']

        addr = store['address']
        terms = addr.split(',')
        m = re.search(ur'\d{5,}', terms[-1])
        if m is not None:
            entry[cm.zip_code] = m.group(0)
        entry[cm.addr_e] = addr

        gs.field_sense(entry)
        print '(%s / %d) Found store: %s, %s (%s, %s)' % (data['brandname_e'], data['brand_id'],
                                                          entry[cm.name_e], entry[cm.addr_e], entry[cm.country_e],
                                                          entry[cm.continent_e])
        db.insert_record(entry, 'stores')
        store_list.append(entry)

    return store_list
コード例 #26
0
        entry[cm.zip_code] = raw['postcode']
        entry[cm.city_e] = cm.extract_city(raw['city'])[0]
        entry[cm.province_e] = raw['region']
        entry[cm.tel] = raw['phone']
        entry[cm.fax] = raw['fax']
        entry[cm.email] = raw['email']
        entry[cm.hours] = cm.reformat_addr(raw['opening'])
        entry[cm.lat] = string.atof(raw['latitude'])
        entry[cm.lng] = string.atof(raw['longitude'])
        entry[cm.url] = raw['link'].replace('\\', '')

        raw = js['Country']
        entry[cm.country_e] = raw['name']
        raw = js['StoreLocatorType']
        entry[cm.store_type] = raw['name']
        gs.field_sense(entry)

        print '(%s / %d) Found store: %s, %s (%s, %s)' % (
            brandname_e, brand_id, entry[cm.name_e], entry[cm.addr_e],
            entry[cm.country_e], entry[cm.continent_e])
        db.insert_record(entry, 'stores')
        store_list.append(entry)

    return store_list


def fetch(level=1, data=None, user='******', passwd=''):
    def func(data, level):
        """
        :param data:
        :param level: 0:国家;1:城市;2:商店列表
コード例 #27
0
ファイル: donna_karan.py プロジェクト: haizi-zh/ofashion
def get_stores(url, data):
    """
    从json对象中获得商店信息
    """
    opener = urllib2.build_opener()
    opener.addheaders = [("User-Agent",
                          "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)"
                          "Chrome/27.0.1453.94 Safari/537.36"),
                         ('Accept', '*/*'), ('X-Requested-With', 'XMLHttpRequest'), ('Connection', 'keep-alive')]
    response = opener.open(url)
    html = response.read().encode('utf-8')
    jsonobj = json.loads(html)
    stores = jsonobj[u'Stores'][u'Items']
    region_list = jsonobj['Regions']
    region_id = jsonobj['Region']
    region = ''
    if len(region_list) > 0 and region_id != 0:
        for val in region_list:
            if val['RegionId'] == region_id:
                region = val['Name']
                break

    country = jsonobj['CurrentCountry']['Name']
    store_list = []
    for s in stores:
        # print('Found store: %s, %s. Tel: %s, lat=%s, lng=%s' % (
        #     s['Name'], s['Address'], s['Phone'], s['Latitude'], s['Longitude']))

        store_type = ['']
        # Some stores may have varioius store types
        if len(s['StoreTypes']) > 0:
            store_type = list(val['Name'] for val in s['StoreTypes'])
        if s['Url'] is not None:
            url = s['Url']
        else:
            url = ''
        if s['ZipCode'] is not None and not s['ZipCode'].__eq__(''):
            zip = s['ZipCode']
        else:
            zip = ''
        local_addr = s['Address']
        if local_addr[-1] == '.':
            local_addr = local_addr[:-1]
        if not zip.__eq__(''):
            addr = u'%s, %s, %s' % (local_addr, s['City'], zip)
        else:
            addr = u'%s, %s' % (local_addr, s['City'])
        if region.__eq__(''):
            addr = u'%s, %s' % (addr, country)
        else:
            addr = u'%s, %s, %s' % (addr, region, country)

        for t in store_type:
            entry = cm.init_store_entry(brand_id, brandname_e, brandname_c)
            cm.update_entry(entry, {'addr_e': addr, 'country_e': country, 'city_e': s['City'],
                                    'comments': s['Comments'],
                                    'province_e': region.strip().upper(), 'zip': zip,
                                    'email': s['Email'], 'fax': s['Fax'], 'lat': s['Latitude'], 'lng': s['Longitude'],
                                    'name_e': s['Name'], 'tel': s['Phone'], 'store_type': t, 'url': url})
            gs.field_sense(entry)

            print '%s Found store: %s, %s (%s, %s)' % (
                brandname_e, entry[cm.name_e], entry[cm.addr_e], entry[cm.country_e],
                entry[cm.continent_e])
            db.insert_record(entry, 'stores')
            store_list.append(entry)

    return store_list
コード例 #28
0
ファイル: benetton.py プロジェクト: haizi-zh/ofashion
def fetch_stores(data):
    # country=Greece&city=ATHENS&adutl=+01&kids=+02&undercolor=+06&togetmap=mapdata
    url = data['data_url']
    param = {
        'country': data['country'],
        'city': data['city'],
        'adutl': ' 01',
        'kids': ' 02',
        'undercolor': ' 06',
        'togetmap': 'mapdata'
    }
    try:
        body = cm.get_data(url, param)
    except Exception:
        cm.dump('Error in fetching stores: %s, %s' % (url, param),
                'benetton_log.txt', False)
        dump_data = {
            'level': 0,
            'time': cm.format_time(),
            'data': {
                'url': url
            },
            'brand_id': data['brand_id']
        }
        cm.dump(dump_data)
        return []

    store_list = []
    for m in re.findall(ur'<marker (.+?)>', body):
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                    data['brandname_c'])
        m1 = re.search(ur'name=\\"(.+?)\\"', m)
        if m1 is not None:
            entry[cm.name_e] = cm.html2plain(
                m1.group(1).strip().replace(u'\\', ''))
        m1 = re.search(ur'address=\\"(.+?)\\"', m)
        if m1 is not None:
            addr = cm.reformat_addr(
                cm.html2plain(m1.group(1)).replace(u'\\', ''))
            tel = cm.extract_tel(addr)
            if tel != '':
                entry[cm.tel] = tel
                addr = addr.replace(tel, '')
            entry[cm.addr_e] = cm.reformat_addr(addr)

        m1 = re.search(ur'lat=\\"(.+?)\\"', m)
        if m1 is not None:
            entry[cm.lat] = string.atof(m1.group(1))

        m1 = re.search(ur'lng=\\"(.+?)\\"', m)
        if m1 is not None:
            entry[cm.lng] = string.atof(m1.group(1))

        entry[cm.country_e] = data['country'].strip().upper()
        entry[cm.city_e] = cm.extract_city(data['city'])[0]
        gs.field_sense(entry)
        cm.dump(
            '(%s / %d) Found store: %s, %s (%s, %s)' %
            (data['brandname_e'], data['brand_id'], entry[cm.name_e],
             entry[cm.addr_e], entry[cm.country_e], entry[cm.continent_e]),
            'benetton_log.txt', False)
        db.insert_record(entry, 'stores')
        store_list.append(entry)
コード例 #29
0
ファイル: etro.py プロジェクト: haizi-zh/ofashion
def fetch_store_details(data):
    url = data['url']
    try:
        body = cm.get_data(url)
    except Exception:
        print 'Error occured: %s' % url
        dump_data = {
            'level': 0,
            'time': cm.format_time(),
            'data': {
                'url': url
            },
            'brand_id': data['brand_id']
        }
        cm.dump(dump_data)
        return []

    entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                data['brandname_c'])
    ret = gs.look_up(data['country'], 1)
    if ret is not None:
        entry[cm.country_e] = ret['name_e']
    m = re.search(ur'<span class="type">Address</span>\s*<p>(.+?)</p>', body,
                  re.S)
    if m is not None:
        addr = cm.reformat_addr(m.group(1))
        country, province, city = gs.addr_sense(addr)
        if country is not None and entry[cm.country_e] == '':
            entry[cm.country_e] = country
        if province is not None:
            entry[cm.province_e] = province
        if city is not None:
            entry[cm.city_e] = city
        entry[cm.addr_e] = addr

    m = re.search(ur'<span class="type">Phone</span>\s*<p>(.+?)</p>', body,
                  re.S)
    if m is not None:
        entry[cm.tel] = m.group(1)

    m = re.search(ur'<span class="type">Opening hours</span>\s*<p>(.+?)</p>',
                  body, re.S)
    if m is not None:
        entry[cm.hours] = cm.reformat_addr(m.group(1))

    m = re.search(ur'<span class="type">You can find</span>\s*<p>(.+?)</p>',
                  body, re.S)
    if m is not None:
        entry[cm.store_type] = cm.reformat_addr(m.group(1))

    m = re.search(ur'google.maps.LatLng\(\s*(-?\d+\.\d+)\s*,\s*(-?\d+\.\d+)',
                  body, re.S)
    entry[cm.lat] = string.atof(m.group(1))
    entry[cm.lng] = string.atof(m.group(2))

    gs.field_sense(entry)
    print '(%s / %d) Found store: %s, %s (%s, %s)' % (
        data['brandname_e'], data['brand_id'], entry[cm.name_e],
        entry[cm.addr_e], entry[cm.country_e], entry[cm.continent_e])
    db.insert_record(entry, 'stores')
    return [entry]
コード例 #30
0
ファイル: hublot.py プロジェクト: haizi-zh/ofashion
def fetch_stores(data):
    url = data['url']
    try:
        body = cm.post_data(url, {
            'rsp': 'json',
            'country': data['country_code']
        })
    except Exception:
        print 'Error occured: %s' % url
        dump_data = {
            'level': 0,
            'time': cm.format_time(),
            'data': {
                'url': url
            },
            'brand_id': data['brand_id']
        }
        cm.dump(dump_data)
        return []

    raw = json.loads(body)
    store_list = []
    for s in raw['stores']:
        entry = cm.init_store_entry(data['brand_id'], data['brandname_e'],
                                    data['brandname_c'])
        entry[cm.name_e] = cm.html2plain(s['name']).strip()

        addr_list = []
        for key in ['address1', 'address2']:
            if s[key].strip() != '':
                addr_list.append(cm.reformat_addr(s[key]))
        entry[cm.addr_e] = ' '.join(addr_list)

        # r=s['region'].strip().upper()
        # m = re.search(ur'\b([A-Z]{2})\b', r)
        # if data[cm.country_e]=='UNITED STATES' and m is not None:
        #     # 美国
        #     ret = gs.look_up(m.group(1), 2)
        #     if ret is not None:
        #         r = ret['name_e']
        # entry[cm.province_e] = r

        entry[cm.city_e] = cm.extract_city(s['city'])[0]
        entry[cm.zip_code] = s['zip'].strip()
        entry[cm.country_e] = data[cm.country_e]
        entry[cm.lat] = string.atof(s['lat'])
        entry[cm.lng] = string.atof(s['lng'])
        entry[cm.tel] = s['phone'].strip()
        entry[cm.fax] = s['fax'].strip()
        entry[cm.email] = s['emailaddress'].strip()
        entry[cm.url] = s['website'].strip()

        days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        opening = []
        if 'openingHours' in s and s['openingHours'] is not None:
            for m in re.finditer(ur'i:(\d);s:\d+:\\?"([^\\"]+?)\\?"',
                                 s['openingHours']):
                opening.append(
                    '%s: %s' %
                    (days[string.atoi(m.group(1))], m.group(2).strip()))
            entry[cm.hours] = ', '.join(opening)

        gs.field_sense(entry)
        ret = gs.addr_sense(entry[cm.addr_e], entry[cm.country_e])
        if ret[1] is not None and entry[cm.province_e] == '':
            entry[cm.province_e] = ret[1]
        if ret[2] is not None and entry[cm.city_e] == '':
            entry[cm.city_e] = ret[2]
        gs.field_sense(entry)
        print '(%s / %d) Found store: %s, %s (%s, %s, %s)' % (
            data['brandname_e'], data['brand_id'], entry[cm.name_e],
            entry[cm.addr_e], entry[cm.city_e], entry[cm.country_e],
            entry[cm.continent_e])
        store_list.append(entry)
        db.insert_record(entry, 'stores')