The Interface of the fdb-spider, based on rocketchat
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.

801 lines
40 KiB

  1. import os
  2. from rocketchat.api import RocketChatAPI
  3. import configparser
  4. import json
  5. import requests
  6. import yaml
  7. import dateutil.parser
  8. import subprocess
  9. config = configparser.ConfigParser()
  10. config.read('config.ini')
  11. botname = config['Chat']['username']
  12. botpassword = config['Chat']['password']
  13. server_url = config['Chat']['URL']
  14. room_id = config['Chat']['room_id']
  15. bot_user_id = config['Chat']['bot_user_id']
  16. spider_directory = config['Spider']['spider_directory']
  17. # here comes the functions to talk to gpt
  18. # For local streaming, the websockets are hosted without ssl - http://
  19. HOST = 'localhost:5000'
  20. URI = f'http://{HOST}/api/v1/chat'
  21. #URI = f'http://{HOST}/api'
  22. # http://192.168.9.197:5000/api/v1/chat
  23. # For reverse-proxied streaming, the remote will likely host with ssl - https://
  24. # URI = 'https://your-uri-here.trycloudflare.com/api/v1/chat'
  25. if __name__ == '__main__':
  26. def name2id(name):
  27. # get all the rooms
  28. import os
  29. room_list = []
  30. rooms = os.listdir('rooms')
  31. for room in rooms:
  32. room_file = open('rooms/' + room, 'r')
  33. room_file_raw = room_file.read()
  34. room_file.close()
  35. room_file_list = room_file_raw.split('§%§%')
  36. room_list.append([room[:-4], room_file_list[0], room_file_list[1], room_file_list[2], room_file_list[3]])
  37. outputid = 'NONE'
  38. for roo in room_list:
  39. if roo[1] == name:
  40. outputid = roo[0]
  41. return outputid
  42. api = RocketChatAPI(settings={'username': botname, 'password': botpassword, 'domain': server_url})
  43. # api.send_message('Ciao, I am the fdb-spider', room_id)
  44. #myinfo = api.get_my_info()
  45. #room_history = api.get_private_room_history(room_id)
  46. #print(room_history['messages'][0]['msg'])
  47. # print(myinfo)
  48. rooms = api.get_private_rooms()
  49. print('blubidab oioioi', rooms)
  50. # api.send_message('Ole', room_id)
  51. n = 0
  52. import time
  53. import schedule
  54. #change to False here, if you want to have the update run at server start
  55. already_updated = True
  56. start = True
  57. import datetime
  58. from datetime import timedelta
  59. while True:
  60. time.sleep(2)
  61. #already_updated = True
  62. now = datetime.datetime.now()
  63. current_hour = now.strftime("%H")
  64. #print(current_hour)
  65. # run variable update and creation at start
  66. if start == True:
  67. room_list = []
  68. rooms = os.listdir('rooms')
  69. for room in rooms:
  70. room_file = open('rooms/' + room, 'r')
  71. room_file_raw = room_file.read()
  72. room_file.close()
  73. room_file_list = room_file_raw.split('§%§%')
  74. #print(room_list)
  75. #print(room)
  76. #print(room_file_list)
  77. room_list.append([room[:-4], room_file_list[0], room_file_list[1], room_file_list[2]])
  78. with open(spider_directory + '/spiders/config.yaml' , "r") as stream:
  79. try:
  80. config = yaml.safe_load(stream)
  81. except yaml.YAMLError as exc:
  82. print(exc)
  83. fdb_list = []
  84. #print(config)
  85. for key in config:
  86. fdb_list.append(key)
  87. start = False
  88. if int(current_hour) > 11:
  89. aftersix = True
  90. if int(current_hour) <= 11:
  91. aftersix = False
  92. already_updated = False
  93. if aftersix == True and already_updated == False and aftersix == False:
  94. room_list = []
  95. rooms = os.listdir('rooms')
  96. for room in rooms:
  97. room_file = open('rooms/' + room, 'r')
  98. room_file_raw = room_file.read()
  99. room_file.close()
  100. room_file_list = room_file_raw.split('§%§%')
  101. room_list.append([room[:-4], room_file_list[0], room_file_list[1], room_file_list[2], room_file_list[3]])
  102. with open(spider_directory + '/spiders/config.yaml' , "r") as stream:
  103. try:
  104. config = yaml.safe_load(stream)
  105. except yaml.YAMLError as exc:
  106. print(exc)
  107. fdb_list = []
  108. #print(config)
  109. for key in config:
  110. fdb_list.append(key)
  111. data = dict({})
  112. for room in room_list:
  113. #print(room[0])
  114. room_fdbs = room[2]
  115. room_tags = room[3]
  116. room_deadline_days = room[4]
  117. #subprocess.run(["python", spider_directory + 'main.py', fdbs])
  118. room_history_list = []
  119. try:
  120. room_history_file = open('roomhistories/' + room[0] + '.txt', 'x')
  121. room_history_file.close()
  122. except:
  123. print('reading from roomhistory')
  124. with open('roomhistories/' + room[0] + '.txt') as room_history_file:
  125. lines = room_history_file.readlines()
  126. for line in lines:
  127. room_history_list.append(line)
  128. #date = datetime.datetime.now() - timedelta(days=3)
  129. #room_history = api.get_room_history(room[0], oldest=date, latest=datetime.datetime.now())
  130. for room_fdb in eval(room_fdbs):
  131. #print('room_fdb',room_fdb, 'fdb_list',fdb_list)
  132. try:
  133. iteration_var_list = config.get(room_fdb).get("entry-list").get("iteration-var-list")
  134. except Exception as e:
  135. print('there was an error with the entry-list parameter in the config regarding the fdb ', room_fdb)
  136. if room_fdb in fdb_list and room_fdb not in [key for key in data]:
  137. iterdict = {}
  138. for i in eval(iteration_var_list):
  139. f = open(spider_directory + "/spiders/output/" + room_fdb + str(i) + "entryList.txt")
  140. text = f.read()
  141. dictionary_entry_list = eval(text)
  142. iterdict[i] = dictionary_entry_list
  143. data[room_fdb] = iterdict
  144. for i in eval(iteration_var_list):
  145. try:
  146. #print(room_fdb, i)
  147. for key in data[room_fdb][i]:
  148. contains_tag = False
  149. period_data_formatted = dateutil.parser.parse(data[room_fdb][i][key]["period"])
  150. name_data_lower = [word.lower() for word in data[room_fdb][i][key]["name"].split(' ')]
  151. info_data_lower = [word.lower() for word in data[room_fdb][i][key]["info"].split(' ')]
  152. text_data_lower = [word.lower() for word in data[room_fdb][i][key]["text"].split(' ')]
  153. tag_list = []
  154. for tag in eval(room_tags):
  155. if '_' in tag:
  156. ntags = tag.split('_')
  157. ntags_length = len(ntags)
  158. ntag_count = 0
  159. for nword in name_data_lower:
  160. for ntag in ntags:
  161. if ntag.lower() in nword:
  162. ntag_count += 1
  163. if ntag_count == ntags_length:
  164. contains_tag = True
  165. tag_list.append(tag + ' in name')
  166. ntag_count = 0
  167. for iword in info_data_lower:
  168. for ntag in ntags:
  169. if ntag.lower() in iword:
  170. ntag_count += 1
  171. if ntag_count == ntags_length:
  172. contains_tag = True
  173. tag_list.append(tag + ' in info')
  174. ntag_count = 0
  175. for tword in text_data_lower:
  176. ntag_count = 0
  177. for ntag in ntags:
  178. if ntag.lower() in tword:
  179. ntag_count += 1
  180. if ntag_count == ntags_length:
  181. contains_tag = True
  182. tag_list.append(tag + ' in text')
  183. else:
  184. for nword in name_data_lower:
  185. if tag.lower() in nword:
  186. contains_tag = True
  187. tag_list.append(tag + ' in name')
  188. for iword in info_data_lower:
  189. if tag.lower() in iword:
  190. contains_tag = True
  191. tag_list.append(tag + ' in info')
  192. for tword in text_data_lower:
  193. if tag.lower() in tword:
  194. contains_tag = True
  195. tag_list.append(tag + ' in text')
  196. if contains_tag == True:
  197. try:
  198. url = data[room_fdb][i][key]["domain"]
  199. except:
  200. url = data[room_fdb][i][key]["link"]
  201. entry_message = '<' + url + '|' + data[room_fdb][i][key]["name"]+ '>' + '\n' + data[room_fdb][i][key]["info"] + '\n' + 'The period of the entry is:' + str(period_data_formatted) + '\n' + str(tag_list)
  202. entry_message_identifier = '<' + url + '|' + data[room_fdb][i][key]["name"]+ '>'
  203. message_was_already_there = False
  204. for message in room_history_list:
  205. #print('message that gets checked with identifier ', message[:-1])
  206. #print('the entry message identifier is:', entry_message_identifier)
  207. if url in message[:-1] or data[room_fdb][i][key]["name"] in message:
  208. message_was_already_there = True
  209. now = datetime.datetime.now()
  210. now_formatted = dateutil.parser.parse(str(now))
  211. delta = period_data_formatted - now_formatted
  212. if message_was_already_there == False and delta.days < int(room_deadline_days):
  213. #print('went into already there false')
  214. api.send_message(entry_message, room[0])
  215. print('before writing')
  216. try:
  217. room_file = open('roomhistories/' + room[0] + '.txt', 'x')
  218. room_file.close()
  219. except:
  220. print('appending to roomhistory')
  221. room_file = open('roomhistories/' + room[0] + '.txt', 'a')
  222. room_file.write(entry_message_identifier + '\n')
  223. room_file.close()
  224. print('after writing')
  225. except Exception as e:
  226. print("probably i was not there in last page, original error is:", e)
  227. #print('data',data['giz'][2],'data')
  228. already_updated = True
  229. # if datestime.split over etc and updated= true etc
  230. n += 1
  231. if n%100 == 0:
  232. print(n)
  233. try:
  234. #print('getting the room history')
  235. date = datetime.datetime.now() - timedelta(days=3)
  236. room_history = api.get_private_room_history(room_id, oldest=date)
  237. except Exception as e:
  238. time.sleep(10)
  239. api = RocketChatAPI(settings={'username': botname, 'password': botpassword, 'domain': server_url})
  240. time.sleep(5)
  241. room_history = api.get_private_room_history(room_id, oldest=date)
  242. print('got a connection error, original message is:',e)
  243. messages_list = []
  244. for message in room_history['messages']:
  245. messages_list.append(message)
  246. if len(messages_list) >= 1:
  247. #print('blub', messages_list)
  248. latest_message_user_id = messages_list[0]['u']['_id']
  249. latest_message_user_username = messages_list[0]['u']['username']
  250. latest_message = messages_list[0]['msg']
  251. latest_message_id = messages_list[0]['_id']
  252. new_message_file = open('new_message_file.txt', 'r')
  253. new_message = new_message_file.read()
  254. new_message_file.close()
  255. new_message_list = new_message.split('§%§%')
  256. #print(latest_message, new_message_list[0])
  257. if new_message_list[0] != latest_message and new_message_list[1] != latest_message_id and latest_message_user_id != bot_user_id:
  258. answer = 'Ich habe kein Kommando erhalten.'
  259. new_message_file = open('new_message_file.txt', 'w')
  260. new_message_file.write(latest_message + '§%§%' + latest_message_id)
  261. new_message_file.close()
  262. user_input = latest_message
  263. user_input_list = user_input.split(' ')
  264. if user_input_list[0] == 'addtags':
  265. try:
  266. room_name_add_tags = user_input_list[1]
  267. room_id_add_tags = name2id(room_name_add_tags)
  268. except:
  269. room_id_add_tags = 'NONE'
  270. try:
  271. new_tags = user_input_list[2]
  272. except:
  273. new_tags = 'NONE'
  274. try:
  275. thirdarg = user_input_list[3]
  276. except:
  277. thirdarg = 'NONE'
  278. if room_id_add_tags != 'NONE' and len(new_tags) >= 1 and thirdarg == 'NONE':
  279. try:
  280. room_file_add_tags = open('rooms/' + room_id_add_tags + '.txt', 'r')
  281. room_info_raw = room_file_add_tags.read()
  282. room_file_add_tags.close()
  283. room_info = room_info_raw.split('§%§%')
  284. tag_list = eval(room_info[-1])
  285. for tag in eval(user_input_list[2]):
  286. if tag not in tag_list:
  287. tag_list.append(tag)
  288. room_file_add_tags = open('rooms/' + room_id_add_tags + '.txt', 'w')
  289. room_file_add_tags.write( str(room_info[0]) + '§%§%' + str(room_info[1]) + '§%§%' + str(tag_list))
  290. room_file_add_tags.close()
  291. answer = 'the updated tag list is' + str(tag_list)
  292. except Exception as e:
  293. print('error opening, original error is:', e)
  294. answer = "The room_id to update the tags was not found"
  295. if user_input_list[0] == 'printtags':
  296. try:
  297. room_id_to_print_tags = user_input_list[1]
  298. except:
  299. answer = "after the command printtags, the second argument has to be the room id.. use printrooms and look up the id of the room you want to print the tags"
  300. room_id_to_print_tags = 'NONE'
  301. if room_id_to_print_tags != 'NONE':
  302. try:
  303. room_file = open('rooms/' + room_id_to_print_tags + '.txt', 'r')
  304. room_info_raw = room_file.read()
  305. room_file.close()
  306. room_info = room_info_raw.split('§%§%')
  307. tag_list = eval(room_info[-1])
  308. answer = tag_list
  309. except Exception as e:
  310. print('error opening, original error is:', e)
  311. answer = "The room_id to get the tags was not found"
  312. if user_input_list[0] == 'printcommands':
  313. answer = """
  314. To print all available rooms and their configuration, use
  315. command : `printrooms`
  316. -----------------------------------------------------------------------------------------
  317. To print all available fdbs, use
  318. command : `printfdbs`
  319. -----------------------------------------------------------------------------------------
  320. To update all rooms use
  321. command : `updaterooms all`
  322. -----------------------------------------------------------------------------------------
  323. To update one room use the room_id from the output of printrooms:
  324. command : `updaterooms <room-id>`
  325. example : `updaterooms 6572012bebb39dd248d08320`
  326. -----------------------------------------------------------------------------------------
  327. To create a room use following command, but be sure to **not have spaces** in your lists,
  328. as a space indicates a new command argument:
  329. command : `createroom <room-name> <list-fdbs> <list-tags> <days-to-deadline>`
  330. example : `createroom room-test-1 ['giz','fdb2'] ['tag1','tag2','tag3'] 7`
  331. -----------------------------------------------------------------------------------------
  332. To delete a room use
  333. command : `deleteroom <room-id>`
  334. example : `deleteroom 6572012bebb39dd248d08320`
  335. -----------------------------------------------------------------------------------------
  336. To print the tags of a room use
  337. command : `printtags <room-id>`
  338. example : `printtags 6572012bebb39dd248d08320`
  339. -----------------------------------------------------------------------------------------
  340. To add tags to the existing tags use
  341. command : `addtags <room-id> <tag-list-without-spaces>`
  342. example : `addtags 6572012bebb39dd248d08320 ['tag1','tag2','tag3']`
  343. """
  344. if user_input_list[0] == 'printrooms':
  345. room_was_found = False
  346. # get all the rooms
  347. import os
  348. room_list = []
  349. rooms = os.listdir('rooms')
  350. for room in rooms:
  351. room_file = open('rooms/' + room, 'r')
  352. room_file_raw = room_file.read()
  353. room_file.close()
  354. room_file_list = room_file_raw.split('§%§%')
  355. room_list.append([room[:-4], room_file_list[0], room_file_list[1], room_file_list[2], room_file_list[3]])
  356. room_list_string = ''
  357. for room in room_list:
  358. room_list_string += str(room) + '\n' + '------------------------------------------------------------------------------' + '\n'
  359. #print(room_list)
  360. answer = room_list_string
  361. if user_input_list[0] == 'updaterooms':
  362. try:
  363. if len(user_input_list[1]) >= 1:
  364. room_to_update = user_input_list[1]
  365. except Exception as e:
  366. room_to_update = 'NONE'
  367. room_list = []
  368. rooms = os.listdir('rooms')
  369. for room in rooms:
  370. room_file = open('rooms/' + room, 'r')
  371. room_file_raw = room_file.read()
  372. room_file.close()
  373. room_file_list = room_file_raw.split('§%§%')
  374. room_list.append([room[:-4], room_file_list[0], room_file_list[1], room_file_list[2], room_file_list[3]])
  375. with open(spider_directory + '/spiders/config.yaml' , "r") as stream:
  376. try:
  377. config = yaml.safe_load(stream)
  378. except yaml.YAMLError as exc:
  379. print(exc)
  380. fdb_list = []
  381. #print(config)
  382. for key in config:
  383. fdb_list.append(key)
  384. answer = "Ich update die Rooms auf Basis der Daten von heute morgen um 6 Uhr.."
  385. data = dict({})
  386. for room in room_list:
  387. if room[0] == room_to_update or room_to_update == 'all':
  388. room_was_found = True
  389. print(room[0])
  390. room_fdbs = room[2]
  391. room_tags = room[3]
  392. room_deadline_days = room[4]
  393. # not running get_rooms because disfunctional
  394. #subprocess.run(["python", spider_directory + 'main.py', fdbs])
  395. #myinfo = api.get_room_info(room[0])
  396. #print(myinfo)
  397. #roomid = "'657cbeccebb39dd248d38ec3'"
  398. #roomoioioi = api.get_user_info(bot_user_id)
  399. #print(roomoioioi)
  400. #room_history_updateroom = api.get_private_room_history(room[0])
  401. # reading from txt state history instead
  402. try:
  403. room_history_file = open('roomhistories/' + room[0] + '.txt', 'x')
  404. room_history_file.close()
  405. except:
  406. print('reading from roomhistory which is already there')
  407. room_history_list = []
  408. with open('roomhistories/' + room[0] + '.txt') as room_history_file:
  409. lines = room_history_file.readlines()
  410. for line in lines:
  411. room_history_list.append(line)
  412. #
  413. #for message in room_history_raw:
  414. # print(message)
  415. for room_fdb in eval(room_fdbs):
  416. #print('room_fdb',room_fdb, 'fdb_list',fdb_list)
  417. try:
  418. iteration_var_list = config.get(room_fdb).get("entry-list").get("iteration-var-list")
  419. except Exception as e:
  420. print('there was an error with the entry-list parameter in the config regarding the fdb ', room_fdb)
  421. if room_fdb in fdb_list and room_fdb not in [key for key in data]:
  422. iterdict = {}
  423. for i in eval(iteration_var_list):
  424. f = open(spider_directory + "/spiders/output/" + room_fdb + str(i) + "entryList.txt")
  425. text = f.read()
  426. dictionary_entry_list = eval(text)
  427. iterdict[i] = dictionary_entry_list
  428. data[room_fdb] = iterdict
  429. for i in eval(iteration_var_list):
  430. try:
  431. print(room_fdb, i)
  432. print('oioioioioiOIOIOI')
  433. for key in data[room_fdb][i]:
  434. contains_tag = False
  435. try:
  436. period_data_formatted = dateutil.parser.parse(data[room_fdb][i][key]["period"])
  437. except Exception as e:
  438. period_data_formatted = 'NONE'
  439. print('getting the period did not work for', room_fdb, i, key, ' ori err is:', e)
  440. name_data_lower = [word.lower() for word in data[room_fdb][i][key]["name"].split(' ')]
  441. info_data_lower = [word.lower() for word in data[room_fdb][i][key]["info"].split(' ')]
  442. text_data_lower = [word.lower() for word in data[room_fdb][i][key]["text"].split(' ')]
  443. print('got until ONE')
  444. tag_list = []
  445. for tag in eval(room_tags):
  446. print('got until TWO')
  447. if '_' in tag:
  448. ntags = tag.split('_')
  449. ntags_length = len(ntags)
  450. print(ntags)
  451. ntag_count = 0
  452. for ntag in ntags:
  453. print('searching for ntag: ', ntag)
  454. for nword in name_data_lower:
  455. if ntag.lower() in nword:
  456. if nword != '':
  457. ntag_count += 1
  458. print(ntag, ' ntag was found')
  459. break
  460. print('ntag count is ', ntag_count, 'ntag_length is ', ntags_length)
  461. if ntag_count == ntags_length:
  462. contains_tag = True
  463. tag_list.append('_'.join(ntags) + ' in name')
  464. ntag_count = 0
  465. for ntag in ntags:
  466. for iword in info_data_lower:
  467. if ntag.lower() in iword:
  468. if iword != '':
  469. ntag_count += 1
  470. break
  471. if ntag_count == ntags_length:
  472. contains_tag = True
  473. tag_list.append('_'.join(ntags) + ' in info')
  474. ntag_count = 0
  475. for ntag in ntags:
  476. for tword in text_data_lower:
  477. if ntag.lower() in tword:
  478. if tword != '':
  479. ntag_count += 1
  480. break
  481. if ntag_count == ntags_length:
  482. contains_tag = True
  483. tag_list.append('_'.join(ntags) + ' in text')
  484. else:
  485. #print('------------------')
  486. print(name_data_lower, info_data_lower, text_data_lower, room[0], room_tags)
  487. nword_contains_tag = False
  488. for nword in name_data_lower:
  489. print(tag.lower(), nword)
  490. if tag.lower() in nword:
  491. print('goooot heeeere')
  492. print(nword)
  493. if nword != '':
  494. print('goot behind nword check')
  495. nword_contains_tag = True
  496. if nword_contains_tag == True:
  497. contains_tag = True
  498. tag_list.append(tag + ' in name')
  499. iword_contains_tag = False
  500. for iword in info_data_lower:
  501. if tag.lower() in iword:
  502. if iword != '':
  503. iword_contains_tag = True
  504. print('oioiOIOIOIoioioiOIOIword', iword)
  505. if iword_contains_tag == True:
  506. contains_tag = True
  507. tag_list.append(tag + ' in info')
  508. tword_contains_tag = False
  509. for tword in text_data_lower:
  510. if tag.lower() in tword:
  511. if tword != '':
  512. tword_contains_tag = True
  513. if tword_contains_tag == True:
  514. contains_tag = True
  515. tag_list.append(tag + ' in text')
  516. print('got until THREE')
  517. if contains_tag == True:
  518. #print('------------------')
  519. #print(name_data_lower, info_data_lower, text_data_lower)
  520. try:
  521. url = data[room_fdb][i][key]["domain"]
  522. except:
  523. url = data[room_fdb][i][key]["link"]
  524. print('101110001101010010010101000111')
  525. entry_message = '<' + url + '|' + data[room_fdb][i][key]["name"]+ '>' + '\n' + data[room_fdb][i][key]["info"] + '\n' + 'The period of the entry is:' + str(period_data_formatted) + '\n' + str(tag_list)
  526. entry_message_identifier = '<' + url + '|' + data[room_fdb][i][key]["name"]+ '>'
  527. message_was_already_there = False
  528. for message in room_history_list:
  529. print('message', message[:-1], 'identifier', entry_message_identifier)
  530. if url in message[:-1] or data[room_fdb][i][key]["name"] in message:
  531. message_was_already_there = True
  532. now = datetime.datetime.now()
  533. now_formatted = dateutil.parser.parse(str(now))
  534. try:
  535. delta = period_data_formatted - now_formatted
  536. days_to_check = delta.days
  537. except Exception as e:
  538. days_to_check = int(room_deadline_days) - 1
  539. print('calc of delta did now work, original error is:', e)
  540. #print('delta', delta, int(delta.days))
  541. if message_was_already_there == False and int(days_to_check) > int(room_deadline_days):
  542. api.send_message(entry_message, room[0])
  543. try:
  544. room_file = open('roomhistories/' + room[0] + '.txt', 'x')
  545. room_file.close()
  546. except:
  547. print('appending to roomhistory')
  548. room_file = open('roomhistories/' + room[0] + '.txt', 'a')
  549. room_file.write(entry_message_identifier + '\n')
  550. room_file.close()
  551. except Exception as e:
  552. print("probably i was not there in last page, original error is:", e)
  553. if room_to_update == 'all':
  554. answer = 'I am updating all rooms based on the data in fdb-spider/spiders/output..'
  555. if room_was_found == False or room_to_update == 'NONE':
  556. answer = 'The room you specified does not exist, or there are no rooms configured, try printcommands or contact the administrator'
  557. if room_was_found == True and room_to_update != 'NONE':
  558. answer = "I am updating the specified room based on the data in fdb-spider/spiders/output.."
  559. if user_input_list[0] == 'printfdbs':
  560. answer = str(fdb_list)
  561. if len(user_input_list) > 1:
  562. answer = 'Die Syntax zum Ausgeben der konfigurierten Förderdatenbanken hat einen Fehler. Versuche es erneut, mit -> printfdbs'
  563. if user_input_list[0] == 'deleteroom':
  564. try:
  565. room_id_del = user_input_list[1]
  566. except Exception as e:
  567. room_id_del = 'NONE'
  568. print(e)
  569. os.remove("rooms/" + room_id_del + ".txt")
  570. anwer = 'deleting the requested room..'
  571. if len(user_input_list) > 2:
  572. answer = 'Die Syntax zum Löschen eines Raumes hat einen Fehler. Versuche es erneut, nach dem Muster -> deleteroom <room_id>'
  573. if user_input_list[0] == 'createroom':
  574. try:
  575. room_name = user_input_list[1]
  576. except Exception as e:
  577. room_name = 'NONE'
  578. print(e)
  579. try:
  580. databases = user_input_list[2]
  581. except Exception as e:
  582. databases = 'NONE'
  583. print(e)
  584. try:
  585. filters = user_input_list[3]
  586. except Exception as e:
  587. filters = 'NONE'
  588. print(e)
  589. try:
  590. days_to_deadline = user_input_list[4]
  591. except Exception as e:
  592. days_to_deadline = 'NONE'
  593. print(e)
  594. if len(user_input_list) > 4:
  595. answer = 'Die Syntax hat einen Fehler. Wahrscheinlich sind Leerzeichen in den Listen. Leerzeichen definieren die Syntax. Versuche es erneut, nach dem Muster -> createroom room1 ["fdb1","fdb2"] ["tag1","tag2"]'
  596. if room_name == 'NONE' or databases == 'NONE' or filters == 'NONE' or days_to_deadline == 'NONE':
  597. answer = 'Um einen Raum zu erstellen, in dem neueste Einträge geteilt werden, lautet die Syntax: createroom <Raumname> <Liste-Datenbanken> <Liste-Filtertags> <Tage-bis-zur-Frist>'
  598. else:
  599. try:
  600. new_room = api.create_public_room(room_name,
  601. members=[latest_message_user_username],
  602. read_only=False)
  603. new_room_id = new_room['channel']['_id']
  604. room_file = open('rooms/' + new_room_id + '.txt', 'w')
  605. room_file.write( room_name + '§%§%' + databases + '§%§%' + filters + '§%§%' + days_to_deadline)
  606. room_file.close()
  607. answer = 'Der Command wurde übermittelt'
  608. except Exception as e:
  609. print('it was not able to create the room, the original error message is:', e)
  610. answer = 'There was an error creating the room, look up the logs.. the original error was: ' + str(e)
  611. #print('oi', user_input)
  612. api.send_message('Die Anfrage wird bearbeitet..', room_id)
  613. # here comes the code interacting with the spiders output json
  614. #answer = 'the up to date entries are: oi Oi Oi!'
  615. api.send_message(answer, room_id)
  616. time.sleep(1)
  617. api.send_message('Ich bin wieder bereit für Konfigurationsinput : )', room_id)
  618. time.sleep(1)