Skip to content

Commit

Permalink
Include time in the generated open notebook entries
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Feb 7, 2013
1 parent 079b451 commit 3871ee2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions rascal/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all:

gen:
wget --no-check-certificate https://api.twitter.com/1/statuses/user_timeline/grammarware.json?count=3200 > grammarware.json
rsc TwiSKO.rsc

10 changes: 9 additions & 1 deletion rascal/src/TwiSKO.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ import IO; // println
import String; //startsWith, endsWith
import List; //size, reverse

public void main(list[str] as)
{
go();
}

public void go()
{
loc w = |home:///workspace/open/data/last1000.json|;
loc r = |home:///workspace/open/data/last1000.xml|;
w = |cwd:///grammarware.json|;
r = |cwd:///grammarware.xml|;
//loc w = |home:///workspace/open/data/one.json|;
list[JSO] tweets = gimmeArray(loc2jso(w));
list[str] res = reverse([s | str s <- [processTweet(gimmeMap(tweet)) | JSO tweet <- tweets], s!=""]);
Expand All @@ -29,7 +36,7 @@ str processTweet(map[str,JSO] t)
return "";
return "
'\<entry\>
' \<ts d=\"<t2day(t)>\" m=\"<t2month(t)>\" y=\"<t2year(t)>\"/\>
' \<ts d=\"<t2day(t)>\" m=\"<t2month(t)>\" y=\"<t2year(t)>\" time=\"<t2time(t)>\"/\>
' \<text\><txt>\</text\>
' \<twi\><t2id(t)>\</twi\>
'\</entry\>";
Expand All @@ -38,5 +45,6 @@ str processTweet(map[str,JSO] t)
str t2day(map[str,JSO] t) = gimmeDay(gimmeString(t["created_at"]));
str t2month(map[str,JSO] t) = gimmeMonth(gimmeString(t["created_at"]));
str t2year(map[str,JSO] t) = gimmeYear(gimmeString(t["created_at"]));
str t2time(map[str,JSO] t) = gimmeTime(gimmeString(t["created_at"]));

str t2id(map[str,JSO] t) = gimmeString(t["id_str"]);
4 changes: 3 additions & 1 deletion rascal/src/io/date/AccessTwitterDate.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import String;
public str gimmeDay(str x) = notrail("<parse(#TwiDate,x).date.d>");
public str gimmeMonth(str x) = "<monthno("<parse(#TwiDate,x).date.m>")>";
public str gimmeYear(str x) = "<parse(#TwiDate,x).date.y>";
public str gimmeTime(str x) = "<parse(#TwiDate,x).date.time>";

public str gimmeDay(loc x) = notrail("<parse(#TwiDate,x).date.d>");
public str gimmeMonth(loc x) = "<monthno("<parse(#TwiDate,x).date.m>")>";
public str gimmeYear(loc x) = "<parse(#TwiDate,x).date.y>";
public str gimmeTime(loc x) = "<parse(#TwiDate,x).date.time>";

str notrail(str s)
{
Expand All @@ -32,4 +34,4 @@ int monthno("Sep") = 19;
int monthno("Oct") = 10;
int monthno("Nov") = 11;
int monthno("Dec") = 12;
default int monthno(str s) = "?";
default int monthno(str s) = 0;
2 changes: 1 addition & 1 deletion rascal/src/io/date/SyntaxTwitter.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module io::date::SyntaxTwitter

start syntax TwiDate = TwiDateSimplified date;
lexical TwiDateSimplified = NotSpace [\ ] TwiMonth m [\ ] TwiDay d [\ ] NotSpace [\ ] NotSpace [\ ] TwiYear y;
lexical TwiDateSimplified = NotSpace [\ ] TwiMonth m [\ ] TwiDay d [\ ] NotSpace time [\ ] NotSpace adj [\ ] TwiYear y;
lexical TwiMonth = [A-Z][a-z][a-z];
lexical TwiDay = [0-9][0-9];
lexical NotSpace = ![\ ]+ >> [\ ];
Expand Down

0 comments on commit 3871ee2

Please sign in to comment.