populate.py 945 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. import datetime
  3. import json
  4. import os
  5. import lc.config as c
  6. import lc.model as m
  7. import lc.request as r
  8. def main():
  9. c.db.init("test.db")
  10. m.create_tables()
  11. u = m.User.get_or_none(name="gdritter")
  12. if not u:
  13. u = m.User.from_request(r.User(name="gdritter", password=os.getenv("PASSWORD", "behest").strip(),))
  14. u.set_as_admin()
  15. c.log(f"created user {u.name}")
  16. with open("scripts/aisamanra.json") as f:
  17. links = json.load(f)
  18. for l in links:
  19. time = datetime.datetime.strptime(l["time"], "%Y-%m-%dT%H:%M:%SZ")
  20. req = r.Link(
  21. url=l["href"],
  22. name=l["description"],
  23. description=l["extended"],
  24. private=l["shared"] == "no",
  25. tags=l["tags"].split(),
  26. created=time,
  27. )
  28. l = m.Link.from_request(u, req)
  29. c.log(f"created link {l.url}")
  30. if __name__ == "__main__":
  31. main()