ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm working on some scripts to run a TwitterBot that will ultimately do several different tasks (download files, store data, tweet various bits of info) based on what tweet is sent to it.
At the moment, I'm using the following to get the tweets.
This gives me a huge file though as it gets a lot of tweets. What I'd like to do is chunk this out by tweet and only do the last three tweets. The file length seems to be pretty regular so I should be able to do this by line. IE Lines 1-20 > Tweet1.txt Lines 21-40 >tweet2.txt .
Alternately, if someone knows of a better way to pull down only the last three tweets from twitter (even better, only new tweets) I'm open to suggestions on that too.
Alternately, if someone knows of a better way to pull down only the last three tweets from twitter (even better, only new tweets) I'm open to suggestions on that too.
I would start by looking at Twitter's API. There seem to be pre-rolled libraries available for many languages, so you should be able to find something to your liking.
is just the file header and not part of the tweet.
For what it's worth, the ultimate goal will be to read out information in these tweets, most notably the sections inside <text> (to choose actions) <created_at> (to tell if it's new) and <screen_name> (so it'll only respond to me)
is just the file header and not part of the tweet.
For what it's worth, the ultimate goal will be to read out information in these tweets, most notably the sections inside <text> (to choose actions) <created_at> (to tell if it's new) and <screen_name> (so it'll only respond to me)
Well, either, as already suggested by Telemachos use the API, or write a script in Perl.
Ok, using the above example and some information I found online, I've adapted the code some.
awk 'BEGIN{
RS=""
FS="n" }{
}END{
# first tweet id and text
print $8
print $9
#second tweet id and text
print $100
print $101
#third tweet id and text
print $192
print $193
}' /home/josh/scripts/recent.txt
This works... sort of... I picked out which lines I needed and when the recent.txt file contained only tweets made by the bot, things worked out, when I sent an @reply to it, the lines shifted and things didn't work. Based on the old code, I'm wondering how to simply output the lines based on tags. IE <id> and <text> Just one example will work since Is hould be able to pad in the rest.
Basically at this point, this is ooking like a good way to simply bypass outputting the tweets to another file andjust pull the info I want from the raw file.
Also I'm wonder what the command is so put the printed information into a spring variable. I tried echo and > and a few variations related to that but got nothing but errors.
Ok, using the above example and some information I found online, I've adapted the code some.
awk 'BEGIN{
RS=""
FS="n" }{
}END{
# first tweet id and text
print $8
print $9
#second tweet id and text
print $100
print $101
#third tweet id and text
print $192
print $193
}' /home/josh/scripts/recent.txt
This works... sort of... I picked out which lines I needed and when the recent.txt file contained only tweets made by the bot, things worked out, when I sent an @reply to it, the lines shifted and things didn't work. Based on the old code, I'm wondering how to simply output the lines based on tags. IE <id> and <text> Just one example will work since Is hould be able to pad in the rest.
Basically at this point, this is ooking like a good way to simply bypass outputting the tweets to another file andjust pull the info I want from the raw file.
Also I'm wonder what the command is so put the printed information into a spring variable. I tried echo and > and a few variations related to that but got nothing but errors.
1) extract the whole tweet;
2) extract the tagged portion from it.
I am not sure what you mean in "bypass outputting the tweets to another file", but 'curl' can output to STDOUT and, say, Perl can read from STDIN, as well as other scripting languages.
Hey all, thanks for the help. I have recently discovered ttytter which looks to do what I want in a much much more elegant fashion than I ever could manage. I can easily output the recent tweets to a file for processing by the system.
This leads to more questions on how to do a few things but that is likely a better topic for another thread.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.