Load all urls when starting

This commit is contained in:
Peter Stuifzand 2018-04-07 21:01:21 +02:00
parent 925e914d01
commit 75c9dfd4f6
2 changed files with 16 additions and 1 deletions

View File

@ -59,6 +59,7 @@ func (b *memoryBackend) Fetch3(channel, fetchURL string) error {
u, _ := url.Parse(fetchURL)
contentType := resp.Header.Get("Content-Type")
log.Println("Found " + contentType)
if strings.HasPrefix(contentType, "text/html") {
data := microformats.Parse(resp.Body, u)
results := simplifyMicroformatData(data)
@ -175,6 +176,8 @@ func (b *memoryBackend) Fetch3(channel, fetchURL string) error {
}
func (b *memoryBackend) channelAddItem(channel string, item microsub.Item) {
log.Printf("Adding item to channel %s\n", channel)
log.Println(item)
// send to redis
channelKey := fmt.Sprintf("channel:%s:posts", channel)

View File

@ -64,6 +64,14 @@ func (b *memoryBackend) load() {
if err != nil {
panic("cant open backend.json")
}
for uid, channel := range b.Channels {
log.Printf("loading channel %s - %s\n", uid, channel.Name)
for _, feed := range b.Feeds[uid] {
log.Printf("- loading feed %s\n", feed.URL)
b.Fetch3(uid, feed.URL)
}
}
}
func (b *memoryBackend) save() {
@ -209,7 +217,11 @@ func mapToItem(result map[string]interface{}) microsub.Item {
if value, e := result["in-reply-to"]; e {
for _, v := range value.([]interface{}) {
item.InReplyTo = append(item.InReplyTo, v.(string))
if replyTo, ok := v.(string); ok {
item.InReplyTo = append(item.InReplyTo, replyTo)
} else if cite, ok := v.(map[string]interface{}); ok {
item.InReplyTo = append(item.InReplyTo, cite["url"].(string))
}
}
}