def main(): # get the data from Craigslist housing = CraigslistHousing(site='sfbay', area='sfc', category='apa', filters={ 'posted_today': True, 'min_price': settings.min_price, 'max_price': settings.max_price, 'min_bedrooms': settings.min_bedrooms }) log.info('Retrieving listings') for result in housing.get_results(sort_by='newest', geotagged=True): # result = {'id': '6902060582', 'repost_of': None, 'name': 'Spacious one bedroom apartment near USF& GG PK', 'url': 'https://sfbay.craigslist.org/sfc/apa/d/san-francisco-spacious-one-bedroom/6902060582.html', 'datetime': '2019-05-31 21:44', 'price': '$2950', 'where': 'inner richmond', 'has_image': True, 'has_map': True, 'geotag': (37.775905, -122.458591), 'bedrooms': '1', 'area': None} # create a `listing` dict with the fields I care about and process the result listing = {} listing['craigslist_id'] = result['id'] listing['craigslist_url'] = result['url'] listing['posted_on'] = result['datetime'] listing['description'] = result['name'] listing['price'] = int( result['price'][1:] ) # price always has a leading '$' so we need to strip the leading character listing['neighborhood'] = str.lower( result['where'] ) if result['where'] else '' # sometimes this is null listing['num_bedrooms'] = result['bedrooms'] listing['sqft'] = result['area'] listing['latitude'] = result['geotag'][0] listing['longitude'] = result['geotag'][1] # decide if we want to notify about this listing # https://stackoverflow.com/questions/2783969/compare-string-with-all-values-in-array if any(x in listing['neighborhood'] for x in settings.neighborhood_blacklist): notify = False else: notify = True # check if the listing is a duplicate if database.get_record(listing['craigslist_id']): log.info('Found duplicate record with ID {}, skipping'.format( listing['craigslist_id'])) continue # if duplicate we assume we've procsessed this listing so just skip it # otherwise we should save the listing and notify if applicable else: log.info('{} looks like a new listing, processing'.format( 'craigslist_id')) # get the map image from Mapbox # we do this here instead of above to limit the number of API requests made to Mapbox listing['map_image'] = get_map(listing['latitude'], listing['longitude']) database.insert_record(listing) if notify is True: send_notification(listing) database.mark_as_notified(listing['craigslist_id'])
def play_game(): cursor = database.create_db() name = '' words = [] n = 1 score = 0 with open(".\\resource\\word.txt", 'r') as f: for c in f: words.append(c.strip()) start = time.time() while n <= 5: os.system("cls") random.shuffle(words) q = random.choice(words) print("[ Q {} ]".format(n)) print(q) answer = input() print("result : ", end='') if str(q).strip() == str(answer).strip(): print("Correct!!!") winsound.PlaySound(".\\resource\\sound\\correct.wav", winsound.SND_FILENAME) score = score + 1 else: print("Wrong...") winsound.PlaySound(".\\resource\\sound\\wrong.wav", winsound.SND_FILENAME) n = n + 1 end = time.time() play_time = end - start play_time = format(play_time, ".3f") os.system("cls") if score >= 3: print("Pass!!!") else: print("Fail...") print("Play time : ", play_time, "s, ", "Score : {}".format(score)) print() while name == '': name = input(">>> Enter your name (No blank) : ") database.insert_record(cursor, name, score, play_time)
def do_POST(self): parameters = self.path.split('/') parameters = list(filter(lambda a: a != "", parameters)) try: arguments = json.loads( self.rfile.read(int(self.headers['content-length'])).decode()) except Exception as e: print(e) self.send_response(400) self.send_header('Access-Control-Allow-Origin', '*') self.end_headers() self.wfile.write(b'Bad request') query, table = helper_post.build_post_select(parameters) if query == 0: self.send_response(404) self.send_header('Access-Control-Allow-Origin', '*') self.end_headers() self.wfile.write(b'Could not find what you requested') else: print(query) answer_array = database.interogate_database(query) print(answer_array) if answer_array == 409 or answer_array == 400: self.send_response(answer_array) self.send_header('Access-Control-Allow-Origin', '*') self.end_headers() if answer_array == 409: self.wfile.write(b'Conflict') else: self.wfile.write(b'Bad request') else: if len(answer_array) >= 1: self.send_response(400) self.send_header('Access-Control-Allow-Origin', '*') self.end_headers() self.wfile.write(b'Bad request') else: query, values = helper_post.build_post_insert_query( arguments, table) database.insert_record(query, values) answer = 'Ok' status_code = 201 self.send_response(status_code) self.send_header('Access-Control-Allow-Origin', '*') self.end_headers() self.wfile.write(answer.encode())
def modify_policy(data_list, patient_id): # Receive json data data_list and insert into database # Probably its hard to give a direct example # Also, only support one-type data # Mixed requirement should be splitted into ones if data_list is None or data_list['resourceType'] is None: Catch_dataError() return data_list policy_list = list_extension(data_list) tag = db.insert_record(patient_id, policy_list, datetime.now()) if tag == 1: return STATUS_OK elif tag == 0: tag2 = db.add_policy(patient_id, policy_list, datetime.now()) if tag2 == -1: return STATUS_ERROR else: return STATUS_OK else: return STATUS_ERROR
example_policy = { "Patient": { "name": [{"text": "David Penrod"}], "resourceType": "Patient", "text": {"status": "generated", "div": "<div><p>David Penrod</p></div>"}, "meta": {"versionID": 1, "lastUpdated": "2016-01-13T15:31:33.555627"}, "gender": "male", "id": "a770136e-616f-45b0-8752-3be0ad9cab42", } } example_id = "a770136e-616f-45b0-8752-3be0ad9cab42" import database as db import json db.delete_record(example_id) db.insert_record(example_id, example_policy, None) if __name__ == "__main__": print json.dumps(db.select_policy("7ff9db40-783d-48c4-b564-fffa42d45e04"), indent=2)
print("\nProbably you made a mistake in the card number. Please try again!") elif not database.validate_card(connection, card_number): print("\nSuch a card does not exist.") else: flag = True return flag bank = Bank() connection = database.db_connection() database.create_table(connection) while True: choice = input(INPUT_PROMPT) if choice == "1": card_number = bank.generate_card_number() pin = bank.generate_pin() database.insert_record(connection, card_number, pin) elif choice == "2": login_card_number = input("\nEnter your card number:\n") login_pin = input("Enter your PIN:\n") if database.validate_login(connection, login_card_number, login_pin): print("\nYou have successfully logged in!") bank.login_choices(connection, login_card_number) else: print("\nWrong card number or PIN!") continue else: print("\nBye!") quit()
example_policy = { "Patient": { "name": [{ "text": "David Penrod" }], "resourceType": "Patient", "text": { "status": "generated", "div": "<div><p>David Penrod</p></div>" }, "meta": { "versionID": 1, "lastUpdated": "2016-01-13T15:31:33.555627" }, "gender": "male", "id": "a770136e-616f-45b0-8752-3be0ad9cab42" } } example_id = "a770136e-616f-45b0-8752-3be0ad9cab42" import database as db import json db.delete_record(example_id) db.insert_record(example_id, example_policy, None) if __name__ == '__main__': print json.dumps(db.select_policy("7ff9db40-783d-48c4-b564-fffa42d45e04"), indent=2)