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.

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