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.

776 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 all`
  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 == 'all':
  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. try:
  419. period_data_formatted = dateutil.parser.parse(data[room_fdb][i][key]["period"])
  420. except Exception as e:
  421. period_data_formatted = 'NONE'
  422. print('getting the period did not work for', room_fdb, i, key, ' ori err is:', e)
  423. name_data_lower = [word.lower() for word in data[room_fdb][i][key]["name"].split(' ')]
  424. info_data_lower = [word.lower() for word in data[room_fdb][i][key]["info"].split(' ')]
  425. text_data_lower = [word.lower() for word in data[room_fdb][i][key]["text"].split(' ')]
  426. print('got until ONE')
  427. tag_list = []
  428. for tag in eval(room_tags):
  429. print('got until TWO')
  430. if '_' in tag:
  431. ntags = tag.split('_')
  432. ntags_length = len(ntags)
  433. print(ntags)
  434. ntag_count = 0
  435. for ntag in ntags:
  436. print('searching for ntag: ', ntag)
  437. for nword in name_data_lower:
  438. if ntag.lower() in nword:
  439. if nword != '':
  440. ntag_count += 1
  441. print(ntag, ' ntag was found')
  442. break
  443. print('ntag count is ', ntag_count, 'ntag_length is ', ntags_length)
  444. if ntag_count == ntags_length:
  445. contains_tag = True
  446. tag_list.append('_'.join(ntags) + ' in name')
  447. ntag_count = 0
  448. for ntag in ntags:
  449. for iword in info_data_lower:
  450. if ntag.lower() in iword:
  451. if iword != '':
  452. ntag_count += 1
  453. break
  454. if ntag_count == ntags_length:
  455. contains_tag = True
  456. tag_list.append('_'.join(ntags) + ' in info')
  457. ntag_count = 0
  458. for ntag in ntags:
  459. for tword in text_data_lower:
  460. if ntag.lower() in tword:
  461. if tword != '':
  462. ntag_count += 1
  463. break
  464. if ntag_count == ntags_length:
  465. contains_tag = True
  466. tag_list.append('_'.join(ntags) + ' in text')
  467. else:
  468. #print('------------------')
  469. print(name_data_lower, info_data_lower, text_data_lower, room[0], room_tags)
  470. nword_contains_tag = False
  471. for nword in name_data_lower:
  472. print(tag.lower(), nword)
  473. if tag.lower() in nword:
  474. print('goooot heeeere')
  475. print(nword)
  476. if nword != '':
  477. print('goot behind nword check')
  478. nword_contains_tag = True
  479. if nword_contains_tag == True:
  480. contains_tag = True
  481. tag_list.append(tag + ' in name')
  482. iword_contains_tag = False
  483. for iword in info_data_lower:
  484. if tag.lower() in iword:
  485. if iword != '':
  486. iword_contains_tag = True
  487. print('oioiOIOIOIoioioiOIOIword', iword)
  488. if iword_contains_tag == True:
  489. contains_tag = True
  490. tag_list.append(tag + ' in info')
  491. tword_contains_tag = False
  492. for tword in text_data_lower:
  493. if tag.lower() in tword:
  494. if tword != '':
  495. tword_contains_tag = True
  496. if tword_contains_tag == True:
  497. contains_tag = True
  498. tag_list.append(tag + ' in text')
  499. print('got until THREE')
  500. if contains_tag == True:
  501. #print('------------------')
  502. #print(name_data_lower, info_data_lower, text_data_lower)
  503. try:
  504. url = data[room_fdb][i][key]["domain"]
  505. except:
  506. url = data[room_fdb][i][key]["link"]
  507. print('101110001101010010010101000111')
  508. 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)
  509. entry_message_identifier = '<' + url + '|' + data[room_fdb][i][key]["name"]+ '>'
  510. message_was_already_there = False
  511. for message in room_history_list:
  512. print('message', message[:-1], 'identifier', entry_message_identifier)
  513. if url in message[:-1] or data[room_fdb][i][key]["name"] in message:
  514. message_was_already_there = True
  515. now = datetime.datetime.now()
  516. now_formatted = dateutil.parser.parse(str(now))
  517. try:
  518. delta = period_data_formatted - now_formatted
  519. days_to_check = delta.days
  520. except Exception as e:
  521. days_to_check = int(room_deadline_days) - 1
  522. print('calc of delta did now work, original error is:', e)
  523. #print('delta', delta, int(delta.days))
  524. if message_was_already_there == False and int(days_to_check) > int(room_deadline_days):
  525. api.send_message(entry_message, room[0])
  526. try:
  527. room_file = open('roomhistories/' + room[0] + '.txt', 'x')
  528. room_file.close()
  529. except:
  530. print('appending to roomhistory')
  531. room_file = open('roomhistories/' + room[0] + '.txt', 'a')
  532. room_file.write(entry_message_identifier + '\n')
  533. room_file.close()
  534. except Exception as e:
  535. print("probably i was not there in last page, original error is:", e)
  536. if room_to_update == 'all':
  537. answer = 'I am updating all rooms based on the data in fdb-spider/spiders/output..'
  538. if room_was_found == False or room_to_update == 'NONE':
  539. answer = 'The room you specified does not exist, or there are no rooms configured, try printcommands or contact the administrator'
  540. if room_was_found == True and room_to_update != 'NONE':
  541. answer = "I am updating the specified room based on the data in fdb-spider/spiders/output.."
  542. if user_input_list[0] == 'printfdbs':
  543. answer = str(fdb_list)
  544. if len(user_input_list) > 1:
  545. answer = 'Die Syntax zum Ausgeben der konfigurierten Förderdatenbanken hat einen Fehler. Versuche es erneut, mit -> printfdbs'
  546. if user_input_list[0] == 'deleteroom':
  547. try:
  548. room_id_del = user_input_list[1]
  549. except Exception as e:
  550. room_id_del = 'NONE'
  551. print(e)
  552. os.remove("rooms/" + room_id_del + ".txt")
  553. anwer = 'deleting the requested room..'
  554. if len(user_input_list) > 2:
  555. answer = 'Die Syntax zum Löschen eines Raumes hat einen Fehler. Versuche es erneut, nach dem Muster -> deleteroom <room_id>'
  556. if user_input_list[0] == 'createroom':
  557. try:
  558. room_name = user_input_list[1]
  559. except Exception as e:
  560. room_name = 'NONE'
  561. print(e)
  562. try:
  563. databases = user_input_list[2]
  564. except Exception as e:
  565. databases = 'NONE'
  566. print(e)
  567. try:
  568. filters = user_input_list[3]
  569. except Exception as e:
  570. filters = 'NONE'
  571. print(e)
  572. try:
  573. days_to_deadline = user_input_list[4]
  574. except Exception as e:
  575. days_to_deadline = 'NONE'
  576. print(e)
  577. if len(user_input_list) > 4:
  578. 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"]'
  579. if room_name == 'NONE' or databases == 'NONE' or filters == 'NONE' or days_to_deadline == 'NONE':
  580. 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>'
  581. else:
  582. try:
  583. new_room = api.create_public_room(room_name,
  584. members=[latest_message_user_username],
  585. read_only=False)
  586. new_room_id = new_room['channel']['_id']
  587. room_file = open('rooms/' + new_room_id + '.txt', 'w')
  588. room_file.write( room_name + '§%§%' + databases + '§%§%' + filters + '§%§%' + days_to_deadline)
  589. room_file.close()
  590. answer = 'Der Command wurde übermittelt'
  591. except Exception as e:
  592. print('it was not able to create the room, the original error message is:', e)
  593. answer = 'There was an error creating the room, look up the logs.. the original error was: ' + str(e)
  594. #print('oi', user_input)
  595. api.send_message('Die Anfrage wird bearbeitet..', room_id)
  596. # here comes the code interacting with the spiders output json
  597. #answer = 'the up to date entries are: oi Oi Oi!'
  598. api.send_message(answer, room_id)
  599. time.sleep(1)
  600. api.send_message('Ich bin wieder bereit für Konfigurationsinput : )', room_id)
  601. time.sleep(1)