Пример #1
0
    def search_by_keyword(self, keyword, page=1):

        url = self.keyword_url.format(keyword, current_app.config["PER_PAGE"],
                                      self.calculate_start(page))
        # dict
        result = HTTP.get(url)
        self.__fill_collection(result)
Пример #2
0
 def search_by_keyword(self, key_world, page=1):
     url = self.keyword_url.format(key_world,
                                   current_app.config['PER_PAGE'],
                                   self.calculate_start(page))
     res = HTTP.get(url)
     self.__fill_collection(res)
     return res
Пример #3
0
 def search_by_keyword(self, keyword, page=1):
     # 把page参数转换成count和start
     # 使用核心对象获取配置
     url = self.keyword_url.format(keyword, current_app.config['PER_PAGE'],
                                   self.caculate_start(page))
     result = HTTP.get(url)
     self.__fill_collection(result)
Пример #4
0
    def search_by_isbn(self,isbn):
              # 链式查找所以self.isbn_url也可以
        url = self.isbn_url.format(isbn)

        #没有第二个参数则默认为True会收到json格式,在python中json会以dict字典接收
        result = HTTP.get(url)
        self.__fill_single(result) #isbn查询的话一定只会返回一本书,用single单本书籍处理
Пример #5
0
 def search_by_isbn(self, isbn):
     url = self.isbn_url.format(isbn)
     print(url)
     http = HTTP()
     data = http.get(url)
     print(data)
     self.__fill_single(data)
Пример #6
0
 def search_by_keyword(self, kw, page):
     count = current_app.config['PAGE_COUNT']
     start = self.calculate_starts(page, count)
     url = self.keyword_url.format(kw, start, count)
     http = HTTP()
     data = http.get(url)
     self.__fill_collection(data)
Пример #7
0
 def search_by_keyword(self, keyword, page=1):
     url = (self.base_url + self.keyword_url).format(
         keyword, current_app.config['PER_PAGE'],
         self.calculate_start(page))
     result = HTTP.get(url=url)
     self.__fill_collection(result)
     return result
Пример #8
0
 def search_by_keyword(self, keyword, page):
     url = self.keyword_url.format(keyword,
                                   current_app.config['BOOK_PRE_PAGE'],
                                   self.calculate_start(page))
     result = HTTP.get(url)
     self.__fill_collection(result)
     return result
Пример #9
0
 def search_by_keyword(self, keyword, page):
     url = self.keyword_url.format(keyword, current_app.config['PER_PAGE'],
                                   self.__caculate_start(page))
     retult = HTTP.get(url)
     self.keyword = keyword
     self.total = retult['total']
     self.books = retult['books']
Пример #10
0
 def search_by_isbn(self, isbn):
     url = self.isbn_url.format(isbn)
     result = HTTP.get(url)
     # todo 将获取的数据缓存到数据库
     # book = query_from_mysql(isbn)
     # if not book:
     #     save(book)
     self.__fill_single(result)
Пример #11
0
	def get_token_openid(self):
		url = f'https://api.weixin.qq.com/sns/jscode2session' + \
		f'?appid={self.appid}&secret={self.secret}&js_code={self.code}' + \
		f'&grant_type=authorization_code'
		data = HTTP.get(url)
		openid = data['openid']
		token = create_jwt_token(openid)
		return token, openid
Пример #12
0
 def search_by_isbn(self, isbn):
     url = self.isbn_url.format(isbn)
     result = HTTP.get(url)
     # book = query_from_mysql(isbn)
     # if book:
     #     return book
     # else:
     #     save(result)
     self.__fill_single(result)
Пример #13
0
    def search_by_keyword(self, keyword, page):
        per_page = current_app.config['PER_PAGE']

        url = self.keyword_url.format(keyword, per_page,
                                      self.calculate_start(page))
        # print(url)
        result = HTTP.get(url)

        self.__fill_collection(result)
Пример #14
0
    def search_by_isbn(self, isbn):
        url = self.isbn_url.format(isbn)
        result = HTTP.get(url)

        # -----适应豆瓣API的代码
        # result['isbn'] = result.pop('isbn10')
        # result['image'] = result['images']['small']
        # -----适应豆瓣API的代码

        self.__fill_single(result)
Пример #15
0
def user_search():
    r = HTTP.get('https://acemongoapi2018inner.alltosun.net/api/v1/user/login')
    print(r)
    print(test(1, 5))

    obj = SQLHelper()
    result = obj.get_list('select * from classes', [])
    print(result)

    return 'user search'
Пример #16
0
 def search_by_isbn(self, isbn):
     """
     通过isbn搜索
     :param isbn:
     :return: 单个书籍
     """
     url = current_app.config['ISBN_URL'].format(isbn)
     result = HTTP.get(url)
     self.__fill_single(result)
     return jsonify(self.books)
Пример #17
0
 def search_by_isbn(self, isbn):
     """
     数据只需要裁剪,不需要返回
     :param isbn:
     :return:
     """
     # self可以取到类变量,self在方法中查找不到变量,会继续在类中查找
     url = self.isbn_url.format(isbn)
     result = HTTP.get(url)
     self.__fill_single(result)
Пример #18
0
 def get(self):
     wx_result = HTTP.get(self.wx_login_url)
     if not wx_result:
         # 获取session_key及openID时异常,微信内部错误
         raise Exception()  # 待完成
     else:
         if 'errcode' in wx_result.keys():
             # loginFail
             self.__process_login_error(wx_result)
         else:
             return wx_result
Пример #19
0
 def search_by_isbn(self, isbn):
     # url = YuShuBook.isbn_url.format(isbn)
     # 链式查找(先从实例变量里面查找,如果没有则查找类变量)
     url = self.isbn_url.format(isbn)
     result = HTTP.get(url)
     # 在获取到数据的时候,查询数据库有没有数据,如果有直接返回,如果没有则存到数据库
     # if book:
     #    return book
     # else:
     #     save(result)
     self.__fill_single(result)
Пример #20
0
 def search_by_isbn(self, isbn):
     url = self.isbn_url.format(isbn)   # self也可以访问到变量,因为链式查找,也可以用类名访问
     result = HTTP.get(url)  # json在python会被转换成dict
     '''伪码,实际工程要这么做,减少爬数据次数
     book = query_from_mysql  #
     if book:
         return book
     else:
         save(result) 
     '''
     self.__fill_single(result)
Пример #21
0
	def get(self):
		wx_result = HTTP.get(self.wx_login_url)
		if not wx_result:
			# 获取session_key及openID时异常,微信内部错误
			raise Exception()
		else:
			if 'errcode' in wx_result.keys():
				# loginFail
				self.__process_login_error(wx_result)
			else:
				return wx_result
Пример #22
0
 def search_by_keyword(self, keyword, page=1):
     """
     数据只需要裁剪,不需要返回
     :param keyword:
     :param page:
     :return:
     """
     url = self.keyword_url.format(keyword, current_app.config["PER_PAGE"],
                                   self.calculate_start(page))
     result = HTTP.get(url)
     self.__fill_collection(result)
Пример #23
0
 def search_by_keyword(self, keyword, page=1):
     """
     通过关键字搜索
     :param keyword: 关键字
     :param page: 从第几页开始 默认1
     :return: 可能为多个书籍
     """
     url = current_app.config['KEYWORD_URL'].format(
         keyword, current_app.config['PER_PAGE'],
         self.calculate_start(page))
     result = HTTP.get(url)
     self.__fill_collection(result)
Пример #24
0
    def search_by_keyword(self, keyword, page=1):
        url = self.keyword_url.format(keyword, current_app.config['PER_PAGE'],
                                      self.calculate_start(page))
        result = HTTP.get(url)

        # -----适应豆瓣API的代码
        # for i in range(result['count']):
        #     result['books'][i]['isbn'] = result['books'][i]['isbn10']
        #     result['books'][i]['image'] = result['books'][i]['images']['small']
        # -----适应豆瓣API的代码

        self.__fill_collection(result)
Пример #25
0
def parse_location_by_ip(ip: str):
    '''
    :param ip: ip地址
    :return: ip所在的省市
    '''
    if ip == '127.0.0.1' or ip.startswith('192.168.'):
        return "内网IP"
    from app.libs.httper import HTTP
    try:
        url = 'http://whois.pconline.com.cn/ipJson.jsp?{0}&json=true'.format(
            ip)
        json_data = HTTP.get(url)
        return '{0} {1}'.format(json_data['pro'], json_data['city'])
    except Exception:
        return '获取地理位置异常 {ip}'.format(ip=ip)
Пример #26
0
 def search_by_keyword(self, keyword, page=1):
     url = self.keyword_url.format(keyword, current_app.config['PER_PAGE'],
                                   self.cal_start(page))
     result = HTTP.get(url)
     self.__fill_conllection(result)
Пример #27
0
 def search_by_isbn(self, isbn):
     url = self.isbn_url.format(isbn)
     result = HTTP.get(url)
     # print('result', result)
     self.__fill_single(result)
Пример #28
0
 def get(self):
     wx_result = HTTP.get(self.wx_login_url)
     self.__process_login_error(wx_result)  # 微信异常处理
     return wx_result
Пример #29
0
 def search_by_key(self, q, page=1):
     url = self.search_by_key_url.format(q, current_app.config["PRE_PAGE"],
                                        self.__calculate_start(page))
     result = HTTP.get(url)
     self.__fill_collection(result)
Пример #30
0
 def search_by_isbn(self, isbn):
     url = self.isbn_url.format(isbn)
     result = HTTP.get(url)
     self.__fill_single(result)
     return result
Пример #31
0
 def search_by_isbn(self,isbn):
     url = self.isbn_url.format(isbn)
     result = HTTP.get(url)
     self.__fill_single(result)
Пример #32
0
 def search_by_isbn(cls, isbn):
     url = YuShuBook.isbn_url.format(isbn)
     print("url", url)
     result = HTTP.get(url)
     return result
Пример #33
0
 def search_by_keyword(cls, keyword, page=1):
     url = YuShuBook.keyword_url.format(keyword,
                                        current_app.config["PER_PAGE"],
                                        cls.calculate_start(page))
     result = HTTP.get(url)
     return result
Пример #34
0
 def search_by_keyword(self,keyword,page=1):
     url = self.keyword_url.format(keyword,current_app.config['PER_PAGE'],YuShuBook.calculate_start)
     result = HTTP.get(url)
     self.__fill_collection(result)