populate.py 967 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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(
  14. r.User(name="gdritter", password=os.getenv("PASSWORD", "behest").strip(),)
  15. )
  16. u.set_as_admin()
  17. c.log(f"created user {u.name}")
  18. with open("scripts/aisamanra.json") as f:
  19. links = json.load(f)
  20. for l in links:
  21. time = datetime.datetime.strptime(l["time"], "%Y-%m-%dT%H:%M:%SZ")
  22. req = r.Link(
  23. url=l["href"],
  24. name=l["description"],
  25. description=l["extended"],
  26. private=l["shared"] == "no",
  27. tags=l["tags"].split(),
  28. created=time,
  29. )
  30. l = m.Link.from_request(u, req)
  31. c.log(f"created link {l.url}")
  32. if __name__ == "__main__":
  33. main()