def list_token(session, token, issuer): listed_token = Listing() listed_token.token_address = token["address"] listed_token.is_public = True listed_token.max_holding_quantity = 1 listed_token.max_sell_amount = 1000 listed_token.owner_address = issuer["account_address"] session.add(listed_token)
def insert_listing_data(session, _token): token = Listing() token.token_address = _token["token_address"] token.is_public = _token["is_public"] token.max_holding_quantity = _token["max_holding_quantity"] token.max_sell_amount = _token["max_sell_amount"] token.owner_address = "0x9467ABe171e0da7D6aBDdA23Ba6e6Ec5BE0b4F7b" session.add(token)
def insert_listing_data(session, _token): token = Listing() token.token_address = _token["token_address"] token.is_public = _token["is_public"] token.max_holding_quantity = _token["max_holding_quantity"] token.max_sell_amount = _token["max_sell_amount"] token.owner_address = _token["owner_address"] session.add(token)
def on_post(self, req, res): LOG.info("v2.token.Tokens(POST)") session = req.context["session"] # 入力値チェック request_json = self.validate(req) contract_address = request_json["contract_address"] # 既存レコードの存在チェック _listing = session.query(Listing). \ filter(Listing.token_address == contract_address). \ first() if _listing is not None: raise InvalidParameterError("contract_address already exist") _executable_contract = session.query(ExecutableContract). \ filter(ExecutableContract.contract_address == contract_address). \ first() if _executable_contract is not None: raise InvalidParameterError("contract_address already exist") # token情報をTokenListコントラクトから取得 ListContract = Contract.get_contract( 'TokenList', config.TOKEN_LIST_CONTRACT_ADDRESS) token = ListContract.functions.getTokenByAddress( contract_address).call() # contract_addressの有効性チェック if token[1] is None or token[1] not in self.available_token_template(): raise InvalidParameterError( "contract_address is invalid token address") owner_address = token[2] # 新規レコードの登録 is_public = request_json["is_public"] max_holding_quantity = request_json[ "max_holding_quantity"] if "max_holding_quantity" in request_json else None max_sell_amount = request_json[ "max_sell_amount"] if "max_sell_amount" in request_json else None listing = Listing() listing.token_address = contract_address listing.is_public = is_public listing.max_holding_quantity = max_holding_quantity listing.max_sell_amount = max_sell_amount listing.owner_address = owner_address session.add(listing) executable_contract = ExecutableContract() executable_contract.contract_address = contract_address session.add(executable_contract) session.commit() self.on_success(res)
def list_private_token(session, token): listed_token = Listing() listed_token.token_address = token['address'] listed_token.is_public = False listed_token.max_holding_quantity = 1 listed_token.max_sell_amount = 1000 session.add(listed_token)
def list_token(session, token): listed_token = Listing() listed_token.token_address = token["address"] listed_token.is_public = True listed_token.max_holding_quantity = 1 listed_token.max_sell_amount = 1000 session.add(listed_token)
def listing_token(session, token): listing = Listing() listing.token_address = token['address'] listing.is_public = True listing.max_holding_quantity = 1 listing.max_sell_amount = 1000 session.add(listing)
def insert_listing(session, listing: dict): _listing = Listing() _listing.token_address = listing["token_address"] _listing.is_public = listing["is_public"] session.add(_listing)
def _insert_listing(session, token_address, owner_address): listing = Listing() listing.token_address = token_address listing.is_public = True listing.owner_address = owner_address session.add(listing)
def bulk_insert_listings(listings): for listing_dict in listings: listing_dict['is_furnished'] = bool(listing_dict['is_furnished']) listing = Listing(**listing_dict) db.session.add(listing) db.session.commit()
def parse_listing_item(listing_url): """Parse a single item and maybe add it to the db""" print "[*] Parsing listing item: {}".format(listing_url) item_page = requests.get(listing_url) item_doc = document_fromstring(item_page.content) r = item_doc.xpath( u'//*[@id="item-infos"]/div/div[1]/div/h1/span[@class="item-infos"]/text()' ) if len(r) < 1: raise ScrapingError('Expected a name') item_name = ' '.join(''.join(r).split()) r = item_doc.xpath( u'//*[@id="criteres_bien"]/div[contains(@class, "General")]/div/ul/li/div/div[.="Type de bien"]/../div[2]/b/text()' ) if len(r) != 1: raise ScrapingError('Expected a type of listing') if r[0] == 'Appartement': item_type = 'apartment' elif r[0] == 'Immeuble': item_type = 'building' elif r[0] == 'Maison': item_type = 'house' #NOTE: Not found yet: elif r[0] == 'Stationnement': item_type = 'parking' else: item_type = 'land' rent_found = False r = item_doc.xpath( u'//*[@id="criteres_bien"]/div[contains(@class, "aspects_financiers")]/div/ul/li/div/div[.="Prix"]/../div[2]/b/text()' ) rent_found = len(r) == 1 if not rent_found: r = item_doc.xpath( u'//*[@id="criteres_bien"]/div[contains(@class, "aspects_financiers")]/div/ul/li/div/div[.="Loyer charges comprises"]/../div[2]/b/text()' ) rent_found = len(r) == 1 if not rent_found: raise ScrapingError('Expected a price/rent') item_rent = int(r[0].split()[0]) r = item_doc.xpath( u'//*[@id="criteres_bien"]/div[contains(@class, "surfaces")]/div/ul/li/div/div[.="Surface"]/../div[2]/b/text()' ) if len(r) != 1: raise ScrapingError('Expected a surface area') item_surface_area = float(r[0].split()[0]) r = item_doc.xpath( u'//*[@id="criteres_bien"]/div[contains(@class, "interieur")]/div/ul/li/div/div[.="Nombre pièces"]/../div[2]/b/text()' ) if len(r) != 1: raise ScrapingError('Expected a room count') item_room_count = int(r[0]) r = item_doc.xpath(u'//div[@id="roadmap"]/div[@id="gmap"]') if len(r) != 1: raise ScrapingError('Expected a google map element') item_lng = float(r[0].get('data-lng')) item_lat = float(r[0].get('data-lat')) item_geometry = shapely.geometry.point.Point(item_lng, item_lat).wkt # NOTE: I do not think that name/type are sufficient to correctly identify a specific item. there_s_change = False row = db.session.query(Listing).filter_by( name=item_name, listing_type=item_type).one_or_none() if row is None: print "[#] New item" listing_item = Listing(name=item_name, url=listing_url, geometry=item_geometry, listing_type=item_type, surface_area=item_surface_area, room_count=item_room_count, rent=item_rent, is_furnished=False) db.session.add(listing_item) there_s_change = True else: print "[!] Item already existing" #TODO: update ? pass return there_s_change