manage_participants.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python
  2. import sys
  3. from flask import Flask
  4. from flask.ext.sqlalchemy import SQLAlchemy
  5. from peerfinder import Participant
  6. app = Flask(__name__)
  7. app.config.from_pyfile('config.py')
  8. db = SQLAlchemy(app)
  9. def show_participants():
  10. for p in Participant.query.all():
  11. print("[{}] {}, {} ({}) is {} "
  12. "and has UUID {} ({})".format(p.id,
  13. p.name,
  14. p.country,
  15. p.contact,
  16. "active" if p.active else "inactive",
  17. p.uuid,
  18. p.comment))
  19. def toggle_participant(id):
  20. p = Participant.query.get(id)
  21. p.active = not p.active
  22. db.session.merge(p)
  23. db.session.commit()
  24. print("{}ctivated participant {}".format("A" if p.active else "Dea",
  25. p))
  26. if __name__ == '__main__':
  27. if len(sys.argv) > 1:
  28. toggle_participant(int(sys.argv[1]))
  29. else:
  30. show_participants()