示例#1
0
 def test():
     redis = Redis()
     for i in range(160):
         j = redis.get("image%s" % str(i))
         if j is None:
             print("image%s" % str(i))
         else:
             pass
 def __init__(self, supplier):
     self.log = Log('SupplierAction')
     self.supplier = supplier
     self.request = Request()
     self.tool = Tool()
     self.redis = Redis()
     self.db = DataBaseOperate()
     self.ps = 10
示例#3
0
 def get_short_massage_code(mobile):
     data_sso = Config('Sso').data
     data = data_sso['http://192.168.62.253:31007'][
         '/mobile/sso/verify-code-get']
     data["mobile"] = mobile
     code = Request().post(
         url="http://192.168.62.253:31007/mobile/sso/verify-code-get",
         data=data)
     Tool.L.logger.debug("手机号 %s 发送验证码成功" % str(mobile))
     return Redis().get('VerifyCodeMobile: SmsVerifyCode:9_REGISTER_%s' %
                        str(mobile))
示例#4
0
 def delete_user_by_mobile(self, mobile):
     user_info = Tool.query_user_info_by_mobile(mobile)
     if user_info:
         redis = Redis()
         user_index = int(redis.get('user_index'))
         DataBaseOperate().operate(
             "39.104.28.40", "farm-uc",
             'UPDATE t_user SET mobile = "%s" WHERE mobile = "%s";' %
             (str(user_index), str(mobile)))
         self.L.logger.debug('原手机号 %s 修改为 %s' %
                             (str(mobile), str(user_index)))
         redis.set('user_index', user_index + 1)
     else:
         raise Exception('手机号输入错误: %s' % str(mobile))
示例#5
0
 def upload_image(self):
     redis = Redis()
     get_index = int(redis.get('get_index')) - 15
     for i in range(1, 16):
         if round((os.path.getsize("./Images/banner" + str(i) + ".jpg")) /
                  1000.0 / 1000.0, 1) < 5:
             Request().post_file(
                 url="http://39.104.28.40:9600/common/farm/upload-img",
                 file_path="./Images/banner%s.jpg" % str(i))
             # zyp_url = json.loads(response)["content"]
             # redis.set("image%s" % str(get_index + i), zyp_url)
             self.L.logger.debug("image%s uploaded !" % str(get_index + i))
         else:
             self.L.logger.debug("image%s exceed size !" %
                                 str(get_index + i))
示例#6
0
 def get_images(self, key='farm'):
     redis = Redis()
     # redis.set('get_index', 0)
     get_index = int(redis.get('get_index'))
     response = Request().get(
         'https://www.pexels.com/search/%s/?page=%s&format=html' %
         (key, str((get_index / 15) + 1)))
     soup = BeautifulSoup(response)
     images = soup.findAll('a', attrs={'href': re.compile("(^https.*)\?")})
     # list_start = get_index
     # list_end = list_start + 15
     i = 0
     for link in images:
         image_url = '%s&auto=compress\n' % link.get('href')
         self.L.logger.debug(image_url)
         image = Request().get(image_url)
         i += 1
         with open('./Images/banner%s.jpg' % str(i), 'wb') as picture:
             picture.write(image)
示例#7
0
 def __init__(self,
              farm_name="自动化默认农场名",
              state_name="北部地区",
              farm_type="综合",
              area_range="500亩以下",
              price_range="500万以下"):
     farm_type_dict = {
         "休闲": 1,
         "畜牧": 2,
         "养殖": 2,
         "种植": 6,
         "酒庄": 3,
         "葡萄园": 3,
         "林木": 4,
         "狩猎": 4,
         "综合": 5
     }
     farm_area_dict = {
         "500亩以下": self.fake.random_int(1, 82),
         "500亩-5000亩": self.fake.random_int(83, 823),
         "5000亩-10000亩": self.fake.random_int(824, 1647),
         "10000亩-50000亩": self.fake.random_int(1648, 8236),
         "50000亩以上": self.fake.random_int(8237, 16473)
     }
     total_price_dict = {
         "500万以下": self.fake.random_int(1, 980392),
         "500万-2000万": self.fake.random_int(1020408, 3921568),
         "2000万-3500万": self.fake.random_int(4081632, 6862745),
         "3500万-5000万": self.fake.random_int(7142857, 9803921),
         "5000万以上": self.fake.random_int(10204081, 19607843)
     }
     city = Tool().query_random_city(state_name)
     self.farm_name = farm_name
     self.farm_name_en = self.fake_en.name() + " Farm"
     self.L.logger.debug("中文农场名 为 %s" % self.farm_name)
     self.L.logger.debug("英文农场名 为 %s" % self.farm_name_en)
     self.farm_type = farm_type_dict[farm_type]
     self.L.logger.debug("农场类型 为 %s %s" % (self.farm_type, farm_type))
     city_name = city[0]
     self.L.logger.debug("农场的州-市 为 %s %s" % (state_name, city_name))
     self.farm_address = city[1]["address"]
     self.L.logger.debug("中文农场地址 为 %s" % self.farm_address)
     self.farm_address_en = city[1]["address"]
     self.L.logger.debug("英文农场地址 为 %s" % self.farm_address_en)
     self.lat = city[1]["lat"]
     self.L.logger.debug("农场维度lat 为 %s" % self.lat)
     self.lng = city[1]["lng"]
     self.L.logger.debug("农场经度lng 为 %s" % self.lng)
     self.nation_id = 25
     self.L.logger.debug("农场的nationId 为 %d" % self.nation_id)
     self.province_id = city[1]["state"]
     self.L.logger.debug("农场的provinceId 为 %d" % self.province_id)
     self.city_id = city[1]["city"]
     self.L.logger.debug("农场的cityId 为 %d" % self.city_id)
     self.area = farm_area_dict[area_range]
     self.L.logger.debug("农场的面积 为 %s 英亩" % str(self.area))
     self.total_price = total_price_dict[price_range]
     self.L.logger.debug("农场的总价 为 %s 澳元" % str(self.total_price))
     self.unitCode = "AUD"
     self.L.logger.debug("农场的货币单位 为 %s" % self.unitCode)
     self.unit_price = self.total_price / self.area
     self.L.logger.debug("农场的单价 为 %s 澳元" % str(self.unit_price))
     self.water_rights = "中文水权描述:" + self.fake.text().replace('\n', ' ')
     self.L.logger.debug(self.water_rights)
     self.water_rights_en = "英文水权描述:" + self.fake_en.text().replace(
         '\n', ' ')
     self.L.logger.debug(self.water_rights_en)
     self.regulations = "中文土地使用规定:" + self.fake.text().replace('\n', ' ')
     self.L.logger.debug(self.regulations)
     self.regulations_en = "英文土地使用规定:" + self.fake_en.text().replace(
         '\n', ' ')
     self.L.logger.debug(self.regulations_en)
     self.rainfall = self.fake.random_int(20, 1000)
     self.L.logger.debug("降雨量 %s毫升/年" % self.rainfall)
     self.disadvantage = "中文杂草和虫害:" + self.fake.text().replace('\n', ' ')
     self.L.logger.debug(self.disadvantage)
     self.disadvantage_en = "英文杂草和虫害:" + self.fake_en.text().replace(
         '\n', ' ')
     self.L.logger.debug(self.disadvantage_en)
     self.area_code = 'mu'
     self.L.logger.debug("中文面积单位: %s" % self.area_code)
     self.area_code_en = 'acre'
     self.L.logger.debug("英文面积单位: %s" % self.area_code_en)
     self.soil_ph = 3  #float(self.fake.random_int(-10, 150)/10)
     self.L.logger.debug("土壤PH值: %s" % self.soil_ph)
     self.soil_type = self.fake.random_int(1, 3)
     redis = Redis()
     self.images = '[{"type":"1", ' \
                   '"url":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},' \
                   '{"type":"2", ' \
                   '"url":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},' \
                   '{"type":"3", ' \
                   '"url":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},' \
                   '{"type":"4", ' \
                   '"url":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"}]'
     self.L.logger.debug("农场Banner 为 %s " % str(self.images))
     self.content = '[{"type":"1", ' \
                    '"value":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},'\
                    '{"type":"2", ' \
                    '"value":"' + self.fake.text().replace("\n", " ") + '"},' \
                    '{"type":"1", ' \
                    '"value":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},' \
                    '{"type":"2", ' \
                    '"value":"' + self.fake.text().replace("\n", " ") + '"}]'
     self.L.logger.debug("中文农场介绍 为 %s " % str(self.content))
     self.content_en = '[{"type":"1", ' \
                       '"value":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},'\
                       '{"type":"2", ' \
                       '"value":"' + self.fake_en.text().replace("\n", " ") + '"},' \
                       '{"type":"1", ' \
                       '"value":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},' \
                       '{"type":"2", ' \
                       '"value":"' + self.fake_en.text().replace("\n", " ") + '"}]'
     self.L.logger.debug("英文农场介绍 为 %s " % str(self.content_en))