Spaces:
Sleeping
Sleeping
File size: 886 Bytes
3ec8945 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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
|