LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   twidge and cronjob (http://www.linuxquestions.org/questions/linux-general-1/twidge-and-cronjob-922833/)

trox 01-09-2012 04:11 AM

twidge and cronjob
 
Hi Everyone and Happy New Year!

I have poured through goolge for hours on this topic. I feel there has to be a way to do this. I want to schedule a cronjob with twidge at a specific time to post a tweet from a text file. Here is the catch though. Instead of making multiple text files with individual tweets, I would like to have twidge randomly select a tweet from the text file for the specified time.

In example, Say I wanted to say "Good Morning America" in random ways from a text file like: I hope you have a [great, lovely, spectacular, dynamic, etc] day! Wherein, twidge is randomly selecting words from the brackets inside the text file. Couldn't I also put individual tweets in []'s as well? Is there a way to do this? Remember I only want to use the command line to schedule this event to happen everyday at a specified time.

Thank you,

trox

fukawi1 01-09-2012 04:25 AM

I am not familiar with twidge.

But the quickest solution (i can think of that is) would be:
Two files
The first file being a list of greetings, the second being the remainder of the message"

Code:

~/tmp $ cat tmp1
Good morning! Hope you have a xxx day!
Greetings! I sincerely hope you have a xxx day!
Thanks for reading my tweet have a xxx day!
~/tmp $ cat tmp2
good
great
wonderful
fantastic
~/tmp $ shuf -n 1 tmp1 | sed "s/xxx/$(shuf -n 1 tmp2)/"
Good morning! Hope you have a good day!
~/tmp $ shuf -n 1 tmp1 | sed "s/xxx/$(shuf -n 1 tmp2)/"
Thanks for reading my tweet have a fantastic day!
~/tmp $

You would have to figure out how to make that work with twidge....

trox 01-09-2012 04:55 AM

twitter and twidge
 
Quote:

Originally Posted by fukawi1 (Post 4570013)
I am not familiar with twidge.

But the quickest solution (i can think of that is) would be:
Two files
The first file being a list of greetings, the second being the remainder of the message"

Code:

~/tmp $ cat tmp1
Good morning! Hope you have a xxx day!
Greetings! I sincerely hope you have a xxx day!
Thanks for reading my tweet have a xxx day!
~/tmp $ cat tmp2
good
great
wonderful
fantastic
~/tmp $ shuf -n 1 tmp1 | sed "s/xxx/$(shuf -n 1 tmp2)/"
Good morning! Hope you have a good day!
~/tmp $ shuf -n 1 tmp1 | sed "s/xxx/$(shuf -n 1 tmp2)/"
Thanks for reading my tweet have a fantastic day!
~/tmp $

You would have to figure out how to make that work with twidge....


Ya, I'll definitely have to research this one more for sure. I know there has to be a less complicated way.

Thanks so much for your reply!

fukawi1 01-09-2012 05:02 AM

Out of curiosity, what is complicated about that solution?

trox 01-10-2012 12:04 AM

twidge and twitter
 
Hi fukawi1,

Thanks for your help. I just feel that something with a bash script would be easier. I understand it that way more. Where I'm telling the system to initiate a command with a set of instructions everyday at a certain time from a script, but making twidge (the program) choose from options I have preselected within the script. It is with humility that I tell you I would need further instruction on how to use what you have shared. If you have the patience, I am willing to go your route. It would be a great learning experience for me. How do you feel about it?


Thank you

fukawi1 01-10-2012 12:48 AM

I'm not sure what you mean by "preselected within a script".
But the example I gave could be applied to variables or arrays in a script.

The basic rundown on my example is this:
Code:

shuf -n 1 tmp1 |
shuf will take a random line from the file tmp1 (you would most likely rename this to say "posts"), which contains the main body's of the twitter posts, with the word you want to replace, marked with xxx. The "|" will take the output from the command to the left, and send it to the input of the command to the right.

Code:

sed "s/xxx/$(shuf -n 1 tmp2)/"
- sed will replace "xxx" within the output of the first shuf command, with a random line from the file tmp2 (lets say greetings, good, great, fantastic, etc).

I apologise if this appears insulting.

You could easily replace the files tmp1 and tmp2 as they occur in that command, with variables, such as

Code:

shuf -n 1 $message | sed "s/xxx/$(shuf -n 1 $greeting)/"
which could be passed as commandline arguments, or edited in the script itself.

I had a quick look at the man page online for twidge, and from what i can work out, once the config file is set up with your username/password etc, it would be a matter of
Code:

#!/bin/bash
message="~/message_body"  # or whichever file you choose
greeting="~/greetings" # or whichever file you choose
tweet=$(shuf -n 1 $message | sed "s/xxx/$(shuf -n 1 $greeting)
twidge update $tweet

You could elaborate on that, by finding the day of the week, and reading from a particular file of greetings on a certain day, etc.

I get the feeling this hasn't helped much though...

trox 01-10-2012 02:07 AM

twidge and tweeter
 
Hi again fukawi1,

What programming language are you using? That might help me understand your fix for this. What you have shared somewhat makes sense from my experience with even the php and html languages. You just took it up to more of a sensible programming language perspective as it applies to machines. I can see the strength of knowing that. Sometimes bash scripting just isn't enough. This is probably one of those times. When it comes to Linux, I can admit that I really need to sharpen my language programming skills and be able to get more intricate when it's needed. This is encouraging and I will try it later this week when I'm off and let you know what happens. Our dialogue reminds me of just why I liked the Linux community so much to begin with!

Thank you

fukawi1 01-10-2012 03:00 AM

Its a bash script.
But for all intents and purposes those commands could be run directly from the command line.


All times are GMT -5. The time now is 02:13 PM.