clean up
This commit is contained in:
parent
a628562f6e
commit
2ac2ea5dac
8
TODO.md
Normal file
8
TODO.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
## People
|
||||||
|
|
||||||
|
- [ ] use remaining fields
|
||||||
|
- [ ] Once a day, if there are new commits in openstates/people, re-create.
|
||||||
|
|
||||||
|
## Other
|
||||||
|
|
||||||
|
- [ ] expand data types
|
@ -5,8 +5,6 @@ from .schemas.common import db
|
|||||||
from .schemas.people import Person, PersonLink, PersonSource, PersonRole, PersonOffice
|
from .schemas.people import Person, PersonLink, PersonSource, PersonRole, PersonOffice
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def to_links(person, dict_list, cls):
|
def to_links(person, dict_list, cls):
|
||||||
for dl in dict_list:
|
for dl in dict_list:
|
||||||
cls.create(
|
cls.create(
|
||||||
@ -15,7 +13,8 @@ def to_links(person, dict_list, cls):
|
|||||||
note=dl.pop("note", ""),
|
note=dl.pop("note", ""),
|
||||||
)
|
)
|
||||||
|
|
||||||
def load_people_yaml(dir_path: pathlib.Path):
|
|
||||||
|
def load_people_yaml(dir_path: pathlib.Path) -> int:
|
||||||
# ensure all tables exist
|
# ensure all tables exist
|
||||||
db.create_tables([Person, PersonLink, PersonSource, PersonRole, PersonOffice])
|
db.create_tables([Person, PersonLink, PersonSource, PersonRole, PersonOffice])
|
||||||
|
|
||||||
@ -49,9 +48,9 @@ def load_people_yaml(dir_path: pathlib.Path):
|
|||||||
person=person,
|
person=person,
|
||||||
jurisdiction=role.pop("jurisdiction"),
|
jurisdiction=role.pop("jurisdiction"),
|
||||||
district=role.pop("district", ""),
|
district=role.pop("district", ""),
|
||||||
type=role.pop('type'),
|
type=role.pop("type"),
|
||||||
start_date=role.pop('start_date', None),
|
start_date=role.pop("start_date", None),
|
||||||
end_date=role.pop('end_date', None),
|
end_date=role.pop("end_date", None),
|
||||||
)
|
)
|
||||||
for office in pdata.pop("offices", []):
|
for office in pdata.pop("offices", []):
|
||||||
PersonOffice.create(
|
PersonOffice.create(
|
||||||
@ -59,7 +58,7 @@ def load_people_yaml(dir_path: pathlib.Path):
|
|||||||
classification=office.pop("classification"),
|
classification=office.pop("classification"),
|
||||||
address=office.pop("address", ""),
|
address=office.pop("address", ""),
|
||||||
voice=office.pop("voice", ""),
|
voice=office.pop("voice", ""),
|
||||||
fax=office.pop("fax",""),
|
fax=office.pop("fax", ""),
|
||||||
)
|
)
|
||||||
|
|
||||||
# currently not using other_names, other_identifiers
|
# currently not using other_names, other_identifiers
|
||||||
@ -72,7 +71,6 @@ def load_people_yaml(dir_path: pathlib.Path):
|
|||||||
return created
|
return created
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
path = pathlib.Path(sys.argv[1])
|
path = pathlib.Path(sys.argv[1])
|
||||||
n_people = 0
|
n_people = 0
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
from peewee import SqliteDatabase, Model
|
from peewee import Model
|
||||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||||
|
|
||||||
db = SqliteExtDatabase('openstates.db', pragmas=(
|
db = SqliteExtDatabase(
|
||||||
('cache_size', 1024 * 64), # 64MB page-cache.
|
"openstates.db",
|
||||||
('journal_mode', 'wal'), # Use WAL-mode (you should always use this!).
|
pragmas=(
|
||||||
('foreign_keys', 1))
|
("cache_size", 1024 * 64), # 64MB page-cache.
|
||||||
)
|
("journal_mode", "wal"), # Use WAL-mode (you should always use this!).
|
||||||
|
("foreign_keys", 1),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BaseModel(Model):
|
class BaseModel(Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
database = db
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ from .common import BaseModel
|
|||||||
from peewee import ForeignKeyField, TextField, DateField
|
from peewee import ForeignKeyField, TextField, DateField
|
||||||
from playhouse.sqlite_ext import JSONField
|
from playhouse.sqlite_ext import JSONField
|
||||||
|
|
||||||
|
|
||||||
class Person(BaseModel):
|
class Person(BaseModel):
|
||||||
id = TextField(primary_key=True)
|
id = TextField(primary_key=True)
|
||||||
name = TextField()
|
name = TextField()
|
||||||
@ -13,6 +14,7 @@ class Person(BaseModel):
|
|||||||
party = TextField()
|
party = TextField()
|
||||||
extras = JSONField()
|
extras = JSONField()
|
||||||
|
|
||||||
|
|
||||||
class PersonLink(BaseModel):
|
class PersonLink(BaseModel):
|
||||||
person = ForeignKeyField(Person, backref="links")
|
person = ForeignKeyField(Person, backref="links")
|
||||||
url = TextField()
|
url = TextField()
|
||||||
@ -24,6 +26,7 @@ class PersonSource(BaseModel):
|
|||||||
url = TextField()
|
url = TextField()
|
||||||
note = TextField()
|
note = TextField()
|
||||||
|
|
||||||
|
|
||||||
class PersonRole(BaseModel):
|
class PersonRole(BaseModel):
|
||||||
person = ForeignKeyField(Person, backref="roles")
|
person = ForeignKeyField(Person, backref="roles")
|
||||||
start_date = DateField(null=True)
|
start_date = DateField(null=True)
|
||||||
@ -32,6 +35,7 @@ class PersonRole(BaseModel):
|
|||||||
jurisdiction = TextField()
|
jurisdiction = TextField()
|
||||||
district = TextField()
|
district = TextField()
|
||||||
|
|
||||||
|
|
||||||
class PersonOffice(BaseModel):
|
class PersonOffice(BaseModel):
|
||||||
person = ForeignKeyField(Person, backref="offices")
|
person = ForeignKeyField(Person, backref="offices")
|
||||||
classification = TextField()
|
classification = TextField()
|
||||||
|
Loading…
Reference in New Issue
Block a user