aboutsummaryrefslogblamecommitdiff
blob: 00897d7feb623747790e3b086056e3de33691800 (plain) (tree)
1
2
3
4
5
6
7

                    




                                     















                                                               
                                                                                








































                                                         
from peewee import *

TOOT_VISIBILITY_PUBLIC = "public"
TOOT_VISIBILITY_UNLISTED = "unlisted"
TOOT_VISIBILITY_PRIVATE = "private"


db = SqliteDatabase("checkinbot.db")
db.connect(reuse_if_open=True)


class BaseModel(Model):
    class Meta:
        database = db


class User(BaseModel):
    telegram_user_id = CharField(unique=True, primary_key=True)
    access_key = CharField(max_length=64)
    home_instance = CharField(max_length=128)
    state = CharField(max_length=128)
    client_id = CharField(max_length=128)
    client_secret = CharField(max_length=128)
    toot_visibility = CharField(max_length=128, default=TOOT_VISIBILITY_PRIVATE)


class Location(BaseModel):
    fsq_id = CharField(unique=True, primary_key=True)
    name = CharField(max_length=128)
    locality = CharField(max_length=128)
    region = CharField(max_length=128)
    latitude = CharField(max_length=128)
    longitude = CharField(max_length=128)


with db.connection_context():
    db.create_tables([User, Location])


def get_poi_by_fsq_id(fsq_id) -> dict:
    with db.connection_context():
        try:
            poi = Location.get(Location.fsq_id == fsq_id)
            return {
                "name": poi.name,
                "locality": poi.locality,
                "region": poi.region,
                "latitude": poi.latitude,
                "longitude": poi.longitude,
            }
        except DoesNotExist:
            return {}


def create_poi(poi: dict):
    with db.connection_context():
        poi = Location.create(
            fsq_id=poi["fsq_id"],
            name=poi["name"],
            locality=poi["locality"],
            region=poi["region"],
            latitude=poi["latitude"],
            longitude=poi["longitude"],
        )
        poi.save()
Powered by cgit v1.2.3 (git 2.41.0)