Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. knex = require 'knex'
  2. knex = knex
  3. client: 'pg'
  4. connection:
  5. host: '127.0.0.1'
  6. user: 'testuser'
  7. password: 'test'
  8. database: 'tag_task'
  9. _ = require 'lodash'
  10.  
  11.  
  12. bookshelf = require('bookshelf') knex
  13.  
  14. Patient = bookshelf.Model.extend tableName: 'patients'
  15.  
  16. delete_closing_tag = (text) ->
  17. return_text = ""
  18. add = true
  19. for index in [0..text.length-1]
  20. add = false if index-1 < text.length && text[index] == '<' && text[index+1] == '/'
  21. return_text += text[index] if add
  22. add = true if !add && text[index] == '>'
  23. return_text
  24.  
  25. delete_closing_tag_lodash = (text) ->
  26. text = text.split ''
  27. i = _.indexOf(text, "/")-1
  28. j = _.indexOf(text, ">", i)+1
  29. while i > 0
  30. _.fill text, '', i, j
  31. i = _.indexOf(text, "/")-1
  32. j = _.indexOf(text, ">", i)+1
  33. text.join ''
  34.  
  35. Patient.forge().fetchAll()
  36. .then (patients) ->
  37. console.log typeof patients.models
  38. for elem in patients.models
  39. conversation = elem.get("conversation")
  40. for topic_key, topic_value of conversation.topics
  41. if topic_value.deleted != true && topic_value.name?
  42. topic_value.name = delete_closing_tag topic_value.name
  43.  
  44. for question_key, question_value of conversation.questions
  45. if question_value.deleted != true && question_value.phrase?
  46. question_value.phrase = delete_closing_tag question_value.phrase
  47.  
  48. for category_key, category_value of conversation.categories
  49. if category_value.deleted != true
  50. if category_value.name?
  51. category_value.name = delete_closing_tag category_value.name
  52. console.log category_value.name
  53. if category_value.response?
  54. category_value.response = delete_closing_tag category_value.response
  55. elem.set "conversation", conversation
  56. elem.save()
  57. .catch (error) ->
  58. console.log error
  59. .finally ->
  60. knex.destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement