Recoding My RSS Twitter Bot
My last blog post about my RSS Twitter Bot made realize a lot of flaws with my bot, not only in the code I wrote but the choices I made about what to code. This led me to re-code the entire bot, but I think the code is much cleaner now.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
I Switched to the RSS Module
During and after writing the first post about my Twitter Bot I did more research into the Ruby RSS Module and found that it has .feed_type
method that allows you to easily sort the types of feeds so you can use the correct methods to parse them. Sorting the feeds this way is infinitely better than the weird/incorrect way I was doing it before albeit it was good practice with hashes.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
I Finally Used a Proc in my Code
I remember learning about Procs and Lamdas on Codecademy and thinking they were pretty cool…ok really cool. Since that time I haven’t used them in my code, accept when trying to code FizzBuzz in as many different ways as possible, which sort of makes sense since everything I’m doing is super simple, but still…I want to use a some damn Procs.
Finally, I found a reason. When re-coding my bot I decided there was no reason to try and adjust the length of the feed titles because eventually my bot will hopefully use a URL shortener, meaning 99.99% of the time the titles will never make the tweet go over 140 characters. Still I needed an easy way to keep @tweets
that are over 140 characters from being sent to the .tweeter
method and causing an error. Obviously, I could stick an if/else statement in a method and call it from the <.rss> and <.atom> methods, but using a Proc sounded way more fun :).
1 2 3 4 5 6 7 8 9 |
|
Next Steps
- Check for new articles, videos, etc. in the feeds and only tweet the new ones
- Learn Sinatra and turn this into a Sinatra App
- Add a url shortner like bit.ly or roll my own