Exemplo n.º 1
0
 def gen_x_deviceinfo(self):
     tmpl = 'imei:{} serial:{} android_id:{} brand:{} model:{} macAddress:02_00_00_00_00_00 netType:WIFI simState:1 ' \
            'wifiList:{} haveBluetooth:true track_id: memory:1384 energy_percent:{} first_open:{} last_open:{}' \
            ' net_type:WIFI hardware_id:{}'.format(
             self.imei, self.serial, tool.gen_random_af(16),
             tool.replace_blank(self.dv_params.get('BRAND')), tool.replace_blank(self.dv_params.get('MODEL')),
             '_'.join([tool.gen_random_af(2) for i in range(6)]), random.randint(10, 98),
             tool.get_timestamp(10), tool.get_timestamp(10), self.hardware_id
             )
     return tool.base64_encode(tmpl)
Exemplo n.º 2
0
def sync_feed(slug, check_exist=True):
    """
    抓取feed文本内容
    """
    logging.info('task.sync_feed: slug->%s ' %(slug))
    db = m.Session()
    feed = db.query(m.Feed).filter_by(slug=slug).first()
    if feed is None: 
        logging.warning('feed not found , slug->%s' %(slug))
        db.close()
        return 
    data = feedparser.parse(feed.url)
    if not data.entries: return 
    feed_timestamp = get_timestamp(data.feed) or \
            datetime.now()
    fetch_timestamp = datetime.now()
    feed_title = getattr(data.feed,'title',feed.name)
    for entry in data.entries:
        title = getattr(entry,'title','')
        author = getattr(entry,'author','')
        source_link = getattr(entry,'link','')
        time_stamp = get_timestamp(entry) or feed_timestamp,
        if check_exist:
            old_entry = db.query(m.Entry).\
                    filter_by(author=author,
                            fid=feed.id,
                            title=title,
                            source_link=source_link).first()
            if old_entry  is not None: 
                continue
        if hasattr(entry, 'content') and entry.content:
            content = u'\n'.join([c.value for c in entry.content])
        else:
            content = getattr(entry,'summary','')
        new_entry = m.Entry(
                title = title,
                time_stamp = time_stamp,
                fetch_timestamp = fetch_timestamp,
                author = author,
                source_link = source_link,
                content = content,
                fid = feed.id)
        db.add(new_entry)
    feed.sync_time = datetime.now()
    try:
        db.commit()
    except:
        db.rollback()
        raise
    finally:
        db.close()
Exemplo n.º 3
0
def sync_feed(slug, check_exist=True):
    """
    抓取feed文本内容
    """
    logging.info('task.sync_feed: slug->%s ' % (slug))
    db = m.Session()
    feed = db.query(m.Feed).filter_by(slug=slug).first()
    if feed is None:
        logging.warning('feed not found , slug->%s' % (slug))
        db.close()
        return
    data = feedparser.parse(feed.url)
    if not data.entries: return
    feed_timestamp = get_timestamp(data.feed) or \
            datetime.now()
    fetch_timestamp = datetime.now()
    feed_title = getattr(data.feed, 'title', feed.name)
    for entry in data.entries:
        title = getattr(entry, 'title', '')
        author = getattr(entry, 'author', '')
        source_link = getattr(entry, 'link', '')
        time_stamp = get_timestamp(entry) or feed_timestamp,
        if check_exist:
            old_entry = db.query(m.Entry).\
                    filter_by(author=author,
                            fid=feed.id,
                            title=title,
                            source_link=source_link).first()
            if old_entry is not None:
                continue
        if hasattr(entry, 'content') and entry.content:
            content = u'\n'.join([c.value for c in entry.content])
        else:
            content = getattr(entry, 'summary', '')
        new_entry = m.Entry(title=title,
                            time_stamp=time_stamp,
                            fetch_timestamp=fetch_timestamp,
                            author=author,
                            source_link=source_link,
                            content=content,
                            fid=feed.id)
        db.add(new_entry)
    feed.sync_time = datetime.now()
    try:
        db.commit()
    except:
        db.rollback()
        raise
    finally:
        db.close()
Exemplo n.º 4
0
 def get_captcha(self, mobile, lat, lng):
     url = 'https://restapi.ele.me/eus/v4/captchas?captcha_str={}'.format(
         mobile)
     headers = copy(self.headers)
     result = self.sneer(url)
     headers.update({
         'x-shard':
         'loc={},{}'.format(lng, lat),
         'x-eleme-requestid':
         '{}|{}'.format(tool.gen_uuid().upper().replace('-', ''),
                        tool.get_timestamp()),
         'ex_r':
         '{}'.format(result[0]),
         'ex_dc':
         '{}'.format(result[1]),
         'ex_d':
         '{}'.format(result[2]),
     })
     headers.pop('content-type')
     try:
         resp = self.s.get(url,
                           headers=headers,
                           proxies=self.proxy,
                           timeout=3)
         return resp.json()
     except requests.exceptions.ConnectTimeout:
         self.proxy = tool.get_proxy(self.local_proxy)
         return None
     except:
         log.exception('get_captcha error.')
         return None
Exemplo n.º 5
0
    def get_shop_restaurants_menu(self, lat, lng, shopId, session):

        url = '	https://restapi.ele.me/shopping/v2/menu?restaurant_id={}'.format(
            shopId)

        headers = copy(self.headers)
        result = self.sneer(url)
        headers.update({
            'x-shard':
            'loc={},{}'.format(lng, lat),
            'x-eleme-requestid':
            '{}|{}'.format(tool.gen_uuid().upper().replace('-', ''),
                           tool.get_timestamp()),
            'random':
            '{}'.format(result[0]),
            'deadpoolcontent':
            '{}'.format(result[1]),
            'deadpool':
            '{}'.format(result[2]),
        })
        try:
            resp = session.get(url,
                               headers=headers,
                               proxies=self.proxy,
                               timeout=3)
            return resp.json()
        except requests.exceptions.ConnectTimeout:
            self.proxy = tool.get_proxy(self.local_proxy)
            return None
        except:
            log.exception('login_by_mobile error.')
            return None
Exemplo n.º 6
0
    def get_shop_restaurants_test(self, lat, lng, shopId, session):

        url = '	https://restapi.ele.me/shopping/restaurant/{}?extras[]=activities&extras[]=flavors&extras[]=albums&extras[]=videos&extras[]=coupon&extras[]=qualification&latitude={}&longitude={}'.format(
            shopId, lat, lng)

        headers = copy(self.headers)
        result = self.sneer(url)
        headers.update({
            'x-shard':
            'loc={},{}'.format(lng, lat),
            'x-eleme-requestid':
            '{}|{}'.format(tool.gen_uuid().upper().replace('-', ''),
                           tool.get_timestamp()),
            'random':
            '{}'.format(result[0]),
            'deadpoolcontent':
            '{}'.format(result[1]),
            'deadpool':
            '{}'.format(result[2]),
        })
        try:
            resp = session.get(url,
                               headers=headers,
                               proxies=self.proxy,
                               timeout=3)
            return resp.status_code, resp.json()
        except requests.exceptions.ConnectTimeout:
            self.proxy = tool.get_proxy(self.local_proxy)
            return None
        except:
            log.exception('login_by_mobile error.')
            return None
Exemplo n.º 7
0
 def get_restaurants_test(self, lat, lng, city_id, order_by, offset,
                          seesion):
     url = 'https://restapi.ele.me/shopping/v3/restaurants?extras[]=identification&extras[]=coupon&' \
           'latitude={}&longitude={}&city_id={}&rank_id={}&network_operator=&network=WIFI&order_by={}&' \
           'extra_filters=home&os=Android%2F{}&deivce={}&weather_code=CLEAR_DAY&offset={}&limit=20'.format(
         lat, lng, city_id, tool.gen_random_af(32), order_by, self.dv_params.get('RELEASE'),
         parse.quote(self.dv_params.get('MODEL')), offset
     )
     headers = copy(self.headers)
     result = self.sneer(url)
     headers.update({
         'x-shard':
         'loc={},{}'.format(lng, lat),
         'x-eleme-requestid':
         '{}|{}'.format(tool.gen_uuid().upper().replace('-', ''),
                        tool.get_timestamp()),
         'ex_r':
         '{}'.format(result[0]),
         'ex_dc':
         '{}'.format(result[1]),
         'ex_d':
         '{}'.format(result[2]),
     })
     try:
         resp = seesion.get(url,
                            headers=headers,
                            proxies=self.proxy,
                            timeout=10)
         return resp.status_code, resp.json()
     except requests.exceptions.ConnectTimeout:
         self.proxy = tool.get_proxy(self.local_proxy)
         return None
     except:
         log.exception('login_by_mobile error.')
         return None
Exemplo n.º 8
0
    def mobile_send_code_captcha(self, mobile, lat, lng, captcha_hash,
                                 captcha_value):
        url = 'https://restapi.ele.me/eus/login/mobile_send_code'
        headers = copy(self.headers)
        result = self.sneer(url)
        headers.update({
            'x-shard':
            'loc={},{}'.format(lng, lat),
            'x-eleme-requestid':
            '{}|{}'.format(tool.gen_uuid().upper().replace('-', ''),
                           tool.get_timestamp()),
            'ex_r':
            '{}'.format(result[0]),
            'ex_dc':
            '{}'.format(result[1]),
            'ex_d':
            '{}'.format(result[2]),
        })

        data = '{"mobile":"%s","captcha_hash":"%s","captcha_value":"%s","latitude":%s,"longitude":%s,"via_audio":false}' % (
            str(mobile),
            str(captcha_hash),
            str(captcha_value),
            str(lat),
            str(lng),
        )
        try:
            resp = self.s.post(url,
                               headers=headers,
                               data=data,
                               proxies=self.proxy,
                               timeout=3)
            return resp.json()
        except requests.exceptions.ConnectTimeout:
            self.proxy = tool.get_proxy(self.local_proxy)
            return None
        except:
            log.exception('mobile_send_code_captcha error.')
            return None
Exemplo n.º 9
0
    def get_restaurants_all_id(self, lat, lng, city_id, order_by, categorys,
                               offset, seesion):
        url = 'https://restapi.ele.me/shopping/v3/restaurants?extras[]=coupon&latitude={}&longitude={}&city_id={}&rank_id=&business_flag=0&order_by={}&{}offset={}&limit=20'.format(
            lat, lng, city_id, order_by, categorys, offset)
        Flag = self.r.has_url(url)
        if not Flag:
            log.info('重复的url')
            return None
        log.info(url)

        headers = copy(self.headers)
        result = self.sneer(url)
        headers.update({
            'x-shard':
            'loc={},{}'.format(lng, lat),
            'x-eleme-requestid':
            '{}|{}'.format(tool.gen_uuid().upper().replace('-', ''),
                           tool.get_timestamp()),
            'ex_r':
            '{}'.format(result[0]),
            'ex_dc':
            '{}'.format(result[1]),
            'ex_d':
            '{}'.format(result[2]),
        })
        try:
            resp = seesion.get(url,
                               headers=headers,
                               proxies=self.proxy,
                               timeout=10)
            return resp.json()
        except requests.exceptions.ConnectTimeout:
            self.proxy = tool.get_proxy(self.local_proxy)
            return None
        except:
            log.exception('login_by_mobile error.')
            return None
Exemplo n.º 10
0
    def get_restaurants(self, lat, lng, city_id, order_by, offset):
        url = 'https://restapi.ele.me/shopping/v3/restaurants?extras[]=identification&extras[]=coupon&' \
              'latitude={}&longitude={}&city_id={}&rank_id={}&network_operator=&network=WIFI&order_by={}&' \
              'extra_filters=home&os=Android%2F{}&deivce={}&weather_code=CLEAR_DAY&offset={}&limit=20'.format(
            lat, lng, city_id, tool.gen_random_af(32), order_by, self.dv_params.get('RELEASE'),
            parse.quote(self.dv_params.get('MODEL')), offset
        )
        url = 'https://restapi.ele.me/shopping/v3/restaurants?extras[]=coupon&latitude=31.243828888982534&longitude=121.48247290402651&city_id=1&rank_id=&business_flag=0&restaurant_category_ids%5B%5D=1&offset=0&limit=20'
        url = 'https://restapi.ele.me/shopping/v3/restaurants?extras[]=coupon&latitude=30.725792&longitude=121.268812&city_id=1&rank_id=&business_flag=0&order_by=5&restaurant_category_ids%5B%5D=4&offset=0&limit=20'

        headers = copy(self.headers)
        result = self.sneer(url)
        headers.update({
            'x-shard':
            'loc={},{}'.format(lng, lat),
            'x-eleme-requestid':
            '{}|{}'.format(tool.gen_uuid().upper().replace('-', ''),
                           tool.get_timestamp()),
            'ex_r':
            '{}'.format(result[0]),
            'ex_dc':
            '{}'.format(result[1]),
            'ex_d':
            '{}'.format(result[2]),
        })
        try:
            resp = self.s.get(url,
                              headers=headers,
                              proxies=self.proxy,
                              timeout=3)
            return resp.json()
        except requests.exceptions.ConnectTimeout:
            self.proxy = tool.get_proxy(self.local_proxy)
            return None
        except:
            log.exception('login_by_mobile error.')
            return None
Exemplo n.º 11
0
    def login_by_mobile(self, token, sms_code, lat, lng):
        url = 'https://restapi.ele.me/eus/login/login_by_mobile'
        headers = copy(self.headers)
        result = self.sneer(url)
        headers.update({
            'x-shard':
            'loc={},{}'.format(lng, lat),
            'x-eleme-requestid':
            '{}|{}'.format(tool.gen_uuid().upper().replace('-', ''),
                           tool.get_timestamp()),
            'ex_r':
            '{}'.format(result[0]),
            'ex_dc':
            '{}'.format(result[1]),
            'ex_d':
            '{}'.format(result[2]),
        })
        data = '{"validate_token":"%s","validate_code":"%s","latitude":%s,"longitude":%s}' % (
            str(token),
            str(sms_code),
            str(lat),
            str(lng),
        )

        try:
            resp = self.s.post(url,
                               headers=headers,
                               data=data,
                               proxies=self.proxy,
                               timeout=3)
            return self.s.cookies
        except requests.exceptions.ConnectTimeout:
            self.proxy = tool.get_proxy(self.local_proxy)
            return None
        except:
            log.exception('login_by_mobile error.')
            return None