populate.py 905 B

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