-
Notifications
You must be signed in to change notification settings - Fork 0
/
DartTwitterWall.dart
75 lines (62 loc) · 2.24 KB
/
DartTwitterWall.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#library('twitter_wall');
#import("TwitterApi.dart");
#import('dart:io');
#import('dart:core');
void main() {
Options options = new Options();
try {
validateInput( options.arguments );
String hashTag = options.arguments[0];
printTweets( hashTag );
Timer timer = new Timer.repeating( 15000, (Timer timer) {
printTweets( hashTag );
});
} catch ( IllegalArgumentException e ) {
print( "Usage: dart DartTwitterWall.dart hashtag" );
}
}
void validateInput( List options ) {
if ( options.length < 1 ) {
throw new IllegalArgumentException();
}
}
void printTweets( String hashTag ) {
TwitterApi api = new TwitterApi(searchQuery:hashTag);
int tweetHeight = 4;
int terminalWidth = 139;
int terminalHeight = 28;
api.getTweets(max:7).then( ( List<Tweet> tweets ) {
printHeader();
int remainingLength = 24;
print( "${repeat(' ', 20)}.${repeat('-', 60)}." );
print( "${repeat(' ', 20)}| NOW: ${new Date.now()} "
"| #$hashTag${repeat( ' ', remainingLength - hashTag.length )}|"
);
print( "${repeat(' ', 20)}\\${repeat( '-', 60 )}/\n" );
int i = 1;
for ( Tweet tweet in tweets ) {
print( tweet.text );
print( "-- \n @${tweet.userName} ${tweet.timeAgo}" );
if ( i < tweets.length ) {
print( "\n" );
}
i++;
}
print( repeat( "\n", terminalHeight - tweetHeight * tweets.length ) );
});
}
void printHeader() {
print( @""" ________ __ ___________ .__ __ __ __ __ .__ .__
\______ \ _____ ________/ |\__ ___/_ _ _|__|/ |__/ |_ ___________/ \ / \_____ | | | |
| | \\__ \\_ __ \ __\| | \ \/ \/ / \ __\ __\/ __ \_ __ \ \/\/ /\__ \ | | | |
| ` \/ __ \| | \/| | | | \ /| || | | | \ ___/| | \/\ / / __ \| |_| |__
/_______ (____ /__| |__| |____| \/\_/ |__||__| |__| \___ >__| \__/\ / (____ /____/____/
\/ \/ \/ \/ \/ """ );
}
String repeat( String char, int lines ) {
StringBuffer strBuf = new StringBuffer();
for(int i = 0; i <= lines; i++) {
strBuf.add(char);
}
return strBuf.toString();
}