mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-03-29 19:21:49 +01:00
added --days options, which controls how many recent days of posts are shown, default value is 3 days. This reduces clutter on output
This commit is contained in:
parent
a43acbee21
commit
31228e5561
@ -4,20 +4,25 @@ import 'package:nostr_console/relays.dart';
|
||||
import 'package:args/args.dart';
|
||||
|
||||
|
||||
var userPublickey = "3235036bd0957dfb27ccda02d452d7c763be40c91a1ac082ba6983b25238388c"; // vishalxl
|
||||
var userPublickey = "3235036bd0957dfb27ccda02d452d7c763be40c91a1ac082ba6983b25238388c"; // vishalxl
|
||||
//var userPublickey = "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"; // jb55
|
||||
//var userPublickey = "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d"; // fiatjaf
|
||||
// ed1d0e1f743a7d19aa2dfb0162df73bacdbc699f67cc55bb91a98c35f7deac69 melvin
|
||||
//var userPublickey = "ed1d0e1f743a7d19aa2dfb0162df73bacdbc699f67cc55bb91a98c35f7deac69"; // melvin
|
||||
//var userPublickey = "52b4a076bcbbbdc3a1aefa3735816cf74993b1b8db202b01c883c58be7fad8bd"; // semisol
|
||||
|
||||
|
||||
// program arguments
|
||||
const request = "request";
|
||||
const user = "user";
|
||||
const String requestArg = "request";
|
||||
const String userArg = "user";
|
||||
const String lastdaysArg = "days";
|
||||
|
||||
// by default the threads that were started in last two days are shown
|
||||
// this can be changed with 'days' command line argument
|
||||
int numLastDays = 2;
|
||||
|
||||
void printEventsAsTree(events) {
|
||||
if( events.length == 0) {
|
||||
print("In printEventsAsTree: events length = 0");
|
||||
print("Warning: In printEventsAsTree: events length = 0");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -38,13 +43,10 @@ void printEventsAsTree(events) {
|
||||
Tree node = Tree.fromEvents(events);
|
||||
|
||||
// print all the events in tree form
|
||||
node.printTree(0, true);
|
||||
node.printTree(0, true, DateTime.now().subtract(Duration(days:numLastDays)));
|
||||
|
||||
print('\n\n===================summary=================');
|
||||
//printUserInfo(events, "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245");
|
||||
//printUserInfo(events, "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d");
|
||||
//printUserInfo(events, "3235036bd0957dfb27ccda02d452d7c763be40c91a1ac082ba6983b25238388c");
|
||||
//printUserInfo(events, "ed1d0e1f743a7d19aa2dfb0162df73bacdbc699f67cc55bb91a98c35f7deac69");
|
||||
|
||||
print('\nnumber of all events : ${events.length}');
|
||||
//print("number or events of kind 0: ${gKindONames.length}");
|
||||
@ -53,22 +55,26 @@ void printEventsAsTree(events) {
|
||||
|
||||
Future<void> main(List<String> arguments) async {
|
||||
List<Event> events = [];
|
||||
int numEvents = 6;
|
||||
|
||||
final parser = ArgParser()..addOption(request, abbr: 'r')..addOption(user, abbr:"u");
|
||||
final parser = ArgParser()..addOption(requestArg, abbr: 'r')
|
||||
..addOption(userArg, abbr:"u")
|
||||
..addOption(lastdaysArg, abbr:"d");
|
||||
ArgResults argResults = parser.parse(arguments);
|
||||
|
||||
if( argResults[request] != null) {
|
||||
stdout.write("got argument request ${argResults[request]}");
|
||||
sendRequest("wss://nostr-pub.wellorder.net", argResults[request], events);
|
||||
if( argResults[requestArg] != null) {
|
||||
stdout.write("got argument request ${argResults[requestArg]}");
|
||||
sendRequest("wss://nostr-pub.wellorder.net", argResults[requestArg], events);
|
||||
Future.delayed(const Duration(milliseconds: 6000), () {
|
||||
printEventsAsTree(events);
|
||||
exit(0);
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
if( argResults[user] != null) {
|
||||
userPublickey = argResults[user];
|
||||
if( argResults[userArg] != null) {
|
||||
userPublickey = argResults[userArg];
|
||||
}
|
||||
if( argResults[lastdaysArg] != null) {
|
||||
numLastDays = int.parse(argResults[lastdaysArg]);
|
||||
print("Going to show posts for last $numLastDays days");
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +142,7 @@ Future<void> main(List<String> arguments) async {
|
||||
|
||||
String authorName = getAuthorName(userPublickey);
|
||||
print("\nFinished fetching feed for user $userPublickey ($authorName), whose contact list has ${contactList.length} profiles.\n ");
|
||||
contactList.forEach((x) => stdout.write(getAuthorName(x) + ", "));
|
||||
contactList.forEach((x) => stdout.write("${getAuthorName(x)}, "));
|
||||
stdout.write("\n");
|
||||
exit(0);
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ void processKind0Event(Event e) {
|
||||
return;
|
||||
}
|
||||
|
||||
print("In getNames: for event content: ${e.eventData.content}");
|
||||
//print("In getNames: for event content: ${e.eventData.content}");
|
||||
String content = e.eventData.content;
|
||||
if( content.isEmpty) {
|
||||
return;
|
||||
@ -174,7 +174,9 @@ class EventData {
|
||||
}
|
||||
|
||||
void printEventData(int depth) {
|
||||
String max3(String v) => v.length > 3? v.substring(0,3) : v.substring(0, v.length);
|
||||
String max3(String v) => v.length > 3? v.substring(0,3) : v.substring(0, v.length);
|
||||
void printGreen(String s) => stdout.supportsAnsiEscapes ?stdout.write("\x1B[32m$s\x1B[0m"):stdout.write(s);
|
||||
|
||||
DateTime dTime = DateTime.fromMillisecondsSinceEpoch(createdAt *1000);
|
||||
|
||||
// TODO do it in one call
|
||||
@ -187,7 +189,7 @@ class EventData {
|
||||
}
|
||||
|
||||
String contentShifted = rightShiftContent(content, spacesPerDepth * depth + 10);
|
||||
void printGreen(String s) => stdout.write("\x1B[32m$s\x1B[0m");
|
||||
|
||||
printDepth(depth);
|
||||
stdout.write("+-------+\n");
|
||||
printDepth(depth);
|
||||
@ -196,7 +198,6 @@ class EventData {
|
||||
printDepth(depth);
|
||||
stdout.write("|Message: ");
|
||||
printGreen(contentShifted);
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
@ -316,7 +317,8 @@ class Tree {
|
||||
children.add(node);
|
||||
}
|
||||
|
||||
void printTree(int depth, bool onlyPrintChildren) {
|
||||
void printTree(int depth, bool onlyPrintChildren, var newerThan) {
|
||||
|
||||
children.sort(ascendingTimeTree);
|
||||
if( !onlyPrintChildren) {
|
||||
e.printEvent(depth);
|
||||
@ -325,20 +327,27 @@ class Tree {
|
||||
}
|
||||
|
||||
for( int i = 0; i < children.length; i++) {
|
||||
stdout.write("\n");
|
||||
printDepth(depth+1);
|
||||
if(!onlyPrintChildren) {
|
||||
stdout.write("\n");
|
||||
printDepth(depth+1);
|
||||
stdout.write("|\n");
|
||||
} else {
|
||||
|
||||
DateTime dTime = DateTime.fromMillisecondsSinceEpoch(children[i].e.eventData.createdAt *1000);
|
||||
//print("comparing $newerThan with $dTime");
|
||||
if( dTime.compareTo(newerThan) < 0) {
|
||||
continue;
|
||||
}
|
||||
stdout.write("\n");
|
||||
printDepth(depth+1);
|
||||
stdout.write("\n\n\n");
|
||||
}
|
||||
children[i].printTree(depth+1, false);
|
||||
children[i].printTree(depth+1, false, newerThan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> getpTags(List<Event> events) {
|
||||
//print("in getPtags. number of events = ${events.length}");
|
||||
List<String> pTags = [];
|
||||
for(int i = 0; i < events.length; i++) {
|
||||
pTags.addAll(events[i].eventData.pTags);
|
||||
@ -348,13 +357,12 @@ List<String> getpTags(List<Event> events) {
|
||||
Set tempPtags = {};
|
||||
pTags.retainWhere((x) => tempPtags.add(x));
|
||||
|
||||
print("in getPtags. returning number of ptags = ${pTags.length}");
|
||||
print("In getPtags. returning number of ptags = ${pTags.length}");
|
||||
return pTags;
|
||||
}
|
||||
|
||||
int ascendingTime(Event a, Event b) {
|
||||
if(a.eventData.createdAt < b.eventData.createdAt) {
|
||||
//print( 'ascendingTime : comparing two ${a.eventData.createdAt} and ${b.eventData.createdAt}');
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -362,7 +370,6 @@ int ascendingTime(Event a, Event b) {
|
||||
|
||||
int ascendingTimeTree(Tree a, Tree b) {
|
||||
if(a.e.eventData.createdAt < b.e.eventData.createdAt) {
|
||||
//print( 'ascendingTimeTree : comparing two ${a.e.eventData.createdAt} and ${b.e.eventData.createdAt}');
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
@ -127,7 +127,7 @@ class Relays {
|
||||
}
|
||||
}
|
||||
|
||||
print('sending request: $request to $relay\n');
|
||||
//print('sending request: $request to $relay\n');
|
||||
fws?.sink.add(request);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ void main() {
|
||||
node.addChildNode(childNode);
|
||||
node.addChildNode(childNode);
|
||||
|
||||
node.printTree(0, false);
|
||||
node.printTree(0, false, DateTime.now().subtract(Duration(days:1)));
|
||||
});
|
||||
|
||||
test('createNodeTree_ordered', () {
|
||||
@ -40,7 +40,7 @@ void main() {
|
||||
List<Event> listEvents = [exampleEvent1, exampleEvent2, exampleEvent3];
|
||||
|
||||
Tree node = Tree.fromEvents(listEvents);
|
||||
node.printTree(0, true);
|
||||
node.printTree(0, true, DateTime.now().subtract(Duration(days:1)));
|
||||
print("=========================");
|
||||
});
|
||||
|
||||
@ -54,7 +54,7 @@ void main() {
|
||||
List<Event> listEvents = [ exampleEvent3, exampleEvent2, exampleEvent1];
|
||||
|
||||
Tree node = Tree.fromEvents(listEvents);
|
||||
node.printTree(0, true);
|
||||
node.printTree(0, true, DateTime.now().subtract(Duration(days:1)));
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user