mirror of
https://github.com/heyarne/berliner-winter.git
synced 2026-05-06 19:23:39 +02:00
50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
import json
|
|
from peewee import *
|
|
|
|
db = SqliteDatabase('violence.db')
|
|
|
|
class BaseModel(Model):
|
|
class Meta:
|
|
database = db
|
|
|
|
def __str__(self):
|
|
r = {}
|
|
for k in self._data.keys():
|
|
try:
|
|
r[k] = str(getattr(self, k))
|
|
except:
|
|
r[k] = json.dumps(getattr(self, k))
|
|
return str(r)
|
|
|
|
class Article(BaseModel):
|
|
"""
|
|
An article is a single incident as crawled from the reach-out webpage
|
|
"""
|
|
date = DateField(index=True)
|
|
month_only = BooleanField(default=False)
|
|
place = CharField()
|
|
description = TextField()
|
|
hash = BlobField(index=True)
|
|
|
|
class Location(BaseModel):
|
|
"""
|
|
A location describes the place an incident has happened
|
|
"""
|
|
confidence = IntegerField()
|
|
lat = DoubleField()
|
|
lng = DoubleField()
|
|
match = CharField()
|
|
returned_place = CharField()
|
|
article = ForeignKeyField(Article)
|
|
|
|
class Category(BaseModel):
|
|
"""
|
|
Describes the category of an incident (e.g. sexism, racism, antisemitism etc)
|
|
"""
|
|
name = CharField()
|
|
article = ForeignKeyField(Article)
|
|
|
|
# Set up the tables
|
|
def create_tables():
|
|
db.connect()
|
|
db.create_tables([Article, Location, Category])
|