Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. htllMakeAuthReq() {
  5. #Load the cookie and make the request to the first arg past to this function
  6. req=$(curl -s -b $cookieFile $1)
  7.  
  8. }
  9.  
  10. htllLogin() {
  11. username='username'
  12. password='pasword'
  13. cookieFile='htll-cookie.txt'
  14. loginUrl="https://hightechlowlife.eu/board/login/login"
  15.  
  16. #Login and get cookie silently
  17. loginReq=$(curl -s -c $cookieFile -d "login=$username&password=$password" $loginUrl)
  18.  
  19. }
  20.  
  21. getMessages() {
  22. #locating messages
  23. message=$(echo -e "$req" | grep "siropuChatMessage\">.*</span" | grep -ioP '">.*</span>')
  24.  
  25. #Remove some of the info messages
  26. message=$(echo -e "$message" | grep -v "</a> is our newest member. Welcome!</span>")
  27.  
  28. #Remove more of the info messages
  29. message=$(echo -e "$message" | grep -v "</a> has started a new thread called &quot;<a href=")
  30.  
  31. #Stepping to the message
  32. message=$(echo -e "$message" | cut -d">" -f2- | sed -E 's/<span .*?">//')
  33.  
  34. #Get rid of span tags
  35. message=$(echo -e "$message" | sed 's/<\/span>//g' | sed s'/<span>//g')
  36.  
  37. #Convert html apostraphe
  38. message=$(echo -e "$message" | sed "s/&#039;/'/g")
  39.  
  40. #Convert html qoute
  41. message=$(echo -e "$message" | sed 's/&quot;/"/g')
  42.  
  43. #Remove html around links
  44. message=$(echo -e "$message" | sed -E 's/<a href=.*?">//' | sed -E 's/<\/a>//')
  45.  
  46. #Convert html greater than sign
  47. message=$(echo -e "$message" | sed 's/&gt;/>/g')
  48. }
  49.  
  50. getUsernames() {
  51. usernames=$(echo -e "$req" | grep -v "siropuChatBot" | grep -ioP "data-author=\".*?\">" | cut -d'"' -f2)
  52. }
  53.  
  54. getShouty() {
  55. #Get current shoutbox
  56. htllMakeAuthReq $shout
  57.  
  58. #parse for messages
  59. getMessages
  60.  
  61. #parse for usernames
  62. getUsernames
  63.  
  64.  
  65. IFS=$'\n'
  66. line=1
  67.  
  68. #print shouty
  69. for i in $(echo -e "$message"); do
  70. currentUser=$(echo -e "$usernames" | sed "$line"'!d')
  71. echo "$currentUser: $i"
  72. ((line++))
  73. done
  74. }
  75.  
  76. #Login
  77. htllLogin
  78.  
  79. #Get shouty
  80. shout="https://hightechlowlife.eu/board/chat/"
  81.  
  82.  
  83.  
  84. while :; do
  85.  
  86. latestShouty=$(getShouty)
  87.  
  88. if [ -z "$oldShouty" ]; then
  89. echo -e "$latestShouty"
  90. fi
  91.  
  92. if [ "$latestShouty" != "$oldShouty" ]; then
  93. if [ -n "$oldShouty" ]; then
  94. lastLineOfOldShouty=$(echo -e "$oldShouty" | tail -1)
  95.  
  96. locationOfLastLineinNewShouty=$(echo -e "$latestShouty" | grep -n "$lastLineOfOldShouty" | cut -f1 -d:)
  97. newShouts=$(echo -e "$latestShouty" | sed '1,'"$locationOfLastLineinNewShouty"'d')
  98. echo -e "$newShouts"
  99. fi
  100. fi
  101. sleep 2
  102. oldShouty="$latestShouty"
  103. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement