Source code for the PTG event scheduling bot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 lines
1.5 KiB

  1. #! /usr/bin/env python
  2. # Copyright (c) 2017, Thierry Carrez
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import json
  16. import os
  17. class PTGDataBase():
  18. def __init__(self, filename):
  19. self.filename = filename
  20. if os.path.isfile(filename):
  21. with open(filename, 'r') as fp:
  22. self.data = json.load(fp)
  23. else:
  24. self.data = {'now': {}, 'next': {}}
  25. def add_now(self, room, session):
  26. self.data['now'][room] = session
  27. if room in self.data['next']:
  28. del self.data['next'][room]
  29. self.save()
  30. def add_next(self, room, session):
  31. if room not in self.data['next']:
  32. self.data['next'][room] = []
  33. self.data['next'][room].append(session)
  34. self.save()
  35. def from_ethercalc(self):
  36. # TODO: Load from ethercalc
  37. pass
  38. def save(self):
  39. # self.from_ethercalc()
  40. with open(self.filename, 'w') as fp:
  41. json.dump(self.data, fp)