LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-09-2012, 04:11 AM   #1
trox
Member
 
Registered: Jan 2006
Distribution: Linux Mint 12, FreeBSD, Ubuntu 12.10, Mac OS X
Posts: 83

Rep: Reputation: 15
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
 
Old 01-09-2012, 04:25 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 189Reputation: 189
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....
 
Old 01-09-2012, 04:55 AM   #3
trox
Member
 
Registered: Jan 2006
Distribution: Linux Mint 12, FreeBSD, Ubuntu 12.10, Mac OS X
Posts: 83

Original Poster
Rep: Reputation: 15
Smile twitter and twidge

Quote:
Originally Posted by fukawi1 View Post
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!
 
Old 01-09-2012, 05:02 AM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 189Reputation: 189
Out of curiosity, what is complicated about that solution?
 
Old 01-10-2012, 12:04 AM   #5
trox
Member
 
Registered: Jan 2006
Distribution: Linux Mint 12, FreeBSD, Ubuntu 12.10, Mac OS X
Posts: 83

Original Poster
Rep: Reputation: 15
Smile 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
 
Old 01-10-2012, 12:48 AM   #6
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 189Reputation: 189
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...
 
Old 01-10-2012, 02:07 AM   #7
trox
Member
 
Registered: Jan 2006
Distribution: Linux Mint 12, FreeBSD, Ubuntu 12.10, Mac OS X
Posts: 83

Original Poster
Rep: Reputation: 15
Smile 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
 
Old 01-10-2012, 03:00 AM   #8
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

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


Reply

Tags
command line, cron, cronjob, cronjobs


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Twidge: twitter from the CLI / command line / shell LXer Syndicated Linux News 0 08-03-2011 04:40 AM
LXer: Twidge Twitter Client is for Those Who Terminal-ly Hate GUI LXer Syndicated Linux News 0 05-09-2010 02:12 AM
Cronjob..... milindpk Linux - Newbie 6 05-06-2010 06:52 PM
LXer: Twidge Command Line Twitter Client for Ubuntu/Linux Desktop is Cool LXer Syndicated Linux News 0 10-21-2009 07:50 AM
LXer: Tweet from the Command Line with Twidge LXer Syndicated Linux News 0 01-07-2009 07:00 PM


All times are GMT -5. The time now is 04:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration