mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-03-26 17:41:43 +01:00
show recommendations in original order, not time sorted
This commit is contained in:
parent
51ea722fbf
commit
c489b76145
39
tests/discovery.py
Normal file
39
tests/discovery.py
Normal file
@ -0,0 +1,39 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import dotenv
|
||||
from nostr_sdk import Keys
|
||||
|
||||
from nostr_dvm.tasks import content_discovery_test
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.backend_utils import keep_alive
|
||||
|
||||
|
||||
def playground():
|
||||
# Generate an optional Admin Config, in this case, whenever we give our DVMs this config, they will (re)broadcast
|
||||
# their NIP89 announcement
|
||||
# You can create individual admins configs and hand them over when initializing the dvm,
|
||||
# for example to whilelist users or add to their balance.
|
||||
# If you use this global config, options will be set for all dvms that use it.
|
||||
admin_config = AdminConfig()
|
||||
admin_config.REBROADCAST_NIP89 = False
|
||||
admin_config.UPDATE_PROFILE = False
|
||||
|
||||
discovery_test = content_discovery_test.build_example("Dicovery Test DVM", "discovery_content_test", admin_config)
|
||||
discovery_test.run()
|
||||
|
||||
keep_alive()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
env_path = Path('.env')
|
||||
if not env_path.is_file():
|
||||
with open('.env', 'w') as f:
|
||||
print("Writing new .env file")
|
||||
f.write('')
|
||||
if env_path.is_file():
|
||||
print(f'loading environment from {env_path.resolve()}')
|
||||
dotenv.load_dotenv(env_path, verbose=True, override=True)
|
||||
else:
|
||||
raise FileNotFoundError(f'.env file not found at {env_path} ')
|
||||
playground()
|
@ -1,7 +1,8 @@
|
||||
<template>
|
||||
<EasyDataTable class="customize-table" header-text-direction="left" table-class-name="customize-table"
|
||||
:headers="headers"
|
||||
:items="data" :sort-by="sortBy"
|
||||
:items="data"
|
||||
:sort-by="sortBy"
|
||||
:sort-type="sortType">
|
||||
<template #item-content="{content, author, authorurl, avatar, indicator, links}">
|
||||
|
||||
@ -12,7 +13,7 @@
|
||||
<img class="avatar" v-else src="@/assets/nostr-purple.svg" />
|
||||
|
||||
<a class="purple" :href="authorurl" target="_blank">{{ author }}</a>
|
||||
<div class="time" :data-tip="indicator.time">
|
||||
<div class="time">
|
||||
{{indicator.time.split("T")[1].split("Z")[0].trim()}}
|
||||
{{indicator.time.split("T")[0].split("-")[2].trim()}}.{{indicator.time.split("T")[0].split("-")[1].trim()}}.{{indicator.time.split("T")[0].split("-")[0].trim().slice(2)}}
|
||||
</div>
|
||||
@ -48,17 +49,19 @@
|
||||
|
||||
import type {Header, Item, SortType} from "vue3-easy-data-table";
|
||||
import store from '../store';
|
||||
import {types} from "sass";
|
||||
import Null = types.Null;
|
||||
defineProps<{
|
||||
data?: []
|
||||
|
||||
}>()
|
||||
|
||||
const sortBy = "indicator.time";
|
||||
const sortType: SortType = "desc";
|
||||
const sortBy: String = "index";
|
||||
const sortType: SortType = "asc";
|
||||
|
||||
const headers: Header[] = [
|
||||
{ text: "Results:", value: "content", fixed:true},
|
||||
// { text: "Time", value: "indicator.time", sortable: true, },
|
||||
{ text: "Results:", value: "content", fixed: true},
|
||||
// { text: "Time", value: "indicator.index", sortable: true, },
|
||||
];
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@ import {data} from "autoprefixer";
|
||||
import {requestProvider} from "webln";
|
||||
import Newnote from "@/components/Newnote.vue";
|
||||
import SummarizationGeneration from "@/components/SummarizationGeneration.vue"
|
||||
import {post_note, schedule, copyurl, copyinvoice, sleep, getEvents, get_user_infos, nextInput} from "../components/helper/Helper.vue"
|
||||
import {post_note, schedule, copyurl, copyinvoice, sleep, getEvents, get_user_infos, nextInput, getEventsOriginalOrder} from "../components/helper/Helper.vue"
|
||||
import amberSignerService from "./android-signer/AndroidSigner";
|
||||
import StringUtil from "@/components/helper/string.ts";
|
||||
|
||||
@ -229,10 +229,10 @@ async function listen() {
|
||||
let event_etags = JSON.parse(event.content)
|
||||
if (event_etags.length > 0) {
|
||||
for (let etag of event_etags) {
|
||||
const eventid = EventId.fromHex(etag[1])
|
||||
const eventid = EventId.fromHex(etag[1]).toHex()
|
||||
entries.push(eventid)
|
||||
}
|
||||
const events = await getEvents(entries)
|
||||
const events = await getEventsOriginalOrder(entries)
|
||||
let authors = []
|
||||
for (const evt of events) {
|
||||
authors.push(evt.author)
|
||||
@ -241,6 +241,7 @@ async function listen() {
|
||||
if (authors.length > 0) {
|
||||
let profiles = await get_user_infos(authors)
|
||||
let items = []
|
||||
let index = 0
|
||||
for (const evt of events) {
|
||||
let p = profiles.find(record => record.author === evt.author.toHex())
|
||||
let bech32id = evt.id.toBech32()
|
||||
@ -267,9 +268,12 @@ async function listen() {
|
||||
"nostrudel": nostrudelurl
|
||||
},
|
||||
avatar: picture,
|
||||
indicator: {"time": evt.createdAt.toHumanDatetime()}
|
||||
index: index,
|
||||
indicator: {"time": evt.createdAt.toHumanDatetime(), "index": index}
|
||||
})
|
||||
index = index+1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dvms.find(i => i.id === event.author.toHex()).result.length = 0
|
||||
|
@ -269,7 +269,7 @@ async function listen() {
|
||||
let event_etags = JSON.parse(event.content)
|
||||
if (event_etags.length > 0) {
|
||||
for (let etag of event_etags) {
|
||||
const eventid = EventId.fromHex(etag[1])
|
||||
const eventid = EventId.parse(etag[1]).toHex() //a bit unnecessary
|
||||
entries.push(eventid)
|
||||
}
|
||||
const events = await getEvents(entries)
|
||||
@ -341,7 +341,7 @@ async function listen() {
|
||||
let infos = await get_user_infos(authors)
|
||||
|
||||
for (const profile of infos) {
|
||||
console.log(profile["author"])
|
||||
//console.log(profile["author"])
|
||||
if (profiles.findIndex(e => e.id === profile["author"]) === -1 && profile["profile"]["name"] !== "" ) {
|
||||
profiles.push({
|
||||
id: profile["author"],
|
||||
|
@ -2,7 +2,7 @@
|
||||
import {defineComponent} from 'vue'
|
||||
import store from "@/store";
|
||||
import amberSignerService from "@/components/android-signer/AndroidSigner";
|
||||
import {Duration, Event, EventBuilder, Filter, Keys, PublicKey, Tag, Timestamp} from "@rust-nostr/nostr-sdk";
|
||||
import {Duration, Event, EventBuilder, EventId, Filter, Keys, PublicKey, Tag, Timestamp} from "@rust-nostr/nostr-sdk";
|
||||
import miniToastr from "mini-toastr/mini-toastr";
|
||||
import VueNotifications from "vue-notifications";
|
||||
|
||||
@ -73,11 +73,37 @@ export async function schedule(note, datetopost) {
|
||||
}
|
||||
|
||||
export async function getEvents(eventids) {
|
||||
const event_filter = new Filter().ids(eventids)
|
||||
let ids = []
|
||||
for (let eid of eventids){
|
||||
ids.push(EventId.parse(eid))
|
||||
}
|
||||
const event_filter = new Filter().ids(ids)
|
||||
let client = store.state.client
|
||||
return await client.getEventsOf([event_filter], Duration.fromSecs(5))
|
||||
}
|
||||
|
||||
}
|
||||
export async function getEventsOriginalOrder(eventids) {
|
||||
let ids = []
|
||||
for (let eid of eventids){
|
||||
ids.push(EventId.parse(eid))
|
||||
}
|
||||
const event_filter = new Filter().ids(ids)
|
||||
let client = store.state.client
|
||||
let results = await client.getEventsOf([event_filter], Duration.fromSecs(5))
|
||||
console.log(results.length)
|
||||
for (let e of results){
|
||||
console.log(e.id.toHex())
|
||||
}
|
||||
|
||||
let final = []
|
||||
for (let f of eventids){
|
||||
let note = results.find(value => value.id.toHex() === f)
|
||||
console.log(note)
|
||||
final.push(note)
|
||||
}
|
||||
|
||||
return final
|
||||
}
|
||||
|
||||
|
||||
export function nextInput(e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user