mirror of
https://github.com/vishalxl/nostr_console.git
synced 2025-04-24 23:40:25 +02:00
added method to write events in file. not used.
This commit is contained in:
parent
c2fb18f4bd
commit
2c37201185
@ -147,7 +147,7 @@ Future<void> main(List<String> arguments) async {
|
||||
|
||||
int numUserEvents = 0, numFeedEvents = 0, numOtherEvents = 0;
|
||||
|
||||
const int numWaitSeconds = 3500;
|
||||
const int numWaitSeconds = 2500;
|
||||
stdout.write('Waiting for user events to come in.....');
|
||||
Future.delayed(const Duration(milliseconds: numWaitSeconds), () {
|
||||
// count user events
|
||||
|
@ -183,6 +183,7 @@ Future<void> mainMenuUi(Tree node, var contactList) async {
|
||||
print("\nFinished fetching feed for user $userPublicKey ($authorName), whose contact list has ${contactList.length} profiles.\n ");
|
||||
contactList.forEach((x) => stdout.write("${getAuthorName(x)}, "));
|
||||
stdout.write("\n");
|
||||
//await node.writeEventsToFile("nostrConsoleEventsStore.txt");
|
||||
exit(0);
|
||||
}
|
||||
} // end while
|
||||
|
@ -99,7 +99,7 @@ class Relays {
|
||||
}
|
||||
String id = json[2]['id'] as String;
|
||||
if( uniqueIdsRecieved.contains(id)) {
|
||||
if( gDebug == 0) print("In relay: received duplicate event id : $id");
|
||||
if( gDebug > 0) print("In relay: received duplicate event id : $id");
|
||||
return;
|
||||
} else {
|
||||
uniqueIdsRecieved.add(id);
|
||||
|
@ -190,6 +190,43 @@ class Tree {
|
||||
});
|
||||
}
|
||||
|
||||
// Write the tree's events to file as one event's json per line
|
||||
Future<void> writeEventsToFile(String filename) async {
|
||||
//print("opening $filename to write to");
|
||||
try {
|
||||
final File file = File(filename);
|
||||
int eventCounter = 0;
|
||||
String nLinesStr = "";
|
||||
|
||||
const int numLinesTogether = 200;
|
||||
int linesWritten = 0;
|
||||
for( var k in allChildEventsMap.keys) {
|
||||
Tree? t = allChildEventsMap[k];
|
||||
if( t != null) {
|
||||
String line = "${t.e.originalJson}\n";
|
||||
nLinesStr += line;
|
||||
eventCounter++;
|
||||
}
|
||||
|
||||
if( eventCounter % numLinesTogether == 0) {
|
||||
await file.writeAsString(nLinesStr, mode: FileMode.append).then( (file) => file);
|
||||
nLinesStr = "";
|
||||
linesWritten += numLinesTogether;
|
||||
}
|
||||
}
|
||||
|
||||
if( eventCounter > linesWritten) {
|
||||
await file.writeAsString(nLinesStr, mode: FileMode.append).then( (file) => file);
|
||||
nLinesStr = "";
|
||||
}
|
||||
|
||||
int len = await file.length();
|
||||
} on Exception catch (e) {
|
||||
print("Could not open file $filename.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @getTagsFromEvent Searches for all events, and creates a json of e-tag type which can be sent with event
|
||||
* Also adds 'client' tag with application name.
|
||||
|
Loading…
x
Reference in New Issue
Block a user