added some further commands like addtags, printtags and printcommands
This commit is contained in:
parent
0bac9ec8a7
commit
e7272bf6f9
2 changed files with 119 additions and 8 deletions
|
@ -53,22 +53,58 @@ if __name__ == '__main__':
|
|||
import time
|
||||
import schedule
|
||||
|
||||
already_updated = False
|
||||
#change to False here, if you want to have the update run at server start
|
||||
already_updated = True
|
||||
start = True
|
||||
import datetime
|
||||
from datetime import timedelta
|
||||
while True:
|
||||
time.sleep(4)
|
||||
time.sleep(2)
|
||||
#already_updated = True
|
||||
now = datetime.datetime.now()
|
||||
|
||||
current_hour = now.strftime("%H")
|
||||
#print(current_hour)
|
||||
|
||||
if int(current_hour) > 6:
|
||||
# run variable update and creation at start
|
||||
if start == True:
|
||||
room_list = []
|
||||
rooms = os.listdir('rooms')
|
||||
for room in rooms:
|
||||
room_file = open('rooms/' + room, 'r')
|
||||
room_file_raw = room_file.read()
|
||||
room_file.close()
|
||||
|
||||
|
||||
room_file_list = room_file_raw.split('§%§%')
|
||||
print(room_list)
|
||||
print(room)
|
||||
print(room_file_list)
|
||||
room_list.append([room[:-4], room_file_list[0], room_file_list[1], room_file_list[2]])
|
||||
|
||||
with open(spider_directory + '/spiders/config.yaml' , "r") as stream:
|
||||
try:
|
||||
config = yaml.safe_load(stream)
|
||||
except yaml.YAMLError as exc:
|
||||
print(exc)
|
||||
fdb_list = []
|
||||
#print(config)
|
||||
|
||||
for key in config:
|
||||
fdb_list.append(key)
|
||||
|
||||
start = False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if int(current_hour) > 11:
|
||||
aftersix = True
|
||||
|
||||
if int(current_hour) < 6:
|
||||
if int(current_hour) <= 11:
|
||||
aftersix = False
|
||||
already_updated == False
|
||||
already_updated = False
|
||||
|
||||
if aftersix == True and already_updated == False:
|
||||
|
||||
|
@ -212,6 +248,78 @@ if __name__ == '__main__':
|
|||
|
||||
|
||||
|
||||
if user_input_list[0] == 'addtags':
|
||||
try:
|
||||
room_id_add_tags = user_input_list[1]
|
||||
except:
|
||||
room_id_add_tags = 'NONE'
|
||||
try:
|
||||
new_tags = user_input_list[2]
|
||||
except:
|
||||
new_tags = 'NONE'
|
||||
try:
|
||||
thirdarg = user_input_list[3]
|
||||
except:
|
||||
thirdarg = 'NONE'
|
||||
if len(room_id_add_tags) >= 1 and len(new_tags) >= 1 and thirdarg == 'NONE':
|
||||
try:
|
||||
|
||||
room_file_add_tags = open('rooms/' + user_input_list[1] + '.txt', 'r')
|
||||
room_info_raw = room_file_add_tags.read()
|
||||
room_file_add_tags.close()
|
||||
room_info = room_info_raw.split('§%§%')
|
||||
tag_list = eval(room_info[-1])
|
||||
for tag in eval(user_input_list[2]):
|
||||
if tag not in tag_list:
|
||||
tag_list.append(tag)
|
||||
|
||||
room_file_add_tags = open('rooms/' + user_input_list[1] + '.txt', 'w')
|
||||
room_file_add_tags.write( str(room_info[0]) + '§%§%' + str(room_info[1]) + '§%§%' + str(tag_list))
|
||||
room_file_add_tags.close()
|
||||
answer = 'the updated tag list is' + str(tag_list)
|
||||
|
||||
except Exception as e:
|
||||
print('error opening, original error is:', e)
|
||||
answer = "The room_id to update the tags was not found"
|
||||
|
||||
if user_input_list[0] == 'printtags':
|
||||
if len(user_input_list[1]) >= 1:
|
||||
try:
|
||||
|
||||
room_file = open('rooms/' + user_input_list[1] + '.txt', 'r')
|
||||
room_info_raw = room_file.read()
|
||||
room_file.close()
|
||||
room_info = room_info_raw.split('§%§%')
|
||||
tag_list = eval(room_info[-1])
|
||||
answer = tag_list
|
||||
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print('error opening, original error is:', e)
|
||||
answer = "The room_id to get the tags was not found"
|
||||
|
||||
|
||||
|
||||
if user_input_list[0] == 'printcommands':
|
||||
answer = """
|
||||
|
||||
To print all available rooms and their configuration, use
|
||||
`printrooms`
|
||||
To print all available fdbs, use
|
||||
`printfdbs`
|
||||
To update all rooms use
|
||||
`updaterooms`
|
||||
To update one room use the room_id from the output of printrooms:
|
||||
`updaterooms <room_id>`
|
||||
To create a room use following command, but be sure to not have spaces in your lists, as a space indicates a new command argument:
|
||||
`createroom <room-name> <list-fdbs> <list-tags>`
|
||||
To delete a room use
|
||||
`deleteroom <room_id>`
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
if user_input_list[0] == 'printrooms':
|
||||
|
||||
|
@ -233,7 +341,10 @@ if __name__ == '__main__':
|
|||
answer = str(room_list)
|
||||
|
||||
if user_input_list[0] == 'updaterooms':
|
||||
|
||||
if len(user_input_list[1]) >= 1:
|
||||
room_to_update = user_input_list[1]
|
||||
else:
|
||||
room_to_update = 'NONE'
|
||||
room_list = []
|
||||
rooms = os.listdir('rooms')
|
||||
for room in rooms:
|
||||
|
@ -262,7 +373,7 @@ if __name__ == '__main__':
|
|||
|
||||
data = dict({})
|
||||
for room in room_list:
|
||||
if room[0] == room_to_update:
|
||||
if room[0] == room_to_update or room_to_update == 'NONE':
|
||||
room_was_found = True
|
||||
print(room[0])
|
||||
room_fdbs = room[2]
|
||||
|
|
|
@ -1 +1 @@
|
|||
updaterooms§%§%ramWq2wQnMLem29uR
|
||||
printtags 6576ec7cebb39dd248d19f34§%§%b53Pv64ZFr65Q44Qy
|
Loading…
Reference in a new issue