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.

803 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 str(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. print(room_id_add_tags)
  269. except:
  270. room_id_add_tags = 'NONE'
  271. try:
  272. new_tags = user_input_list[2]
  273. except:
  274. new_tags = 'NONE'
  275. try:
  276. thirdarg = user_input_list[3]
  277. except:
  278. thirdarg = 'NONE'
  279. if room_id_add_tags != 'NONE' and len(new_tags) >= 1 and thirdarg == 'NONE':
  280. try:
  281. room_file_add_tags = open('rooms/' + room_id_add_tags + '.txt', 'r')
  282. room_info_raw = room_file_add_tags.read()
  283. room_file_add_tags.close()
  284. room_info = room_info_raw.split('§%§%')
  285. tag_list = eval(room_info[-2])
  286. for tag in eval(user_input_list[2]):
  287. if tag not in tag_list:
  288. tag_list.append(tag)
  289. room_file_add_tags = open('rooms/' + room_id_add_tags + '.txt', 'w')
  290. room_file_add_tags.write( str(room_info[0]) + '§%§%' + str(room_info[1]) + '§%§%' + str(tag_list) + '§%§%' + str(room_info[-1]))
  291. room_file_add_tags.close()
  292. answer = 'the updated tag list is' + str(tag_list)
  293. except Exception as e:
  294. print('error opening, original error is:', e)
  295. answer = "The room_id to update the tags was not found"
  296. if user_input_list[0] == 'printtags':
  297. try:
  298. room_name_add_tags = user_input_list[1]
  299. room_id_to_print_tags = name2id(room_name_add_tags)
  300. except:
  301. answer = "after the command printtags, the second argument has to be the room name.. use printrooms and look up the id of the room you want to print the tags"
  302. room_id_to_print_tags = 'NONE'
  303. if room_id_to_print_tags != 'NONE':
  304. try:
  305. room_file = open('rooms/' + room_id_to_print_tags + '.txt', 'r')
  306. room_info_raw = room_file.read()
  307. room_file.close()
  308. room_info = room_info_raw.split('§%§%')
  309. tag_list = eval(room_info[-1])
  310. answer = tag_list
  311. except Exception as e:
  312. print('error opening, original error is:', e)
  313. answer = "The room_id to get the tags was not found"
  314. if user_input_list[0] == 'printcommands':
  315. answer = """
  316. To print all available rooms and their configuration, use
  317. command : `printrooms`
  318. -----------------------------------------------------------------------------------------
  319. To print all available fdbs, use
  320. command : `printfdbs`
  321. -----------------------------------------------------------------------------------------
  322. To update all rooms use
  323. command : `updaterooms all`
  324. -----------------------------------------------------------------------------------------
  325. To update one room use the room_id from the output of printrooms:
  326. command : `updaterooms <room-id>`
  327. example : `updaterooms 6572012bebb39dd248d08320`
  328. -----------------------------------------------------------------------------------------
  329. To create a room use following command, but be sure to **not have spaces** in your lists,
  330. as a space indicates a new command argument:
  331. command : `createroom <room-name> <list-fdbs> <list-tags> <days-to-deadline>`
  332. example : `createroom room-test-1 ['giz','fdb2'] ['tag1','tag2','tag3'] 7`
  333. -----------------------------------------------------------------------------------------
  334. To delete a room use
  335. command : `deleteroom <room-id>`
  336. example : `deleteroom 6572012bebb39dd248d08320`
  337. -----------------------------------------------------------------------------------------
  338. To print the tags of a room use
  339. command : `printtags <room-name>`
  340. example : `printtags test42`
  341. -----------------------------------------------------------------------------------------
  342. To add tags to the existing tags use
  343. command : `addtags <room-name> <tag-list-without-spaces>`
  344. example : `addtags test42 ['tag1','tag2','tag3']`
  345. """
  346. if user_input_list[0] == 'printrooms':
  347. room_was_found = False
  348. # get all the rooms
  349. import os
  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. room_list_string = ''
  359. for room in room_list:
  360. room_list_string += str(room) + '\n' + '------------------------------------------------------------------------------' + '\n'
  361. #print(room_list)
  362. answer = room_list_string
  363. if user_input_list[0] == 'updaterooms':
  364. try:
  365. if len(user_input_list[1]) >= 1:
  366. room_name_to_update = user_input_list[1]
  367. room_to_update = name2id(room_name_to_update)
  368. #room_to_update = user_input_list[1]
  369. except Exception as e:
  370. room_to_update = 'NONE'
  371. room_list = []
  372. rooms = os.listdir('rooms')
  373. for room in rooms:
  374. room_file = open('rooms/' + room, 'r')
  375. room_file_raw = room_file.read()
  376. room_file.close()
  377. room_file_list = room_file_raw.split('§%§%')
  378. room_list.append([room[:-4], room_file_list[0], room_file_list[1], room_file_list[2], room_file_list[3]])
  379. with open(spider_directory + '/spiders/config.yaml' , "r") as stream:
  380. try:
  381. config = yaml.safe_load(stream)
  382. except yaml.YAMLError as exc:
  383. print(exc)
  384. fdb_list = []
  385. #print(config)
  386. for key in config:
  387. fdb_list.append(key)
  388. answer = "Ich update die Rooms auf Basis der Daten von heute morgen um 6 Uhr.."
  389. data = dict({})
  390. for room in room_list:
  391. if room[0] == room_to_update or room_to_update == 'all':
  392. room_was_found = True
  393. print(room[0])
  394. room_fdbs = room[2]
  395. room_tags = room[3]
  396. room_deadline_days = room[4]
  397. # not running get_rooms because disfunctional
  398. #subprocess.run(["python", spider_directory + 'main.py', fdbs])
  399. #myinfo = api.get_room_info(room[0])
  400. #print(myinfo)
  401. #roomid = "'657cbeccebb39dd248d38ec3'"
  402. #roomoioioi = api.get_user_info(bot_user_id)
  403. #print(roomoioioi)
  404. #room_history_updateroom = api.get_private_room_history(room[0])
  405. # reading from txt state history instead
  406. try:
  407. room_history_file = open('roomhistories/' + room[0] + '.txt', 'x')
  408. room_history_file.close()
  409. except:
  410. print('reading from roomhistory which is already there')
  411. room_history_list = []
  412. with open('roomhistories/' + room[0] + '.txt') as room_history_file:
  413. lines = room_history_file.readlines()
  414. for line in lines:
  415. room_history_list.append(line)
  416. #
  417. #for message in room_history_raw:
  418. # print(message)
  419. for room_fdb in eval(room_fdbs):
  420. #print('room_fdb',room_fdb, 'fdb_list',fdb_list)
  421. try:
  422. iteration_var_list = config.get(room_fdb).get("entry-list").get("iteration-var-list")
  423. except Exception as e:
  424. print('there was an error with the entry-list parameter in the config regarding the fdb ', room_fdb)
  425. if room_fdb in fdb_list and room_fdb not in [key for key in data]:
  426. iterdict = {}
  427. for i in eval(iteration_var_list):
  428. f = open(spider_directory + "/spiders/output/" + room_fdb + str(i) + "entryList.txt")
  429. text = f.read()
  430. dictionary_entry_list = eval(text)
  431. iterdict[i] = dictionary_entry_list
  432. data[room_fdb] = iterdict
  433. for i in eval(iteration_var_list):
  434. try:
  435. print(room_fdb, i)
  436. print('oioioioioiOIOIOI')
  437. for key in data[room_fdb][i]:
  438. contains_tag = False
  439. try:
  440. period_data_formatted = dateutil.parser.parse(data[room_fdb][i][key]["period"])
  441. except Exception as e:
  442. period_data_formatted = 'NONE'
  443. print('getting the period did not work for', room_fdb, i, key, ' ori err is:', e)
  444. name_data_lower = [word.lower() for word in data[room_fdb][i][key]["name"].split(' ')]
  445. info_data_lower = [word.lower() for word in data[room_fdb][i][key]["info"].split(' ')]
  446. text_data_lower = [word.lower() for word in data[room_fdb][i][key]["text"].split(' ')]
  447. print('got until ONE')
  448. tag_list = []
  449. for tag in eval(room_tags):
  450. print('got until TWO')
  451. if '_' in tag:
  452. ntags = tag.split('_')
  453. ntags_length = len(ntags)
  454. print(ntags)
  455. ntag_count = 0
  456. for ntag in ntags:
  457. print('searching for ntag: ', ntag)
  458. for nword in name_data_lower:
  459. if ntag.lower() in nword:
  460. if nword != '':
  461. ntag_count += 1
  462. print(ntag, ' ntag was found')
  463. break
  464. print('ntag count is ', ntag_count, 'ntag_length is ', ntags_length)
  465. if ntag_count == ntags_length:
  466. contains_tag = True
  467. tag_list.append('_'.join(ntags) + ' in name')
  468. ntag_count = 0
  469. for ntag in ntags:
  470. for iword in info_data_lower:
  471. if ntag.lower() in iword:
  472. if iword != '':
  473. ntag_count += 1
  474. break
  475. if ntag_count == ntags_length:
  476. contains_tag = True
  477. tag_list.append('_'.join(ntags) + ' in info')
  478. ntag_count = 0
  479. for ntag in ntags:
  480. for tword in text_data_lower:
  481. if ntag.lower() in tword:
  482. if tword != '':
  483. ntag_count += 1
  484. break
  485. if ntag_count == ntags_length:
  486. contains_tag = True
  487. tag_list.append('_'.join(ntags) + ' in text')
  488. else:
  489. #print('------------------')
  490. print(name_data_lower, info_data_lower, text_data_lower, room[0], room_tags)
  491. nword_contains_tag = False
  492. for nword in name_data_lower:
  493. print(tag.lower(), nword)
  494. if tag.lower() in nword:
  495. print('goooot heeeere')
  496. print(nword)
  497. if nword != '':
  498. print('goot behind nword check')
  499. nword_contains_tag = True
  500. if nword_contains_tag == True:
  501. contains_tag = True
  502. tag_list.append(tag + ' in name')
  503. iword_contains_tag = False
  504. for iword in info_data_lower:
  505. if tag.lower() in iword:
  506. if iword != '':
  507. iword_contains_tag = True
  508. print('oioiOIOIOIoioioiOIOIword', iword)
  509. if iword_contains_tag == True:
  510. contains_tag = True
  511. tag_list.append(tag + ' in info')
  512. tword_contains_tag = False
  513. for tword in text_data_lower:
  514. if tag.lower() in tword:
  515. if tword != '':
  516. tword_contains_tag = True
  517. if tword_contains_tag == True:
  518. contains_tag = True
  519. tag_list.append(tag + ' in text')
  520. print('got until THREE')
  521. if contains_tag == True:
  522. #print('------------------')
  523. #print(name_data_lower, info_data_lower, text_data_lower)
  524. try:
  525. url = data[room_fdb][i][key]["domain"]
  526. except:
  527. url = data[room_fdb][i][key]["link"]
  528. print('101110001101010010010101000111')
  529. 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)
  530. entry_message_identifier = '<' + url + '|' + data[room_fdb][i][key]["name"]+ '>'
  531. message_was_already_there = False
  532. for message in room_history_list:
  533. print('message', message[:-1], 'identifier', entry_message_identifier)
  534. if url in message[:-1] or data[room_fdb][i][key]["name"] in message:
  535. message_was_already_there = True
  536. now = datetime.datetime.now()
  537. now_formatted = dateutil.parser.parse(str(now))
  538. try:
  539. delta = period_data_formatted - now_formatted
  540. days_to_check = delta.days
  541. except Exception as e:
  542. days_to_check = int(room_deadline_days) - 1
  543. print('calc of delta did now work, original error is:', e)
  544. #print('delta', delta, int(delta.days))
  545. if message_was_already_there == False and int(days_to_check) > int(room_deadline_days):
  546. api.send_message(entry_message, room[0])
  547. try:
  548. room_file = open('roomhistories/' + room[0] + '.txt', 'x')
  549. room_file.close()
  550. except:
  551. print('appending to roomhistory')
  552. room_file = open('roomhistories/' + room[0] + '.txt', 'a')
  553. room_file.write(entry_message_identifier + '\n')
  554. room_file.close()
  555. except Exception as e:
  556. print("probably i was not there in last page, original error is:", e)
  557. if room_to_update == 'all':
  558. answer = 'I am updating all rooms based on the data in fdb-spider/spiders/output..'
  559. if room_was_found == False or room_to_update == 'NONE':
  560. answer = 'The room you specified does not exist, or there are no rooms configured, try printcommands or contact the administrator'
  561. if room_was_found == True and room_to_update != 'NONE':
  562. answer = "I am updating the specified room based on the data in fdb-spider/spiders/output.."
  563. if user_input_list[0] == 'printfdbs':
  564. answer = str(fdb_list)
  565. if len(user_input_list) > 1:
  566. answer = 'Die Syntax zum Ausgeben der konfigurierten Förderdatenbanken hat einen Fehler. Versuche es erneut, mit -> printfdbs'
  567. if user_input_list[0] == 'deleteroom':
  568. try:
  569. room_id_del = user_input_list[1]
  570. except Exception as e:
  571. room_id_del = 'NONE'
  572. print(e)
  573. os.remove("rooms/" + room_id_del + ".txt")
  574. anwer = 'deleting the requested room..'
  575. if len(user_input_list) > 2:
  576. answer = 'Die Syntax zum Löschen eines Raumes hat einen Fehler. Versuche es erneut, nach dem Muster -> deleteroom <room_id>'
  577. if user_input_list[0] == 'createroom':
  578. try:
  579. room_name = user_input_list[1]
  580. except Exception as e:
  581. room_name = 'NONE'
  582. print(e)
  583. try:
  584. databases = user_input_list[2]
  585. except Exception as e:
  586. databases = 'NONE'
  587. print(e)
  588. try:
  589. filters = user_input_list[3]
  590. except Exception as e:
  591. filters = 'NONE'
  592. print(e)
  593. try:
  594. days_to_deadline = user_input_list[4]
  595. except Exception as e:
  596. days_to_deadline = 'NONE'
  597. print(e)
  598. if len(user_input_list) > 4:
  599. 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"]'
  600. if room_name == 'NONE' or databases == 'NONE' or filters == 'NONE' or days_to_deadline == 'NONE':
  601. 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>'
  602. else:
  603. try:
  604. new_room = api.create_public_room(room_name,
  605. members=[latest_message_user_username],
  606. read_only=False)
  607. new_room_id = new_room['channel']['_id']
  608. room_file = open('rooms/' + new_room_id + '.txt', 'w')
  609. room_file.write( room_name + '§%§%' + databases + '§%§%' + filters + '§%§%' + days_to_deadline)
  610. room_file.close()
  611. answer = 'Der Command wurde übermittelt'
  612. except Exception as e:
  613. print('it was not able to create the room, the original error message is:', e)
  614. answer = 'There was an error creating the room, look up the logs.. the original error was: ' + str(e)
  615. #print('oi', user_input)
  616. api.send_message('Die Anfrage wird bearbeitet..', room_id)
  617. # here comes the code interacting with the spiders output json
  618. #answer = 'the up to date entries are: oi Oi Oi!'
  619. api.send_message(answer, room_id)
  620. time.sleep(1)
  621. api.send_message('Ich bin wieder bereit für Konfigurationsinput : )', room_id)
  622. time.sleep(1)