filebot/main.py

46 lines
1.1 KiB
Python
Raw Normal View History

2016-04-21 21:55:31 +02:00
from bootstrap import node_generator
from bot import *
from callbacks import init_callbacks
import time
import sys
class FileBot(object):
def __init__(self, path):
super(FileBot, self).__init__()
self.tox = None
self.stop = False
self.profile = None
self.path = path
2016-04-30 14:18:15 +02:00
print 'FileBot v0.1.1'
2016-04-21 21:55:31 +02:00
def main(self):
self.tox = tox_factory(ProfileHelper.open_profile(self.path))
init_callbacks(self.tox)
# bootstrap
for data in node_generator():
self.tox.bootstrap(*data)
settings = Settings()
self.profile = Bot(self.tox)
print 'Iterate'
try:
while not self.stop:
self.tox.iterate()
time.sleep(self.tox.iteration_interval() / 1000.0)
except KeyboardInterrupt:
2016-04-26 19:42:20 +02:00
settings.save()
data = self.tox.get_savedata()
ProfileHelper.save_profile(data)
del self.tox
2016-04-21 21:55:31 +02:00
if __name__ == '__main__':
if len(sys.argv) > 1:
path = sys.argv[1]
bot = FileBot(path)
bot.main()
else:
raise IOError('Path to save file not found')