Implementing configuration

Very tired. Must sleep. Wanted to work. Working on making config.json a thing so rss feed can be edited outside of the code.
This commit is contained in:
gmemstr 2017-07-01 00:26:32 -07:00
parent baa3ef76ae
commit a78472364c
4 changed files with 60 additions and 38 deletions

7
config.json Normal file
View file

@ -0,0 +1,7 @@
{
"Name": "Git Galaxy Stargazers",
"Host": "Gabriel Simmer",
"Email": "gabriel@gitgalaxy.com",
"Image": "https://podcast.gitgalaxy.com/assets/podcast_image.png",
"PodcastUrl": "https://podcast.gitgalaxy.com"
}

View file

@ -1,21 +1,16 @@
{
"version": "https://jsonfeed.org/version/1",
"title": "Git Galaxy Stargazers",
"home_page_url": "https://gitgalaxy.com",
"title": "",
"description": "discussion about open source projects",
"author": {
"name": "Gabriel Simmer"
},
"author": {},
"items": [
{
"id": "",
"url": "https://podcast.gitgalaxy.com/download/2017-07-12_TESTING WORLD.mp3",
"url": "/download/2017-07-12_TESTING WORLD.mp3",
"title": "TESTING WORLD",
"summary": "Hello, World!",
"summary": "testing4",
"date_published": "2017-07-12T00:00:00Z",
"author": {
"name": "Gabriel Simmer"
}
"author": {}
}
]
}

View file

@ -1,20 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">
<channel>
<title>Git Galaxy Stargazers</title>
<link>https://gitgalaxy.com</link>
<title></title>
<link></link>
<description>discussion about open source projects</description>
<managingEditor>gabriel@gitgalaxy.com (Gabriel Simmer)</managingEditor>
<pubDate>Mon, 19 Jun 2017 07:36:34 -0700</pubDate>
<pubDate>Sat, 01 Jul 2017 00:23:10 -0700</pubDate>
<image>
<url>https://podcast.gitgalaxy.com/assets/podcast_image.png</url>
<url></url>
<title></title>
<link></link>
</image>
<item>
<title>TESTING WORLD</title>
<link>https://podcast.gitgalaxy.com/download/2017-07-12_TESTING WORLD.mp3</link>
<description>Hello, World!</description>
<enclosure url="https://podcast.gitgalaxy.com/download/2017-07-12_TESTING WORLD.mp3" length="100" type="audio/mpeg"></enclosure>
<link>/download/2017-07-12_TESTING WORLD.mp3</link>
<description>testing4</description>
<enclosure url="/download/2017-07-12_TESTING WORLD.mp3" length="100" type="audio/mpeg"></enclosure>
<pubDate>Wed, 12 Jul 2017 00:00:00 +0000</pubDate>
</item>
</channel>

View file

@ -9,8 +9,17 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/gmemstr/feeds"
"github.com/Tkanos/gonfig"
)
type Configuration struct {
Name string
Host string
Email string
Image string
PodcastUrl string
}
func watch() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
@ -42,6 +51,12 @@ func watch() {
}
func generate_rss() {
configuration := Configuration{}
err := gonfig.GetConf("config.json", &configuration)
if err != nil {
log.Fatal(err)
}
fmt.Println(configuration)
now := time.Now()
files, err := ioutil.ReadDir("podcasts")
if err != nil {
@ -49,31 +64,37 @@ func generate_rss() {
}
feed := &feeds.Feed{
Title: "Git Galaxy Stargazers",
Link: &feeds.Link{Href: "https://gitgalaxy.com"},
Title: configuration.Name,
Link: &feeds.Link{Href: configuration.PodcastUrl},
Description: "discussion about open source projects",
Author: &feeds.Author{Name: "Gabriel Simmer", Email: "gabriel@gitgalaxy.com"},
Author: &feeds.Author{Name: configuration.Host, Email: configuration.Email},
Created: now,
Image: &feeds.Image{Url: "https://podcast.gitgalaxy.com/assets/podcast_image.png"},
Image: &feeds.Image{Url: configuration.Image},
}
for _, file := range files {
s := strings.Split(file.Name(), "_")
t := strings.Split(s[1], ".")
title := t[0]
date, err := time.Parse("2006-01-02", s[0])
if err != nil {
log.Fatal(err)
}
feed.Items = []*feeds.Item{
&feeds.Item{
Title: title,
Link: &feeds.Link{Href: "https://podcast.gitgalaxy.com/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
Enclosure: &feeds.Enclosure{Url: "https://podcast.gitgalaxy.com/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
Description: "Hello, World!",
Author: &feeds.Author{Name: "Gabriel Simmer", Email: "gabriel@gitgalaxy.com"},
Created: date,
},
if strings.Contains(file.Name(), ".mp3") {
s := strings.Split(file.Name(), "_")
t := strings.Split(s[1], ".")
title := t[0]
description,err := ioutil.ReadFile("podcasts/" + strings.Replace(file.Name(), ".mp3", "_SHOWNOTES.md", 2))
if err != nil {
log.Fatal(err)
}
date, err := time.Parse("2006-01-02", s[0])
if err != nil {
log.Fatal(err)
}
feed.Items = []*feeds.Item{
&feeds.Item{
Title: title,
Link: &feeds.Link{Href: configuration.PodcastUrl + "/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
Enclosure: &feeds.Enclosure{Url: configuration.PodcastUrl + "/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
Description: string(description),
Author: &feeds.Author{Name: configuration.Host, Email: configuration.Email},
Created: date,
},
}
}
}
rss, err := feed.ToRss()