def update_product(self, _id, json): product = self.products_mng.upt_product(_id, json['name'], json['description'], json['image'], json['categories'], json['start_price'], json['shipping_cost'], json['end_date'], json['is_direct'], self.get_user_by_session().get_id()) utilities.save_json(self.products_mng.jsonify(), products_path) return product
def bid_on_product(self, product_id, json): bid_price = json['bid_price'] bid_price = float(bid_price) product_to_update = self.products_mng.get_product_by_id(product_id) if product_to_update.get_is_direct() == 1: raise AssertionError('Cannot bid on a instant-buy product.') user = self.get_user_by_session() if user.get_credit_card() == 0: raise AssertionError('Cannot bid without a Credit Card registred.') uid = user.get_id() if bid_price < product_to_update.get_current_price() + 0.01: raise AssertionError('You cannot bid less or equal than the current price.') if time() >= product_to_update.get_end_date(): raise AssertionError('This sale is over.') if product_to_update.get_vendor_id() == uid: raise AssertionError("Vendor cannot bid on his own bids.") product_to_update.current_price = bid_price product_to_update.bid_count += 1 bidders = product_to_update.get_bidders() for bidder in bidders: if bidder == uid: bidders.remove(bidder) break bidders.append(uid) utilities.save_json(self.products_mng.jsonify(), products_path) return product_to_update.jsonify()
def add_pm(self, json): if not json: raise ValueError("Request is not JSON") _id = self.pm_mng.add_private_message(json['subject'], json['text'], self.get_user_by_session().get_id(), json['recipient_id']) utilities.save_json(self.pm_mng.jsonify(), pm_path) return self.pm_mng.get_private_message(_id).jsonify()
def add_product(self, json): if not json: raise ValueError("Request is not JSON") product = self.products_mng.add_product(json['name'], json['categories'], json['description'], json['image'], json['start_price'], self.get_user_by_session().get_id(), time(), json['end_date'], json['shipping_cost'], json['is_direct']) utilities.save_json(self.products_mng.jsonify(), products_path) return product.jsonify()
def add_category(self, json): if not json: raise ValueError('Request is not JSON') category = self.products_mng.categories_mng.add_category(json['name'], json['description'], json['image'], json['parent'], json['childs']) utilities.save_json(self.products_mng.categories_mng.jsonify(), categories_path) return category.jsonify()
def continuous_save_twitter(): raw_json_file = PATH_STEP1_RAW raw_json_file = os.path.abspath(os.path.join('.', raw_json_file)) raw_texts = [] if os.path.exists(raw_json_file) and os.path.isfile(raw_json_file): raw_texts = load_json(raw_json_file) count = len(raw_texts) if count > 0: print(f"Preloaded {count} texts.") while count < 10000: new_texts = fetch_twitter(100) raw_texts.extend(new_texts) count = len(raw_texts) print(f"Outputting {count} texts...") save_json(raw_texts, raw_json_file, ensure_ascii=False) time.sleep(2)
def process(): data = load_json(PATH_STEP1_RAW) data = list(map(extract_text, data)) data = list(map(sentence_segment, data)) data = list(map(word_tokenize_sentpad, data)) save_json(data, PATH_STEP2_CLEAN, ensure_ascii=False)
def register(self, json): if not json: raise ValueError("Request is not JSON") self.user_mng.add_user(json['username'], json['password'], json['mail']) utilities.save_json(self.user_mng.user_to_json(), users_path)
def rate_user(self, user_id, json): for user in self.user_mng.get_users(): if user.get_id() == user_id: json = self.user_mng.rate_user(user, json['rating'], self.get_user_by_session().get_id()) utilities.save_json(self.user_mng.user_to_json(), users_path) return json
start_date = input("Thanks! Enter 'y' if you want to get info just since the last election or 'n' if you want to do it for all time.") if start_date == 'y': start_date = "lEtZ72ugJfwwp00kq6cDTaVGPuvjH3FH" else: start_date = "Vaz6rTDHIxMrCObtEAAPgq%2fxFmcLN2ZQ" for alderman in alderman_info_list: print('Working on {} from ward {}.'.format(alderman[1], alderman[0])) ward = alderman[0] alderman_name = alderman[1] committee_id = alderman[2] boe_encrypted_committee_id = alderman[3] response = urllib.request.urlopen(r"https://illinoissunshine.org/api/receipts/?committee_id="+committee_id+r"&datatype=csv") df = pd.read_csv(response) df = utilities.preprocess_data(df) if start_date == "lEtZ72ugJfwwp00kq6cDTaVGPuvjH3FH": df = utilities.since_last_election(df) df = utilities.group_and_aggregate(df) df = utilities.add_donor_type_size(df) df = utilities.ward_geo_lookup(df, ward) df = utilities.add_lat_long(df, ward) df['coord'] = tuple(zip(df['lat'], df['lng'])) df = utilities.add_donation_location(df, ward) df = utilities.add_not_itemized(df, boe_encrypted_committee_id, start_date, end_date) # dc.add_class(df) # make_web_json(df,alderman[0]) utilities.save_tsv(df, ward) df = utilities.html_safe(df) utilities.save_json(df, ward, alderman_name)
res = list(zip(list(map(lambda x: x[0], geo)), list(map(lambda x: x[1], geo)), list(map(lambda x: x[2], res)))) res = list(map(lambda x: (x[2], x[0], x[1]), res)) new_res = list(map(lambda x: {"_id": "{}_{}".format(x[1], x[2]), "lat": x[1], "lng": x[2], "radius": x[0]}, res)) print(len(new_res)) ll = [] acc = [] for coord in new_res: x = coord['lat'] y = coord['lng'] if (x, y) not in acc: temp_lst = list(filter(lambda i: i['lat'] == x and i['lng'] == y, new_res)) temp_lst = sorted(temp_lst, key=lambda i: i['radius'], reverse=True)[0] ll.append(temp_lst) acc.append((x, y)) new_res = ll print(len(new_res)) save_json("../resources/static_ll_points.json", new_res) # Insert into database client = init_mongo_client() db = client.restaurant_db for point in new_res: db.ll_points.insert_one(point)