Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tweets
#1
I need to monitor tweets from several users.

So I'd like to grab all of the users' rss feeds and then sort the data by time of post.

Here is what I whipped up to grab all the data:
Code:
Copy      Help
str s=
;'NT_NewsEditor','NT_SportsEditor','NT_SpringValley','NT_Court','NT_County','NT_LifeEditor','NT_Business','NT_Peru','NT_Editor','NT_LaSalle','NT_Online','NT_PhotoEditor','NT_Photo','NT_Mendota','NT_Princeton','NT_PutnamCounty']
s.findreplace("'")
s.findreplace("," "[]")
s.findreplace("[")
s.findreplace("]")
for _i 0 numlines(s)
,_s.getl(s _i)
,_s-"http://twitter.com/"
,IntGetFile _s str'Twitter
,for int'i 0 numlines(Twitter)
,,str Line.getl(Twitter i)
,,
,,if(matchw(Line "*href=''http://twitter.com/statuses/user_timeline*.rss*"))
,,,str Title=Line
,,,str mSearch="title=''"
,,,int Mark=find(Title mSearch 0 1)
,,,Title.remove(0 Mark+mSearch.len)
,,,Mark=find(Title "'' type=''")
,,,Title.remove(Mark)
,,,
,,,Line.findreplace("    <link rel=''alternate'' href=''")
,,,int RSS=find(Line ".rss")
,,,Line.remove(RSS+4)
,,,IntGetFile Line str'rss
,,,;mes rss
,,,mkdir "$desktop$\twitter\"
,,,rss.setfile(F"$desktop$\twitter\{Title}.txt")

I'm thinking that changing all of the dates to a int (i.e. "Fri, 14 May 2010 23:11:26 +0000" = 201005231126)
Then putting all of the data into a CSV variable and then sort by the time stamp.

Thanks,
Jimmy Vig
#2
To convert such date string to number, at first need to make standard format "mm/dd/yyyy hh:mmConfuseds", then assign to a DATE variable.
#3
Function cTwitterDate
Code:
Copy      Help
function str&TwitterDate
ARRAY(str) a
int i=findrx(TwitterDate "(\w{3}), (\d{2}) (\w{3}) (\d{4}) (\d{2}:\d{2}:\d{2})" 0 0 a)
str sDate=F"{a[3]}-{a[2]}-{a[4]} {a[5]}"
DATE dDate=sDate
sDate.timeformat("{yyyy}{MM}{dd}{HH}{mm}{ss}" dDate)

TwitterDate=sDate

Function TwitterParse
Code:
Copy      Help
function str&Data

IXml x=CreateXml
x.FromString(Data)
Data=""
ARRAY(IXmlNode) a
x.Path("rss/channel/item" a)
int i
for i 0 a.len
,IXmlNode n=a[i].FirstChild
,for _i 0 6
,,if(!n) break
,,sel _i
,,,case 2
,,,str TimeStamp=n.Value
,,,cTwitterDate TimeStamp
,,,case 0
,,,str Title=n.Value
,,,Title.findreplace("[]" " ")
,,n=n.Next
,str Tweet=F"({TimeStamp}) {Title}"
,Data.addline(Tweet)

Yep. Pretty Much from here it's pretty simple. I ended up just putting the date at that start of a string and then populated an array. Used sort(1). Got exactly what I wanted.


Forum Jump:


Users browsing this thread: 1 Guest(s)