Spaces:
Runtime error
Runtime error
| from deta import Deta # Import Deta | |
| from pprint import pprint | |
| import os | |
| deta_key = os.getenv("DETA_KEY") | |
| deta = Deta(deta_key) | |
| db = deta.Base("deprem-ocr") | |
| def get_users_by_city(city_name, limit=10): | |
| user = db.fetch({"city": city_name.capitalize()}, limit=limit).items | |
| return user | |
| def get_all(): | |
| res = db.fetch() | |
| all_items = res.items | |
| # fetch until last is 'None' | |
| while res.last: | |
| res = db.fetch(last=res.last) | |
| all_items += res.items | |
| return all_items | |
| def write_db(data_dict): | |
| # 2) initialize with a project key | |
| deta_key = os.getenv("DETA_KEY") | |
| deta = Deta(deta_key) | |
| # 3) create and use as many DBs as you want! | |
| users = deta.Base("deprem-ocr") | |
| users.insert(data_dict) | |
| print("Pushed to db") | |
| def get_latest_row(last): | |
| all_items = get_all() | |
| latest_items = all_items[-last:] | |
| return latest_items | |