populate.py 835 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python3
  2. import datetime
  3. import json
  4. import lc.config
  5. import lc.model as m
  6. import lc.request as r
  7. def main():
  8. lc.config.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. with open("scripts/aisamanra.json") as f:
  15. links = json.load(f)
  16. for l in links:
  17. time = datetime.datetime.strptime(l["time"], "%Y-%m-%dT%H:%M:%SZ")
  18. req = r.Link(
  19. url=l["href"],
  20. name=l["description"],
  21. description=l["extended"],
  22. private=l["shared"] == "yes",
  23. tags=l["tags"].split(),
  24. created=time,
  25. )
  26. print(m.Link.from_request(u, req))
  27. if __name__ == "__main__":
  28. main()